interface OptionsAllowedValuesInterface

Same name and namespace in other branches
  1. 11.x core/modules/options/src/OptionsAllowedValuesInterface.php \Drupal\options\OptionsAllowedValuesInterface

Provides an interface to get allowed values for a list field.

Hierarchy

Expanded class hierarchy of OptionsAllowedValuesInterface

All classes that implement OptionsAllowedValuesInterface

7 files declare their use of OptionsAllowedValuesInterface
ListField.php in core/modules/options/src/Plugin/views/filter/ListField.php
ListItemBase.php in core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php
NumberListField.php in core/modules/options/src/Plugin/views/argument/NumberListField.php
options.module in core/modules/options/options.module
OptionsAllowedValuesTest.php in core/modules/options/tests/src/Kernel/OptionsAllowedValuesTest.php

... See full list

File

core/modules/options/src/OptionsAllowedValuesInterface.php, line 13

Namespace

Drupal\options
View source
interface OptionsAllowedValuesInterface {
  
  /**
   * Returns the array of allowed values for a list field.
   *
   * The strings are not safe for output. Keys and values of the array should be
   * sanitized through \Drupal\Core\Field\AllowedTagsXssTrait::fieldFilterXss()
   * before being displayed.
   *
   * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $definition
   *   The field storage definition.
   * @param \Drupal\Core\Entity\FieldableEntityInterface|null $entity
   *   (optional) The specific entity when this function is called from the
   *   context of a specific field on a specific entity. This allows custom
   *   'allowed_values_function' callbacks to either restrict the values or
   *   customize the labels for particular bundles and entities. NULL when
   *   there is not a specific entity available, such as for Views filters.
   *
   * @return array
   *   The array of allowed values. Keys of the array are the raw stored values
   *   (number or text), values of the array are the display labels.
   *
   * @see callback_allowed_values_function()
   */
  public function getAllowedValues(FieldStorageDefinitionInterface $definition, ?FieldableEntityInterface $entity = NULL) : array;

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.