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 / 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 / intro_drupal_8_9_getting_taxonomy_terms_from_different_levels_programmatically.md
Last active April 11, 2024 08:13
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 February 18, 2024 22:12
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 / 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

@davidjguru
davidjguru / drupal_8_9_composing_directions_files_graphql_using_data_producers_in_field_resolvers.md
Last active February 20, 2023 10:00
Drupal 8 || 9 - Composing directions for files from GraphQL using Data Producers in Fields Resolvers

Use Case

Well, I have a Content Type "basic page" (a classic) and inside I can use Layout Builder to put in some custom blocks with fields. For this case I need to reach values from a certain block "FactBox" and some of its fields: title, subtitle, body...you know. But I have to get values from an entity reference field too. I have a media field for uploading documents "listOfDocuments" (name of type: MediaPdf), and I need to send to the frontend layer name of the file, url, the internal uri... How can I get the values? this is the use case here.

The Query I'd like to resolve

As you can see, I'm trying to reach values from fields: uri, url, name of a media entity MediaPdf in a field ListOfDocuments included on a block called MyCustomBlock which is present in the main zone of Layout Regions inside a Content Type Page and we're testing the query against a specific node with url /basic-page. Along the way, I will take advantage and get other field values included in the custom blo