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.
Supporting organizations:
Project information
- Project categories: Administration tools, Content editing experience, Developer tools
- Created by stborchert on , updated
Stable releases for this project are covered by the security advisory policy.
Look for the shield icon below.
