nerdfisch: DevBits

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

13.04.2026 | Pascal Crott

Restore AJAX functionality when using Slick Slider and Layout Builder

Uses new Drupal "once" Library without using JQuery (see: https://www.drupal.org/node/3158256).

content-carousel.js
          slick.on('breakpoint', function (e, _) {
            if (settings.isLayoutBuilder) {
              once.remove('ajax', '.use-ajax', _.$slideTrack[0]);
              Drupal.ajax.bindAjaxLinks(_.$slideTrack[0]);
            }
          });
js
ajax
slick slider
layout builder
once
13.04.2026 | Marc Hitscherich

Chrome: Bypass NET::ERR_CERT_INVALID

Issue:

If a website has an invalid SSL certificate there might be no way to bypass the validation warning and access the actual website. Especially in Chrome sometimes the button beneath the error message to explicitly bypass the certificate warning is not available.

Solution:

To access a website despite an invalid certificate in Chrome, place the cursor somewhere on the browser window and try typing »thisisunsafe«.

Chrome
Black magic
browser
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