public static function CshsWidget::isApplicable in Client-side Hierarchical Select 8.2
Same name and namespace in other branches
- 8.3 src/Plugin/Field/FieldWidget/CshsWidget.php \Drupal\cshs\Plugin\Field\FieldWidget\CshsWidget::isApplicable()
- 8 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 48
Class
- CshsWidget
- Provides "cshs" field widget.
Namespace
Drupal\cshs\Plugin\Field\FieldWidgetCode
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 %field because it is not using the default entity reference selection handler or not configured to use a single taxonomy vocabulary. 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;
}