You are here

public static function ReferenceWidget::isApplicable in Select (or other) 4.x

Same name and namespace in other branches
  1. 8 src/Plugin/Field/FieldWidget/ReferenceWidget.php \Drupal\select_or_other\Plugin\Field\FieldWidget\ReferenceWidget::isApplicable()

Returns if the widget can be used for the provided field.

Parameters

\Drupal\Core\Field\FieldDefinitionInterface $field_definition: The field definition that should be checked.

Return value

bool TRUE if the widget can be used, FALSE otherwise.

Overrides WidgetBase::isApplicable

1 call to ReferenceWidget::isApplicable()
ReferenceWidgetTest::testIsApplicable in tests/src/Unit/ReferenceWidgetTest.php
Tests if the widget correctly determines if it is applicable.

File

src/Plugin/Field/FieldWidget/ReferenceWidget.php, line 248

Class

ReferenceWidget
Plugin implementation of the 'select_or_other_reference' widget.

Namespace

Drupal\select_or_other\Plugin\Field\FieldWidget

Code

public static function isApplicable(FieldDefinitionInterface $field_definition) {
  $options = $field_definition
    ->getSettings();
  $handler_settings = isset($options['handler_settings']) ? $options['handler_settings'] : NULL;
  $handler = \Drupal::service('plugin.manager.entity_reference_selection')
    ->getInstance($options);
  return $handler instanceof SelectionWithAutocreateInterface && isset($handler_settings['auto_create']) && $handler_settings['auto_create'];
}