function OptionsTestHooks::optionsListAlter

Same name and namespace in other branches
  1. 11.x core/modules/options/tests/options_test/src/Hook/OptionsTestHooks.php \Drupal\options_test\Hook\OptionsTestHooks::optionsListAlter()

Implements hook_options_list_alter().

Attributes

#[Hook('options_list_alter')]

File

core/modules/options/tests/options_test/src/Hook/OptionsTestHooks.php, line 28

Class

OptionsTestHooks
Hook implementations for options_test.

Namespace

Drupal\options_test\Hook

Code

public function optionsListAlter(array &$options, array $context) : void {
  if ($context['fieldDefinition']->getName() === 'card_4' && $context['widget']->getPluginId() === 'options_select') {
    // Rename _none option.
    $options['_none'] = '- Select something -';
  }
  if ($context['fieldDefinition']->getName() === 'card_4' && $context['entity']->bundle() === 'entity_test') {
    // Remove 0 option.
    unset($options[0]);
  }
}

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