Skip to content

Instantly share code, notes, and snippets.

View megclaypool's full-sized avatar

Meg Claypool megclaypool

View GitHub Profile
@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;

Ok, so

  • $thingie is your node, or paragraph, or whatever. You're probably writing this code in your thingie's preprocess hook
  • field_paragraph is a paragraph field whose inner data you want to plunder
  • desired_field is the actual field inside the paragraph whose data you need
// First, check that the field exists and isn't empty
if ($thingie->hasField('field_paragraph') && !$thingie->field_paragraph->isEmpty()) {
  
  // In this case, this is a single value field. Otherwise you might need to set up a loop or call a specific entry

Redirecting visitors from an auto-generated taxonomy term page to a node (like a landing page) is totally doable, but there's a trick to it!

You can't just type the auto-generated url for the taxonomy term into the redirect; for whatever reason it just doesn't work. (For example, "resource-types/law-overviews" wouldn't work.) Instead, you need to use the taxonomy term number.

Go to the term listing page for the taxonomy. Click or hover over the edit button to get the edit url, which incldes the term number.

Then in the redirect, you put /taxonomy/term/THE-TERM-NUMBER-YOU-JUST-FOUND into the "From" field, and use autocomplete to select the desired node "To" field.

ex: From: /taxonomy/term/118