function hook_yamlform_element_alter in YAML Form 8
Alter form elements.
Parameters
array $element: The form element.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
array $context: An associative array containing the following key-value pairs:
- form: The form structure to which elements is being attached.
See also
\Drupal\yamlform\YamlFormSubmissionForm::prepareElements()
hook_yamlform_element_ELEMENT_TYPE_form_alter()
1 function implements hook_yamlform_element_alter()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- yamlform_test_custom_properties_yamlform_element_alter in tests/
modules/ yamlform_test_custom_properties/ yamlform_test_custom_properties.module - Implements hook_yamlform_element_alter().
File
- ./
yamlform.api.php, line 47 - Hooks related to YAML Form module.
Code
function hook_yamlform_element_alter(array &$element, \Drupal\Core\Form\FormStateInterface $form_state, array $context) {
// Code here acts on all elements included in a form.
/** @var \Drupal\yamlform\YamlFormSubmissionForm $form_object */
$form_object = $form_state
->getFormObject();
/** @var \Drupal\yamlform\YamlFormSubmissionInterface $yamlform_submission */
$yamlform_submission = $form_object
->getEntity();
/** @var \Drupal\yamlform\YamlFormInterface $yamlform */
$yamlform = $yamlform_submission
->getYamlForm();
// Add custom data attributes to all elements.
$element['#attributes']['data-custom'] = '{custom data goes here}';
}