Skip to content

Instantly share code, notes, and snippets.

View davidjguru's full-sized avatar
🍅
Working within a pomodoro cycle

David Rodriguez davidjguru

🍅
Working within a pomodoro cycle
View GitHub Profile
@davidjguru
davidjguru / drupal_8_adding_new_fields_in_database.txt
Created August 29, 2019 21:06
Drupal 8: Adding new fields in the database (install / uninstall)
// Context: In a custom module, within the .install file
// Doing tasks on the installation.
// Looking for a field and create if not exist.
// We'll delete this field in the uninstallation process.
// We're using a pair of basic Drupal hooks: install and uninstall.
/**
* Implements hook_install().
*/
function your_custom_module_install() {
@davidjguru
davidjguru / intro_drupal_8_9_getting_taxonomy_terms_from_different_levels_programmatically.md
Last active May 12, 2024 21:22
Drupal 8 || 9 - Getting Taxonomy Terms from different levels programmatically

Introduction

In this snippet I've gathered some examples and cases about how to get taxonomy terms programmatically in Drupal, using always the same method and the same mechanics: get terms and then processing it in order to get only the required under certain criteria.

Author

@davidjguru
davidjguru / bash_aliases
Last active April 29, 2024 17:54
BASH Aliases commands for a Linux (Debian / Ubuntu) environment
## Morning Opertures
alias whatsup='service --status-all'
alias hello='sudo /etc/init.d/apache2 stop && cd workspace/project && ddev start && ddev launch'
alias hi='sudo systemctl stop apache2'
alias iad='systemctl is-active docker'
alias ports='nmap localhost'
alias dns="sudo systemd-resolve --status | grep 'DNS Servers'"
alias bye='shutdown -r now'
## Usual Instructions
@davidjguru
davidjguru / intro_drupal_truncate_watchdog_table_using_drush.md
Last active April 22, 2024 11:27
Drupal 8 || 9 : Truncate Watchdog table using Drush from a DDEV deploy.
@davidjguru
davidjguru / Blocks.md
Created November 12, 2020 17:47 — forked from bdlangton/Blocks.md
Drupal 8 programmatic solutions

Render custom blocks

$bid = 'myblock';
$block = \Drupal\block_content\Entity\BlockContent::load($bid);
$render = \Drupal::entityTypeManager()->getViewBuilder('block_content')->view($block);

Render plugin blocks

$block_manager = \Drupal::service('plugin.manager.block');
@davidjguru
davidjguru / Set_up_a_new_mac.txt
Created April 11, 2024 14:02 — forked from tomraithel/Set_up_a_new_mac.txt
Stuff I use to install if I setup a new mac
- Change the root password!
- System Settings > Security
- General: Set Password required to "instant"
- FileVault: activate
- System Setting > Keyboard
- Set all key speeds to "fast"
- Mark checkbox to use "fn" keys without option key
- Generate SSH-Key: ssh-keygen -t rsa -C "email@provider.com" -b 2048
- Change desktop background :)
- Install PHPstorm + Java
@davidjguru
davidjguru / drupal_8_9_configure_phpunit_for_testing.md
Last active April 11, 2024 08:15
Drupal 8 || 9 - Configure your PHPUnit environment for functional testing
@davidjguru
davidjguru / drupal_8_9_how_to_create_media_remote_video_entity_node_programmatically.md
Created June 9, 2021 18:49
Drupal 8 || 9 - How to create a media (remote video) entity node programmatically
use Drupal\media\Entity\Media;


// Model: https://www.youtube.com/embed/234Dfq985c1?enablejsapi=1&rel=0&showinfo=0&autoplay=1
$second_part = explode("/", $iframe_code)[4];
$video_code = explode("?", $second_part)[0];
$wellformed_url = "https://youtube.com/watch?v=" . $video_code;

// Create the new media item. 
@davidjguru
davidjguru / MyCustomForm.php
Created May 19, 2023 08:22 — forked from MatthieuScarset/MyCustomForm.php
Drupal - Autosubmit exposed form in JS
<?php
namespace Drupal\mymodule\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Provides a custom form.
*/
@davidjguru
davidjguru / working_with_github_cli_and_derivative_extensions.md
Last active April 25, 2023 16:24
Working with Github CLI and derivative extensions

Introduction

Github CLI is a console tool for working on interactions with Github from terminal. This tool allow to add new extension by developing them and adding to the main gh prompt as sub-commands from your command line. Read More about how to implement custom Github CLI extensions.

For this example we use a private extension not available for public purposes but you can explore some others existing Github CLI extensions. See the list of available extensions at https://github.com/topics/gh-extension.

In order to follow the next steps just change [RESOURCE] by your marked extension.

Install Github CLI in Ubuntu / Debian

Add repository