Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
commit push commit push

David Rodriguez davidjguru

:octocat:
commit push commit push
View GitHub Profile
@davidjguru
davidjguru / my_favourite_git_aliases_for_prompt.md
Created Mar 31, 2022
Gathering my favourite git aliases (from the Linux OS level, not like Git aliases).
View my_favourite_git_aliases_for_prompt.md

Git Related Aliases

Getting basic info of the situation of your project: status, branches, current branch, naming of remote repo.

alias gs='git status'
alias gb='git branch'
alias gr='git remote -v'
alias gp='git rev-parse --abbrev-ref HEAD'

Getting info from 'Git log' about last commits, last changed files in 12 months by order and by commit message.

@davidjguru
davidjguru / git_getting_all_remote_branches_updated_in_local_environment.md
Created Mar 30, 2022
How to get all the code from remote repository from all the available remote branches.
View git_getting_all_remote_branches_updated_in_local_environment.md
git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git fetch --all
git pull --all
@davidjguru
davidjguru / _intro_drupal_8_9_getting_data_from_user_account.md
Last active Feb 17, 2022
Drupal 8 || 9 - Getting data from user account in Drupal
View _intro_drupal_8_9_getting_data_from_user_account.md
@davidjguru
davidjguru / _introduction_drupal_8_9_getting_info_about_services_using_drush.md
Last active Feb 17, 2022
Drupal 8 || 9 - Getting info about available services in your Drupal installation
View _introduction_drupal_8_9_getting_info_about_services_using_drush.md

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 Nov 10, 2021
Drupal 8 || 9 - Configure your PHPUnit environment for functional testing
View drupal_8_9_configure_phpunit_for_testing.md
@davidjguru
davidjguru / .configure_lando_for_debugging_in_decoupled_drupal_installation.md
Last active Dec 17, 2021
Decoupled Drupal using Lando in Containers: Configuration for Debugging
View .configure_lando_for_debugging_in_decoupled_drupal_installation.md

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 Oct 25, 2021
Drupal 8 || 9 - Getting Entity Reference ID from GraphQL Field Resolvers
View drupal_9_getting_entity_reference_id_in_graphql.md
$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 Oct 16, 2021
Debugging from VSCode: some launch.json example files
View ddev_drupal_launch.json
{
"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 Oct 26, 2021
Upgrading from Drupal 8 to Drupal 9: My favourite articles
View davidjguru_upgrading_from_drupal8_to_drupal9_my_favourite_articles.md
@davidjguru
davidjguru / drupal_8_9_composing_directions_files_graphql_using_data_producers_in_field_resolvers.md
Last active Sep 18, 2021
Drupal 8 || 9 - Composing directions for files from GraphQL using Data Producers in Fields Resolvers
View drupal_8_9_composing_directions_files_graphql_using_data_producers_in_field_resolvers.md

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