You are here

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

Same name and namespace in other branches
  1. 8 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 47

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 (!empty($field_definition
      ->getSettings()['handler_settings']['target_bundles'] ?? [])) {
      return TRUE;
    }
    \Drupal::messenger()
      ->addWarning(\t('The client-side hierarchical select widget cannot be used for the %field because it is not using the default entity reference selection handler or has no taxonomy vocabularies selected. If you are aimed to use the CSHS widget for the %label field, please configure it accordingly or ignore this warning as its purpose to let site builders know why the CSHS widget is not an option for this taxonomy reference field.', [
      '%label' => $field_definition
        ->getLabel(),
      // Some fields have no IDs and only names.
      '%field' => \str_replace('.', ' -> ', \method_exists($field_definition, 'id') ? $field_definition
        ->id() : $field_definition
        ->getName()),
    ]));
  }
  return FALSE;
}