protected function SelectOtherWidget::getDefaultValue in CCK Select Other 8
Get the default values from the items for the form elements.
Parameters
\Drupal\Core\Field\FieldItemListInterface $items: FieldInterface items.
int $delta: The field item to extract.
Return value
array An associative array containing the default value for the select element the default value for the textfield element.
1 call to SelectOtherWidget::getDefaultValue()
- SelectOtherWidget::formElement in src/
Plugin/ Field/ FieldWidget/ SelectOtherWidget.php - Returns the form for a single field widget.
File
- src/
Plugin/ Field/ FieldWidget/ SelectOtherWidget.php, line 184
Class
- SelectOtherWidget
- Plugin implementation of the 'cck_select_other' widget.
Namespace
Drupal\cck_select_other\Plugin\Field\FieldWidgetCode
protected function getDefaultValue(FieldItemListInterface $items, $delta = 0) {
$item =& $items[$delta];
$option_keys = [];
$options = $this
->getOptions($items
->getEntity());
if (!empty($options)) {
$option_keys = array_keys($options);
}
if (!$item->{$this->column}) {
$values = [
'select' => $this->fieldDefinition
->isRequired() ? '' : '_none',
'textfield' => '',
];
}
elseif (in_array($item->{$this->column}, $option_keys)) {
$values = [
'select' => $item->{$this->column},
'textfield' => '',
];
}
else {
$values = [
'select' => 'other',
'textfield' => $item->{$this->column},
];
}
return $values;
}