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_8_9_getting_data_from_user_account.md
Last active August 28, 2024 05:21
Drupal 8 || 9 - Getting data from user account in Drupal
@davidjguru
davidjguru / _introduction_drupal_8_9_getting_info_about_services_using_drush.md
Last active August 28, 2024 05:22
Drupal 8 || 9 - Getting info about available services in your Drupal installation

Drupal 8 || 9 - Getting info about available services in your Drupal installation

Sometimes you need to know what classes you have available to use as a service in your Drupal installation: either because you don't remember by heart all the services provided by the Drupal core (it's impossible!) or because you come to a project with a lot of custom developments accumulated. In between, there are also all the services available through contributed modules, which you can also use in your implementations. For all these reasons I have compiled some ways to get information about services in a Drupal installation.

Author

@davidjguru
davidjguru / drupal_8_9_configure_phpunit_for_testing.md
Last active August 28, 2024 05:22
Drupal 8 || 9 - Configure your PHPUnit environment for functional testing
@davidjguru
davidjguru / .configure_lando_for_debugging_in_decoupled_drupal_installation.md
Last active August 28, 2024 05:23
Decoupled Drupal using Lando in Containers: Configuration for Debugging

Configuration for Debugging Decoupled Drupal using Lando.

Architecture

This snippet is for a decoupled system divided in some folders, something like:

/root_project/
   |
   |_/backend_folder/
 |_____/frontend_folder/
@davidjguru
davidjguru / drupal_9_getting_entity_reference_id_in_graphql.md
Created October 25, 2021 08:18
Drupal 8 || 9 - Getting Entity Reference ID from GraphQL Field Resolvers
$registry->addFieldResolver('ContentType', 'graphqlField',
 $builder->compose(
   $builder->produce('entity_id')
     ->map('entity', $builder->fromParent()),
   $builder->callback(function ($id) {
     // First: get node by id.
     $node = \Drupal::entityTypeManager()->getStorage('node')->load($id);
     // Second: get entity reference id.
$entity_id = $node->get('field_entity_reference_name')->first()->getValue()['target_id'];
@davidjguru
davidjguru / ddev_drupal_launch.json
Created October 16, 2021 17:32
Debugging from VSCode: some launch.json example files
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"hostname": "0.0.0.0",
"port": 9000,
"pathMappings": {
@davidjguru
davidjguru / davidjguru_upgrading_from_drupal8_to_drupal9_my_favourite_articles.md
Last active August 28, 2024 05:23
Upgrading from Drupal 8 to Drupal 9: My favourite articles
@davidjguru
davidjguru / drupal_8_9_composing_directions_files_graphql_using_data_producers_in_field_resolvers.md
Last active August 28, 2024 05:23
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

@davidjguru
davidjguru / drupal_integration_with_web_analytics_tooling.md
Last active August 28, 2024 05:24
Drupal Integration with web analytics tooling
Module D7 D8 D9 Update Use Rating Free Link
Google Analytics πŸ‘ πŸ‘ πŸ‘ πŸ‘‰ πŸ’ͺ πŸ‘Œ βœ”οΈ drupal.org/ga
Google Analytics Reports πŸ‘ πŸ‘ πŸ‘ πŸ‘‰ 🀘 πŸ‘Œ βœ”οΈ drupal.org/gar
Google Tag Manager πŸ‘ πŸ‘ πŸ‘ ☝️ πŸ’ͺ πŸ‘Œ βœ”οΈ drupal.org/gtm
Piwik / Matomo πŸ‘ πŸ‘ πŸ‘ ☝️ πŸ‘Š πŸ‘Œ βœ”οΈ drupal.org/m
Matomo Reports πŸ‘ πŸ‘ πŸ‘ ☝️ πŸ™ πŸ‘Œ :heavy_check_ma
@davidjguru
davidjguru / intro_drupal_8_9_getting_taxonomy_terms_from_different_levels_programmatically.md
Last active December 10, 2024 14:15
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