Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: GoogleTag Manager 2.0.3 Minor update available for module gtm (2.0.3). Release: General Data Protection Regulation Compliance 2.0.2 Minor update available for module gdpr_compliance (2.0.2). Release: Contact Mail 2.0.5 Minor update available for module contact_mail (2.0.5). Release: Contact ajax 3.0.3 Minor update available for module contact_ajax (3.0.3). Release: Commerce ML Starter 2.0.3 Minor update available for module cmlstarter (2.0.3). Release: Commerce ML Migrations 2.0.3 Minor update available for module cmlmigrations (2.0.3). Release: Commerce ML Exchange 2.0.3 Minor update available for module cmlexchange (2.0.3). Release: Cache Alter 3.0.2 Minor update available for module cache_alter (3.0.2). Usage Milestone: Term CSV Export Import Module term_csv_export_import crossed 1,000 active installs. Module Revived: Ai Text 2 Speech 1.2.0 Module tts updated after 10 months of inactivity (1.2.0).

Allowed Values Functions

Security covered Drupal 11 · not 10
View on drupal.org

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.

Activity

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

Release Timeline

Releases

Version Type Core 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