public function EntityDisplayTrait::hasSelectOtherWidget in CCK Select Other 8
Determine if a field has the select other widget configured.
This is due to "loose coupling", which makes it difficult for a widget to make constraints upon a field.
Parameters
\Drupal\Core\Field\FieldDefinitionInterface $definition: The field definition to check.
Return value
bool TRUE if the definition has a select other widget defined in one of its form displays.
1 call to EntityDisplayTrait::hasSelectOtherWidget()
- SelectOtherAllowedValuesConstraintValidator::validate in src/
Validation/ Plugin/ Validation/ Constraint/ SelectOtherAllowedValuesConstraintValidator.php - Checks if the passed value is valid.
File
- src/
EntityDisplayTrait.php, line 56
Class
- EntityDisplayTrait
- Provides methods for dealing with entity displays.
Namespace
Drupal\cck_select_otherCode
public function hasSelectOtherWidget(FieldDefinitionInterface $definition) {
$displays = $this
->getFormDisplays($definition, $this
->getEntityTypeManager());
$field_name = $definition
->getName();
return array_reduce($displays, function (&$result, $display) use ($field_name) {
/** @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $display */
if (!$result && $display
->getRenderer($field_name) !== NULL) {
$widget_id = $display
->getRenderer($field_name)
->getPluginId();
if ($widget_id === 'cck_select_other') {
$result = TRUE;
}
}
return $result;
}, FALSE);
}