Allowed Values Functions
Registering custom allowed values callbacks for Drupal fields normally requires editing StorageConfig files or implementing hooks. This module replaces that boilerplate with a PHP attribute you add directly to your callback method.
Allowed Values Functions is a small but ergonomic developer-experience improvement for Drupal modules that define dynamic allowed values for list fields.
Normally, telling Drupal to use a custom method for a field's allowed values requires either modifying the field's StorageConfig YAML directly or implementing hook_entity_field_storage_info_alter(). Both approaches place configuration in a different location from the code that provides the values, making the relationship harder to trace and easier to break during refactoring.
This module introduces an AllowedValuesFunction PHP attribute. You annotate your callback method directly, and the module wires up the StorageConfig automatically. The attribute accepts the entity type and field name, and you can stack multiple attributes on a single method to cover several fields at once.
The module targets Drupal 11 (with 10.6+ support on the 0.x branch) and is maintained by undpaul, a German Drupal agency with a strong track record of quality contributed modules. Version 1.0.1 is the current stable release, covered by the Drupal security advisory policy.
Let’s talk
Ready to stop worrying
about your Drupal site?
Start with a free audit — no commitment, no jargon. Our engineers will review your site and send you a plain-English report within 48 hours.
0207 490 2311 · hello@websitesupport.io