hook_options_list_alter

hook_options_list_alter(array &$options, array $context)

Alters the list of options to be displayed for a field.

This hook can notably be used to change the label of the empty option.

Parameters

array $options: The array of options for the field, as returned by \Drupal\Core\TypedData\OptionsProviderInterface::getSettableOptions(). An empty option (_none) might have been added, depending on the field properties.

array $context: An associative array containing:

See also

hook_options_list()

Related topics

Hooks
Define functions that alter the behavior of Drupal core.

File

core/modules/options/options.api.php, line 31
Hooks provided by the Options module.

Code

function hook_options_list_alter(array &$options, array $context) {
  // Check if this is the field we want to change.
  if ($context['fieldDefinition']->id() == 'field_option') {
    // Change the label of the empty option.
    $options['_none'] = t('== Empty ==');
  }
}
doc_Drupal
2016-10-29 09:18:24
Comments
Leave a Comment

Please login to continue.