hook_field_widget_form_alter(&$element, \Drupal\Core\Form\FormStateInterface $form_state, $context)
Alter forms for field widgets provided by other modules.
$element: The field widget form element as constructed by hook_field_widget_form().
$form_state: The current state of the form.
$context: An associative array containing the following key-value pairs:
\Drupal\Core\Field\WidgetBase::formSingleElement()
hook_field_widget_WIDGET_TYPE_form_alter()
function hook_field_widget_form_alter(&$element, \Drupal\Core\Form\FormStateInterface $form_state, $context) { // Add a css class to widget form elements for all fields of type mytype. $field_definition = $context['items']->getFieldDefinition(); if ($field_definition->getType() == 'mytype') { // Be sure not to overwrite existing attributes. $element['#attributes']['class'][] = 'myclass'; } }
© 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!field!field.api.php/function/hook_field_widget_form_alter/8.1.x