Skip to main content

Devbit

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.

Dominik Wille

Dominik Wille

Senior Front- und Backend Developer

Ihre Drupal-Website zukunftssicher machen

Wir prüfen Ihr System und zeigen, was Sie für AI, Wartung und Upgrades brauchen.