You are here

function views_ui_add_limited_validation in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views_ui/admin.inc \views_ui_add_limited_validation()
  2. 9 core/modules/views_ui/admin.inc \views_ui_add_limited_validation()

Processes a non-JavaScript fallback submit button to limit its validation errors.

1 string reference to 'views_ui_add_limited_validation'
views_ui_add_ajax_trigger in core/modules/views_ui/admin.inc
Converts a form element in the add view wizard to be AJAX-enabled.

File

core/modules/views_ui/admin.inc, line 122
Provides the Views' administrative interface.

Code

function views_ui_add_limited_validation($element, FormStateInterface $form_state) {

  // Retrieve the AJAX triggering element so we can determine its parents. (We
  // know it's at the same level of the complete form array as the submit
  // button, so all we have to do to find it is swap out the submit button's
  // last array parent.)
  $array_parents = $element['#array_parents'];
  array_pop($array_parents);
  $array_parents[] = $element['#views_ui_ajax_data']['trigger_key'];
  $ajax_triggering_element = NestedArray::getValue($form_state
    ->getCompleteForm(), $array_parents);

  // Limit this button's validation to the AJAX triggering element, so it can
  // update the form for that change without requiring that the rest of the
  // form be filled out properly yet.
  $element['#limit_validation_errors'] = [
    $ajax_triggering_element['#parents'],
  ];

  // If we are in the process of a form submission and this is the button that
  // was clicked, the form API workflow in \Drupal::formBuilder()->doBuildForm()
  // will have already copied it to $form_state->getTriggeringElement() before
  // our #process function is run. So we need to make the same modifications in
  // $form_state as we did to the element itself, to ensure that
  // #limit_validation_errors will actually be set in the correct place.
  $clicked_button =& $form_state
    ->getTriggeringElement();
  if ($clicked_button && $clicked_button['#name'] == $element['#name'] && $clicked_button['#value'] == $element['#value']) {
    $clicked_button['#limit_validation_errors'] = $element['#limit_validation_errors'];
  }
  return $element;
}