Quick Tips

created 230531

This page is for quick tips that may not deserve their own page, but are valuable information for Drupal developers to be aware of

Backend UI/UX

  • March 13, 2023 - If you need to add description text to a media name or label, you can use hook_field_widget_single_element_form_alter().For example, this snipped worked for me (this probably could be improved to better target the entity type).

    /** * Implements hook_field_widget_single_element_form_alter(). */ function MY_MODULE_field_widget_single_element_form_alter(array &$element, &$form_state, array $context) { // Add description to Name field on media add and edit forms. if ($context['items'] && isset($element['value']['#title']) && $element['value']['#title'] == "Name") { $element['value']['#description'] = t('This name is only for internal use and should include any terms that people might search for.'); } }

Contribution / Drupal.org

  • May 11, 2023 - If you want to make sure you don’t miss notifications for modules you maintain on Drupal.org you can set that up in the Issue Notifications tab on your profile.

Errors/Warnings

  • January 29, 2023 - If you have a warning on the status page of a Drupal 9 site saying that there are mismatched entity and/or field definitions, the way to solve it is to go to the entity field config, click on edit for the field to get to the edit form, click the edit Field Settings tab, and then click Save field settings. You can also install devel_entity_updates and run drush entup.

Theming

  • December 27, 2022 - Add the following snippet to your settings.local.php to limit the depth of kint output when outputting large variables:
    Kint 4:

    // Change kint maxLevels setting: if (class_exists('Kint')) { \Kint::$depth_limit = 5; }

    Kint 3:

    // Change kint maxLevels setting: include_once(DRUPAL_ROOT . '/modules/contrib/devel/kint/kint/Kint.class.php'); if(class_exists('Kint')){ // Set the maxlevels to prevent out-of-memory. Currently there doesn't seem to be a cleaner way to set this: Kint::$maxLevels = 4; }
  • January 25, 2023 - The spaceless filter in Twig has been deprecated: Change usages of {% spaceless %} tag, which is deprecated as of Twig 1.38 with {% apply spaceless %} filter

  • May 31, 2023 - If you want to add cache tags and contexts right inside the Twig templates and not in preprocess `{{ {'#cache': {contexts: ['url']}} }}`  or for tags `{{ {'#cache': {tags: ['block_content:123']}} }}


Review History

Who

When

Status

Who

When

Status

 

 

 

Bob

20230531

Created