You are here

public static function CshsWidget::isApplicable in Client-side Hierarchical Select 8

Same name and namespace in other branches
  1. 8.3 src/Plugin/Field/FieldWidget/CshsWidget.php \Drupal\cshs\Plugin\Field\FieldWidget\CshsWidget::isApplicable()
  2. 8.2 src/Plugin/Field/FieldWidget/CshsWidget.php \Drupal\cshs\Plugin\Field\FieldWidget\CshsWidget::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/CshsWidget.php, line 39

Class

CshsWidget
Provides "cshs" field widget.

Namespace

Drupal\cshs\Plugin\Field\FieldWidget

Code

public static function isApplicable(FieldDefinitionInterface $field_definition) : bool {
  if (static::helperIsApplicable($field_definition)) {

    /* @see \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection */
    if (\count($field_definition
      ->getSettings()['handler_settings']['target_bundles'] ?? []) === 1) {
      return TRUE;
    }
    \Drupal::messenger()
      ->addWarning(\t('The client-side hierarchical select widget cannot be used for the %label field. Either change the widget type or configure the %field to use the default entity reference selection handler with only a single vocabulary.', [
      '%label' => $field_definition
        ->getLabel(),
      '%field' => \str_replace('.', ' -> ', $field_definition
        ->id()),
    ]));
  }
  return FALSE;
}