You are here

public static function OptionsShsWidget::isApplicable in Simple hierarchical select 2.0.x

Same name and namespace in other branches
  1. 8 src/Plugin/Field/FieldWidget/OptionsShsWidget.php \Drupal\shs\Plugin\Field\FieldWidget\OptionsShsWidget::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

File

src/Plugin/Field/FieldWidget/OptionsShsWidget.php, line 311

Class

OptionsShsWidget
Plugin implementation of the 'options_shs' widget.

Namespace

Drupal\shs\Plugin\Field\FieldWidget

Code

public static function isApplicable(FieldDefinitionInterface $field_definition) {

  // The widget currently only works for taxonomy terms.
  if ($field_definition
    ->getSetting('target_type') !== 'taxonomy_term') {
    return FALSE;
  }

  // The widget only works with fields having one target bundle as source.
  $handler_settings = $field_definition
    ->getSetting('handler_settings');
  return isset($handler_settings['target_bundles']) && count($handler_settings['target_bundles']) === 1;
}