Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Allowed Values Functions

Security covered Under active development 2 sites

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.

Drupal 11 · not 10

Ask your assistant about Allowed Values Functions

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

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.

Activity

Tracked releases
5
Tracked since
Mar 2026
Latest release
6 months ago
Releases (12 mo)
5 ▲ from 0
Maintenance
Slowing

Release Timeline

Releases

Version Type Core PHP Release date
1.0.1 Stable 11 Mar 30, 2026
0.0.0 Stable 10–11 Mar 18, 2026
0.0.x-dev Dev 10–11 Mar 18, 2026
1.0.x-dev Dev 11 Mar 18, 2026
1.0.0 Stable 11 Mar 16, 2026