nerdfisch: DevBits

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

12.02.2026 | Michael Ebert

Get value of an entity field

entity_field_value.php
// For single value fields.
$entity->field_name->value;

// If you don`t know the main property.
$main_property_name = $entity->field_name->getMainPropertyName();

// For multiple value fields.
$entity->field_name->getValue();
php
field values
entities
12.02.2026 | Pascal Crott

Dynamically remove entity_reference value from views exposed filter via flag

my_module.module
<?php

use Drupal\Component\Utility\Html;
use Drupal\Core\Form\FormStateInterface;


/**
 * Implements hook_form_FORM_ID_alter() for 'views_exposed_form'.
 */
function hook_form_views_exposed_form_alter(&$form, FormStateInterface $form_state) {
  // Configure the values to your needs.
  $view_name = 'my_view';
  $display_name = 'my_display';
  $entity_type_id = 'taxonomy_term';
  $reference_field = 'field_category';
  // The field on the referenced entity.
  $flag_on_reference_field = 'field_hide_on_exposed_form';

  if ($form['#id'] == Html::getId("views-exposed-form-{$view_name}-{$display_name}")) {
    $entity_storage = \Drupal::entityTypeManager()->getStorage($entity_type_id);
    $options = &$form[$reference_field]['#options'];
    foreach ($entity_storage->loadMultiple(array_keys($options)) as $id => $entity) {
      if ($entity->hasField($flag_on_reference_field) && !$entity->{$flag_on_reference_field}->isEmpty()) {
        unset($options[$id]);
      }
    }
  }
}

module
views
exposed filters
copy-paste
potential module
05.02.2026 | Mathias Grab

How to create a <pubDate> date pattern (RFC822) to be used with Views RSS feeds

 This snippet is an example config for a date format in Drupal which can be imported.

rss_feed_date_format.yml
langcode: en
status: true
dependencies: {  }
id: rss_feed_date_format
label: RFC822
locked: false
pattern: 'D, d M Y h:i:s O'

 

Change the date format via Sitebuilding
In the administrative menu open Configuration -> Region and language -> Date and time formats or open the path /admin/config/regional/date-time.
Then use the button "+ Add format".

Sitebuilding date format 1

 

 

Sitebuilding date format 2
  

Here you can give your new date format a label and enter D, d M Y h:i:s O as a fitting RFC822 <pubDate> format.

Sitebuilding date format 3

For more information about PHP date format options, see the official PHP documentation.

yml / yaml
time and date
RSS
05.02.2026 | Michael Ebert

Make a database dump including data from an ignored table

drush_override_ignored_table_list.sql
drush sql:dump --structure-tables-list=cache,cachetags,'cache_*',history,'search_*',sessions,webprofiler
drush
databases
29.01.2026 | Peter Gerken

Manipulate Form Data before Submit

formDataManipulation.js
// Modifies form data on submit.
form.addEventListener("formdata", (e) => {
  const formData = e.formData;
  geoLocationFieldNames.forEach((name) => {
    formData.delete(name);
  });
});

js
manipulating forms
functional frontend