Direkt zum Inhalt

Devbits

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

13.11.2025 | Dominik Wille

Don't list a widget for a field type.

You want to create a custom widget for a field but it should not be available to all fields of this type.

  public static function isApplicable(FieldDefinitionInterface $field_definition) {
    if (isset($field_definition->getDisplayOptions('form')['type'])) {
      return $field_definition->getDisplayOptions('form')['type'] == 'slot_content_weights';
    }

    return FALSE;
  }

Issue:

You want to create a custom widget for a field but it should not be available to all fields of this type.

Solution:

Use the `isApplicable` method to restrict it to this field only.