class OptionsTestHooks
Hook implementations for options_test.
Hierarchy
- class \Drupal\options_test\Hook\OptionsTestHooks
Expanded class hierarchy of OptionsTestHooks
File
-
core/
modules/ options/ tests/ options_test/ src/ Hook/ OptionsTestHooks.php, line 13
Namespace
Drupal\options_test\HookView source
class OptionsTestHooks {
/**
* Implements hook_form_FORM_ID_alter().
*/
public function formEntityTestEntityTestFormAlter(&$form, FormStateInterface $form_state, $form_id) : void {
if (\Drupal::state()->get('options_test.form_alter_enable', FALSE)) {
$form['card_1']['widget']['#required_error'] = t('This is custom message for required field.');
}
}
/**
* Implements hook_options_list_alter().
*/
public function optionsListAlter(array &$options, array $context) {
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]);
}
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
OptionsTestHooks::formEntityTestEntityTestFormAlter | public | function | Implements hook_form_FORM_ID_alter(). |
OptionsTestHooks::optionsListAlter | public | function | Implements hook_options_list_alter(). |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.