Direkt zum Inhalt

Devbits

Kleine Code-Schnipsel aus unserem Alltag mit Drupal, PHP und DevOps: Problem, Lösung, Code.

06.08.2026 | Lothar Ferreira Neumann

Change custom text field sizes in Gin Backend Theme using Asset Injector

A custom text input field might appear too large in Gin. Our example uses an ID field which will usually never be filled with more than ~7 characters.

To alter the node ID field (nid) of our content view we add this to the file:

/* Views exposed filter: appropriate field widths */
.views-exposed-form #edit-nid {
  max-width: 10ch;
}

Issue:

A custom text input field might appear too large in Gin. Our example uses an ID field which will usually never be filled with more than ~7 characters.

Prerequisites:

Our solution uses the Asset Injector module. This module can be useful for small additions to backend theming. However, there may be cleaner solutions to this, e.g. extending Gin for your project with some custom CSS, defining a custom field type, and more. 

Solution:

Adjust the width of specific Views exposed filter fields using CSS through Asset Injection. This keeps short numeric fields like Node ID compact and improves the layout of the exposed filter form. We are using the Gin backend theme in this example. You can access the asset injector for Gin here:
/admin/config/development/asset-injector/css/gin

Please note:

Don't use Asset Injector for altering a frontend theme.

Before:

Screenshot of the content view with long nid field.

After:

Content view with short nid field

Quick note how to get the right ID for the CSS file, in our case #edit-nid:

The ID of the field is shown in the inspector

24.02.2026 | Lothar Ferreira Neumann

Hide a view if it yields no results

Displaying a view (a list of content) that has no items can be unnecessary if there is no need for a "no results" option. Views that are being hidden when empty can be useful for rich landing pages that aim to provide lots of relevant, additional recent content teasers to the user. However, there…

12.02.2026 | Pascal Crott

Dynamically remove entity_reference value from views exposed filter via flag

A views filter based on taxonomy terms should not show all terms as filterable options, e.g. because they are internal

<?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]);
      }
    }
  }
}

Issue:

A views filter based on taxonomy terms should not show all terms as filterable options, e.g. because they are internal

Solution:

Create a field on your taxonomy to determine whether it should be included in filters, then alter your form so it reacts to the field setting. You can copy-paste the code provided into your module.