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_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 / .configure_lando_for_debugging_in_decoupled_drupal_installation.md
Last active December 17, 2021 12:51
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 October 26, 2021 16:30
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 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

@davidjguru
davidjguru / drupal_integration_with_web_analytics_tooling.md
Last active October 14, 2021 17:29
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 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 / intro_gitlab_api_examples_from_php_using_guzzle.md
Created June 18, 2021 08:07
Drupal 8 || 9 - Getting info about projects and files using the Gitlab API v4 from PHP code

Well, maybe you need track some kind of information and data from Gitlab repositories and the Gitlab API (v4) seems to be very extensive and complex...ok, I understand you, really.

I had to connect a custom Drupal module to the Gitlab API in order to get some info, so I wrote down some notes with examples talkin' to the Gitlab API.

For the next examples, you only need to know your user id (no the @user, this is a keycode) and get an access token from your Gitlab profile settings. They are the basic resources requested by the Gitlab API for connections.

For more information, see the Gitlab API Resources documentation: https://docs.gitlab.com/ee/api/api_resources.html.

Author

@davidjguru
davidjguru / intro_drupal_8_9_reverse_geocoding_using_external_service_from_php.md
Last active June 18, 2021 08:27
Drupal 8 || 9 - Reverse Geocoding using external Service from PHP

I was developing an external query based in long/lat values in order to get certain addresses. For do this, I was using the geocoding library for PHP and some providers. I'm gathering here the main steps and how you can execute the integrations.

Maria Arias de Reyna, @delawen and Juan Luis Rodríguez, @juanluisrp guided me. They are the greatest GIS experts I know and they were very helpful here, givin' me some ideas and links to resources. Kudos.

Author