You are here

function hook_yamlform_element_ELEMENT_TYPE_form_alter in YAML Form 8

Alter form elements for a specific type.

Modules can implement hook_yamlform_element_ELEMENT_TYPE_form_alter() to modify a specific form element, rather than using hook_yamlform_element_alter() and checking the element type.

Parameters

array $element: The form element.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

array $context: An associative array. See hook_field_widget_form_alter() for the structure and content of the array.

See also

\Drupal\yamlform\YamlFormSubmissionForm::prepareElements()

hook_yamlform_element_alter(()

File

./yamlform.api.php, line 78
Hooks related to YAML Form module.

Code

function hook_yamlform_element_ELEMENT_TYPE_form_alter(array &$element, \Drupal\Core\Form\FormStateInterface $form_state, array $context) {

  // Add custom data attributes to a specific element type.
  $element['#attributes']['data-custom'] = '{custom data goes here}';

  // Attach a custom library to the element type.
  $element['#attached']['library'][] = 'MODULE/MODULE.element.ELEMENT_TYPE';
}