function views_ui_form_button_was_clicked
Same name in other branches
- 9 core/modules/views_ui/admin.inc \views_ui_form_button_was_clicked()
- 10 core/modules/views_ui/admin.inc \views_ui_form_button_was_clicked()
- 11.x core/modules/views_ui/admin.inc \views_ui_form_button_was_clicked()
#process callback for a button; determines if a button is the form's triggering element.
The Form API has logic to determine the form's triggering element based on the data in POST. However, it only checks buttons based on a single #value per button. This function may be added to a button's #process callbacks to extend button click detection to support multiple #values per button. If the data in POST matches any value in the button's #values array, then the button is detected as having been clicked. This can be used when the value (label) of the same logical button may be different based on context (e.g., "Apply" vs. "Apply and continue").
See also
_form_builder_handle_input_element()
_form_button_was_clicked()
2 string references to 'views_ui_form_button_was_clicked'
- ViewEditForm::renderDisplayTop in core/
modules/ views_ui/ src/ ViewEditForm.php - Render the top of the display so it can be updated during ajax operations.
- ViewUI::getStandardButtons in core/
modules/ views_ui/ src/ ViewUI.php - Provide a standard set of Apply/Cancel/OK buttons for the forms. Also provide a hidden op operator because the forms plugin doesn't seem to properly provide which button was clicked.
File
-
core/
modules/ views_ui/ admin.inc, line 316
Code
function views_ui_form_button_was_clicked($element, FormStateInterface $form_state) {
$user_input = $form_state->getUserInput();
$process_input = empty($element['#disabled']) && ($form_state->isProgrammed() || $form_state->isProcessingInput() && (!isset($element['#access']) || $element['#access']));
if ($process_input && !$form_state->getTriggeringElement() && !empty($element['#is_button']) && isset($user_input[$element['#name']]) && isset($element['#values']) && in_array($user_input[$element['#name']], array_map('strval', $element['#values']), TRUE)) {
$form_state->setTriggeringElement($element);
}
return $element;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.