views_ui_add_limited_validation

views_ui_add_limited_validation($element, FormStateInterface $form_state)

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

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'] = array($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;
}
doc_Drupal
2016-10-29 09:55:41
Comments
Leave a Comment

Please login to continue.