function options_allowed_values

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 field_filter_xss() before being displayed.

Parameters

$field: The field definition.

$instance: (optional) A field instance array. Defaults to NULL.

\Drupal\Core\Entity\EntityInterface $entity: (optional) The entity object. Defaults to NULL.

Return value

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.

5 calls to options_allowed_values()
FieldList::init in drupal/core/modules/field/lib/Drupal/field/Plugin/views/argument/FieldList.php
Overrides \Drupal\views\Plugin\views\argument\ArgumentPluginBase::init().
ListString::init in drupal/core/modules/field/lib/Drupal/field/Plugin/views/argument/ListString.php
Overrides \Drupal\views\Plugin\views\argument\String::init().
OptionsDefaultFormatter::viewElements in drupal/core/modules/options/lib/Drupal/options/Plugin/field/formatter/OptionsDefaultFormatter.php
Builds a renderable array for a field value.
options_field_validate in drupal/core/modules/options/options.module
Implements hook_field_validate().
options_options_list in drupal/core/modules/options/options.module
Implements hook_options_list().
1 string reference to 'options_allowed_values'
options_field_update_field in drupal/core/modules/options/options.module
Implements hook_field_update_field().

File

drupal/core/modules/options/options.module, line 239
Defines selection, check box and radio button widgets for text and numeric fields.

Code

function options_allowed_values($field, $instance = NULL, EntityInterface $entity = NULL) {
  $allowed_values =& drupal_static(__FUNCTION__, array());
  if (!isset($allowed_values[$field['uuid']])) {
    $function = $field['settings']['allowed_values_function'];

    // If $cacheable is FALSE, then the allowed values are not statically
    // cached. See options_test_dynamic_values_callback() for an example of
    // generating dynamic and uncached values.
    $cacheable = TRUE;
    if (!empty($function)) {
      $values = $function($field, $instance, $entity, $cacheable);
    }
    else {
      $values = $field['settings']['allowed_values'];
    }
    if ($cacheable) {
      $allowed_values[$field['uuid']] = $values;
    }
    else {
      return $values;
    }
  }
  return $allowed_values[$field['uuid']];
}