nerdfisch: DevBits

Kleine, aber feine Code-Snippets, nützliche Tweaks und elegante Lösungsansätze aus dem Entwickler-Alltag

02.04.2026 | Michael Ebert

Set a custom theme to be used by Symfony Mailer

symfony_mailer.mailer_policy._.yml
configuration:
  email_theme:
    theme: my_custom_theme

yml / yaml
symfony
mail
themes
02.04.2026 | Lothar Ferreira Neumann

Updating user roles using a module update hook

switch_roles.install
<?php

use Drupal\user\RoleInterface;

/**
 * Remove the old roles and replace them with the new ones.
 */
function MY_MODULE_update_9041(): void {
  $em = \Drupal::entityTypeManager();
  $user_storage = $em->getStorage('user');

  // Ensure the new role exists. If not, create it first.
  $role_storage = $em->getStorage('user_role');
  if ($role_storage->load('new_role') === NULL) {
    /** @var \Drupal\user\RoleInterface $role */
    $role = $role_storage->create([
      'id' => 'new_role',
      'label' => 'New role',
    ]);
    $role->save();
  }

  $uids = \Drupal::entityQuery('user')
    ->accessCheck(FALSE)
    ->execute();

  if (empty($uids)) {
    return;
  }

  /** @var \Drupal\user\UserInterface[] $users */
  $users = $user_storage->loadMultiple($uids);

  foreach ($users as $user) {
    if ($user->hasRole('old_role')) {
      $user->addRole('new_role');
      $user->removeRole('old_role');
    }

    $user->save();
  }
}
install
update hooks
roles and permissions
entity API
access control
user
Migration
26.03.2026 | Pascal Crott

Clear plugin manager cache

my_module.module
\Drupal::service('plugin_id.manager')->clearCachedDefinitions();
// Clear entity_type plugin cache.
\Drupal::entityTypeManager()->clearCachedDefinitions();
cache
plugins
26.03.2026 | Dominik Wille

Quick start: module testing on drupal.org

add-gitlab-ci.sh
curl https://git.drupalcode.org/project/gitlab_templates/-/raw/main/gitlab-ci/template.gitlab-ci.yml > .gitlab-ci.yml

sh
automated tests
drupal
modules
19.03.2026 | Peter Gerken

Block raw network access for a container

docker-compose.offline.yml
services:
  web:
    cap_drop:
      - NET_RAW
yml / yaml
local development
docker
copy-paste