Skip to content

Instantly share code, notes, and snippets.

View megclaypool's full-sized avatar

Meg Claypool megclaypool

View GitHub Profile
@megclaypool
megclaypool / How to load a Drupal entity by ID in Twig.md.groovy
Created June 19, 2025 18:08
[How to load a Drupal entity by ID in Twig.md]
The magic secret is the drupal_entity function!
```twig
{% set object = drupal_entity('ENTITY_TYPE', ID, 'VIEW_MODE')) %}
```
Ex:
```twig
{% set object = drupal_entity('node', 123, 'default')) %}
```

Database GUIs

If you’d like to use a GUI database client, you’ll need the right connection details and there may even be a command to launch it for you:

  • phpMyAdmin, formerly built into DDEV core, can be installed by running ddev add-on get ddev/ddev-phpmyadmin.
  • Adminer can be installed with ddev add-on get ddev/ddev-adminer
  • The ddev describe command displays the Host: details you’ll need to connect to the db container externally, for example if you’re using an on-host database browser like SequelAce.
  • macOS users can use ddev sequelace to launch the free Sequel Ace database browser, ddev tableplus to launch TablePlus, ddev querious to launch Querious, ddev dbeaver to launch DBeaver, and the obsolete Sequel Pro is also supported with ddev sequelpro. (Each must be installed for the command to exist.)
  • WSL2 and Linux users can use ddev dbeaver to launch DBeaver. (Must be installed for the command to exist.)
  • PhpStorm (and all JetBrains tools) have a nice database browser. (If you use the DDEV Inte
@megclaypool
megclaypool / Using Drush to generate a Drupal UUID.txt
Created May 31, 2025 18:31
This is useful if you need to hand-generate config files in case a field or something didn't get properly created :P
## The command:
```bash
drush php-eval "echo \Drupal::service('uuid')->generate();"
```
Preface with `lando` or `ddev` or whatever as needed for your local dev environment
Note that it'll generate the UUID, then it'll append a % as the program exits. Don't use the % in your UUID 😆
## Example:
1. Make sure your composer file includes the following:
```yml
"extra": {
"installer-paths": {
...
"recipes/{$name}": [
"type:drupal-recipe"
]
}
}

The basic plan:

{% set imagePath = 'public://images/default.jpg' %}
{% set responsiveimagestyle = {
    '#theme': 'responsive_image',
    '#responsive_image_style_id': 'my_responsive_image_style_id',
    '#uri': imagePath,
    '#alt': 'my alt text',
    '#attributes': { class: 'img-responsive', alt: 'my alt text' },
} %}
@megclaypool
megclaypool / GitCommitBestPractices.md
Created May 31, 2025 18:27 — forked from luismts/GitCommitBestPractices.md
Git Tips and Git Commit Best Practices

Git Commit Best Practices

Basic Rules

Commit Related Changes

A commit should be a wrapper for related changes. For example, fixing two different bugs should produce two separate commits. Small commits make it easier for other developers to understand the changes and roll them back if something went wrong. With tools like the staging area and the ability to stage only parts of a file, Git makes it easy to create very granular commits.

Commit Often

Committing often keeps your commits small and, again, helps you commit only related changes. Moreover, it allows you to share your code more frequently with others. That way it‘s easier for everyone to integrate changes regularly and avoid having merge conflicts. Having large commits and sharing them infrequently, in contrast, makes it hard to solve conflicts.

  1. Install the Sidebery extension
  2. In Firefox, open about:support
  3. Scroll down to Profile Folder and click the Show in Finder button
  4. Within the gobbldygook folder that appears, open the chrome folder.
  5. Open the userChrome.css file in a text editor.
  6. Paste the contents of the sidebery.css file into it
  7. Relaunch Firefox

Ok, so

  • $thingie is your node, or paragraph, or whatever. You're probably writing this code in your thingie's preprocess hook
  • field_reference is the entity reference field that's referring to your taxonomy term whose inner data you want to plunder
  • desired_field is the actual field inside the taxonomy term whose data you need
// Make sure the field exists and isn't empty
if ($thingie->hasField('field_reference') && !$thingie->get('field_reference')->isEmpty()) {
  // This is a taxonomy term reference, so I need to get the term id, then load it to get the term data.
  $termreference = $thingie->get('field_reference')->target_id;