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.
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:
hook_options_list()
function hook_options_list_alter(array &$options, array $context) { // Check if this is the field we want to change. if ($context['field']->id() == 'field_option') { // Change the label of the empty option. $options['_none'] = t('== Empty =='); } }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!options!options.api.php/function/hook_options_list_alter/8.1.x