nerdfisch: DevBits

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

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
18.12.2025 | Michael Böker

How to add a password field to an entity as the Field_UI has none to offer

PasswordItem.php
/**
 * Defines the 'password' entity field type.
 *
 * @FieldType(
 *   id = "password",
 *   label = @Translation("Password"),
 *   description = @Translation("An entity field containing a password value."),
 *   no_ui = TRUE,
 * )
 */
php
drupal
fields
field_ui
Security
databases
12.12.2025 | Michael Ebert

Render field with given formatter type programmatically

my_module.module
$field_render_array = $entity->{$field_name}->view([
  'type' => 'default_formatter', // Replace with desired formatter type.
  'label' => 'hidden', // If you want to hide the label of the field (optional).
  'settings' => [
    'trim_length' => 100, // Example for textfields: Trim the text to 100 characters.
  ],
]);
field values
fields