Allowed Values Functions
This module allows you to easily define allowed values for fields by using an attribute on a method. You no longer need to configure this directly in field storage definitions.
This module simplifies the process of using a method for a field's allowed values.
Normally, you have to set the method directly in the field’s StorageConfig — either in the configuration file or via hook_entity_field_storage_info_alter().
After installing this module, you can simply add the AllowedValuesFunction attribute to the corresponding method and don’t have to worry about anything else.
Example:
#[AllowedValuesFunction('node', 'field_headline_alignment')]
#[AllowedValuesFunction('paragraph', 'field_subheadline_alignment')]
public static function subheadlineAlignmentAllowedValues(FieldStorageDefinitionInterface $definition, ?FieldableEntityInterface $entity = NULL): array {
return [
'left' => t('Left'),
'center' => t('Center'),
'right' => t('Right'),
];
}
Post-Installation
After installation create a class in one of your custom modules and add the method that provides the allowed values for a field. Add the attribute AllowedValuesFunction to the method.
Depends on
Dependencies of the latest stable release
No dependencies recorded for this project.
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.