nerdfisch: DevBits

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

22.01.2026 | Marc Hitscherich

Fix SSH warning "Remote host identification has changed" after server move.

fix-ssh-warning.sh
# Remove all old entries for my.example.com
ssh-keygen -R my.example.com

# Scan all supported fingerprints from the new server and insert them in your known_hosts file
ssh-keyscan my.example.com >> ~/.ssh/known_hosts
ssh
sh
cli
ssh
Security
Server Administration
Command Line
22.01.2026 | Michael Ebert

Set default access permissions for some roles in VAPN module

my_module.module
use Drupal\Core\Form\FormStateInterface;

function my_module_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  // Add default values for vapn module so the editor don't need to check this.
  if (isset($form['vapn']) && $form_state->getFormObject()->getEntity()->isNew()) {
    $form['vapn']['content']['widget']['#default_value'] = ['anonymous', 'authenticated'];
  }
}
my_module.deploy.php
use Drupal\node\Entity\Node;

function my_module_deploy_vapn_install() {
  $entity_type_manager = \Drupal::service('entity_type.manager');
  $role_storage = $entity_type_manager->getStorage('user_role');
  $node_storage = $entity_type_manager->getStorage('node');
  $nodes = $node_storage->loadByProperties([
    'type' => 'my_bundle'
  ]);

  $roles = array_values($role_storage->loadMultiple(['anonymous', 'authenticated']));
  foreach ($nodes as $node) {
    // First check if already some roles are set. Only needed if you are upgrading vapn.
    if ($node->vapn->isEmpty()) {
      $node->setSyncing(TRUE)
        ->set('vapn', $roles)
        ->save();
    }
  }
}
node access
access control
15.01.2026 | Lothar Ferreira Neumann

How to migrate latitude & longitude geodata into a unified geocode field

geofield_migration.yml
field_geofield:
  plugin: geofield_latlon
  source:
    - field_latitude
    - field_longitude
yml
geodata
Migration
15.01.2026 | Mathias Grab

Show installed module information via composer

terminal.sh
# Syntax.
composer show vendor/package

# Example.
composer show drupal/eca

terminal_result.sh
name     : drupal/eca
descrip. : Event, Conditions, Actions - powerful, versatile, and user-friendly rules engine for Drupal
keywords : 
versions : * 2.1.0
type     : drupal-module
license  : GNU General Public License v2.0 or later (GPL-2.0-or-later) (OSI approved) https://spdx.org/licenses/GPL-2.0-or-later.html#licenseText
homepage : https://www.drupal.org/project/eca
source   : [git] https://git.drupalcode.org/project/eca.git 2.1.0
dist     : [zip] https://ftp.drupal.org/files/projects/eca-2.1.0.zip 2.1.0
path     : /var/www/html/web/modules/contrib/eca
names    : drupal/eca

support
source : https://drupal.org/project/eca
issues : https://drupal.org/project/issues/eca

requires
dragonmantank/cron-expression ^3.1
drupal/core ^10.3||^11
ext-dom *
ext-json *
mtownsend/xml-to-array ^2.0
php >=8.1

requires (dev)
drupal/eca_ui *
drupal/entity_reference_revisions ^1.12
drupal/inline_entity_form ^3.0
drupal/paragraphs ^1.18
drupal/token ^1.15
drupal/webform dev-3465838-drupal-11-compatibility

sh
composer
18.12.2025 | Dominik Wille

How to pass a context to a condition plugin instance

ResolveConditionsWithContext.php
use ConditionAccessResolverTrait;


$conditions = [];
foreach ($conditions as $condition_id => $condition) {
  if ($condition instanceof ContextAwarePluginInterface) {
    try {
      $contexts = $this->contextRepository->getRuntimeContexts(array_values($condition->getContextMapping()));
      $this->contextHandler->applyContextMapping($condition, $contexts);
    }
    catch (MissingValueContextException $e) {
      $missing_value = TRUE;
    }
    catch (ContextException $e) {
      $missing_context = TRUE;
    }
  }
  $conditions[$condition_id] = $condition;
}

$this->resolveConditions($conditions, 'and')
php
drupal
contexts
conditions