protected function FarmFieldFactory::modifyListStringField in farmOS 2.x
List string field modifier.
Parameters
\Drupal\Core\Field\BaseFieldDefinition &$field: A base field definition object.
array $options: An array of options.
1 call to FarmFieldFactory::modifyListStringField()
- FarmFieldFactory::buildFieldDefinition in modules/
core/ field/ src/ FarmFieldFactory.php - Builds a field definition with farmOS opinions.
File
- modules/
core/ field/ src/ FarmFieldFactory.php, line 728
Class
- FarmFieldFactory
- Factory for generating farmOS field definitions.
Namespace
Drupal\farm_fieldCode
protected function modifyListStringField(BaseFieldDefinition &$field, array $options = []) {
// Set the allowed values, if specified.
if (!empty($options['allowed_values'])) {
$field
->setSetting('allowed_values', $options['allowed_values']);
}
// Set the allowed values function, if specified.
if (!empty($options['allowed_values_function'])) {
$field
->setSetting('allowed_values_function', $options['allowed_values_function']);
}
// Build form and view display settings.
$field
->setDisplayOptions('form', [
'type' => 'options_buttons',
'weight' => $options['weight']['form'] ?? 0,
]);
$field
->setDisplayOptions('view', [
'label' => 'inline',
'type' => 'list_default',
'weight' => $options['weight']['view'] ?? 0,
]);
}