API page: https://api.drupal.org/api/drupal/core%21modules%21options%21options.api...
While trying to use the sample provided on the api page i get the following error:
Error: Call to a member function id() on null in mymodule_options_list_alter()
The field information is stored in $context['fieldDefinition'] object for now.
To get the field name the sample should look the following way.
function hook_options_list_alter(array &$options, array $context) {
// Check if this is the field we want to change.
if ($context['fieldDefinition']->getName() == 'field_option') {
// Change the label of the empty option.
$options['_none'] = t('== Empty ==');
}
}
The ->id() function from the existing sample would return bundle / entity_type and the actual fieldname.
Comments
Comment #2
steffenrComment #3
david.gil commentedI can confirm the problem, i am working in a patch
Comment #4
david.gil commentedHi,
i attach the patch that solves the documentation problem.
Best
Comment #5
david.gil commentedComment #6
keopxLooks fine
Comment #8
catchCommitted/pushed to 8.3.x and cherry-picked to 8.2.x. Thanks!