diff --git a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php index 70bb21a..e790916 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php +++ b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php @@ -410,65 +410,6 @@ public function buildOptionsForm(&$form, &$form_state) { } /** - * A submit handler that is used for storing temporary items when using - * multi-step changes, such as ajax requests. - */ - function submitTemporaryForm($form, &$form_state) { - // Run it through the handler's submit function. - $this->submitOptionsForm($form['options'], $form_state); - $item = $this->options; - $types = ViewExecutable::viewsHandlerTypes(); - - // For footer/header $handler_type is area but $type is footer/header. - // For all other handle types it's the same. - $handler_type = $type = $form_state['type']; - if (!empty($types[$type]['type'])) { - $handler_type = $types[$type]['type']; - } - - $override = NULL; - $executable = $form_state['view']->get('executable'); - if ($executable->display_handler->useGroupBy() && !empty($item['group_type'])) { - if (empty($executable->query)) { - $executable->initQuery(); - } - $aggregate = $executable->query->get_aggregation_info(); - if (!empty($aggregate[$item['group_type']]['handler'][$type])) { - $override = $aggregate[$item['group_type']]['handler'][$type]; - } - } - - // Create a new handler and unpack the options from the form onto it. We - // can use that for storage. - $handler = views_get_handler($item['table'], $item['field'], $handler_type, $override); - $handler->init($executable, $executable->display_handler, $item); - - // Add the incoming options to existing options because items using - // the extra form may not have everything in the form here. - $options = $form_state['values']['options'] + $this->options; - - // This unpacks only options that are in the definition, ensuring random - // extra stuff on the form is not sent through. - $handler->unpackOptions($handler->options, $options, NULL, FALSE); - - // Store the item back on the view. - $executable = $form_state['view']->get('executable'); - $executable->temporary_options[$type][$form_state['id']] = $handler->options; - - // @todo Decide if \Drupal\views_ui\Routing\ViewsUIController::ajaxForm() is - // perhaps the better place to fix the issue. - // \Drupal\views_ui\Routing\ViewsUIController::ajaxForm() drops the current - // form from the stack, even if it's an #ajax. So add the item back to the top - // of the stack. - $form_state['view']->addFormToStack($form_state['form_key'], $form_state['display_id'], $type, $item['id'], TRUE); - - $form_state['rerender'] = TRUE; - $form_state['rebuild'] = TRUE; - // Write to cache - views_ui_cache_set($form_state['view']); - } - - /** * Provides a fake field instance. * * @param string $formatter diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php index 6f8b440..975ee36 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php @@ -941,7 +941,7 @@ public static function breakPhraseString($str, &$handler = NULL) { /** * Displays the Expose form. */ - function displayExposedForm($form, &$form_state) { + public function displayExposedForm($form, &$form_state) { $item = &$this->options; // flip $item['exposed'] = empty($item['exposed']); @@ -961,4 +961,63 @@ function displayExposedForm($form, &$form_state) { $form_state['force_expose_options'] = TRUE; } + /** + * A submit handler that is used for storing temporary items when using + * multi-step changes, such as ajax requests. + */ + public function submitTemporaryForm($form, &$form_state) { + // Run it through the handler's submit function. + $this->submitOptionsForm($form['options'], $form_state); + $item = $this->options; + $types = ViewExecutable::viewsHandlerTypes(); + + // For footer/header $handler_type is area but $type is footer/header. + // For all other handle types it's the same. + $handler_type = $type = $form_state['type']; + if (!empty($types[$type]['type'])) { + $handler_type = $types[$type]['type']; + } + + $override = NULL; + $executable = $form_state['view']->get('executable'); + if ($executable->display_handler->useGroupBy() && !empty($item['group_type'])) { + if (empty($executable->query)) { + $executable->initQuery(); + } + $aggregate = $executable->query->get_aggregation_info(); + if (!empty($aggregate[$item['group_type']]['handler'][$type])) { + $override = $aggregate[$item['group_type']]['handler'][$type]; + } + } + + // Create a new handler and unpack the options from the form onto it. We + // can use that for storage. + $handler = views_get_handler($item['table'], $item['field'], $handler_type, $override); + $handler->init($executable, $executable->display_handler, $item); + + // Add the incoming options to existing options because items using + // the extra form may not have everything in the form here. + $options = $form_state['values']['options'] + $this->options; + + // This unpacks only options that are in the definition, ensuring random + // extra stuff on the form is not sent through. + $handler->unpackOptions($handler->options, $options, NULL, FALSE); + + // Store the item back on the view. + $executable = $form_state['view']->get('executable'); + $executable->temporary_options[$type][$form_state['id']] = $handler->options; + + // @todo Decide if \Drupal\views_ui\Routing\ViewsUIController::ajaxForm() is + // perhaps the better place to fix the issue. + // \Drupal\views_ui\Routing\ViewsUIController::ajaxForm() drops the current + // form from the stack, even if it's an #ajax. So add the item back to the top + // of the stack. + $form_state['view']->addFormToStack($form_state['form_key'], $form_state['display_id'], $type, $item['id'], TRUE); + + $form_state['rerender'] = TRUE; + $form_state['rebuild'] = TRUE; + // Write to cache + views_ui_cache_set($form_state['view']); + } + } diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php index 0be0173..e485068 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php @@ -2043,7 +2043,7 @@ public function rescanThemes($form, &$form_state) { /** * Displays the Change Theme form. */ - function changeThemeForm($form, &$form_state) { + public function changeThemeForm($form, &$form_state) { // This is just a temporary variable. $form_state['view']->theme = $form_state['values']['theme']; diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/filter/FilterPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/filter/FilterPluginBase.php index 6a55283..7289e14 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/filter/FilterPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/filter/FilterPluginBase.php @@ -416,7 +416,7 @@ function show_build_group_button(&$form, &$form_state) { /** * Displays the Build Group form. */ - function buildGroupForm($form, &$form_state) { + public function buildGroupForm($form, &$form_state) { $item = &$this->options; // flip. If the filter was a group, set back to a standard filter. $item['is_grouped'] = empty($item['is_grouped']); @@ -1085,7 +1085,7 @@ function build_group_form(&$form, &$form_state) { /** * Add a new group to the exposed filter groups. */ - function addGroupForm($form, &$form_state) { + public function addGroupForm($form, &$form_state) { $item = &$this->options; // Add a new row. diff --git a/core/modules/views/views_ui/lib/Drupal/views_ui/Form/ConfigItem.php b/core/modules/views/views_ui/lib/Drupal/views_ui/Form/ConfigItem.php index 34fc7e9..f178902 100644 --- a/core/modules/views/views_ui/lib/Drupal/views_ui/Form/ConfigItem.php +++ b/core/modules/views/views_ui/lib/Drupal/views_ui/Form/ConfigItem.php @@ -157,10 +157,14 @@ public function build(array $form, array &$form_state) { $name = $form_state['update_name']; } - $view->getStandardButtons($form, $form_state, 'views_ui_config_item_form', $name, t('Remove'), 'remove'); - // Only validate the override values, because this values are required for - // the override selection. - $form['buttons']['remove']['#limit_validation_errors'] = array(array('override')); + $view->getStandardButtons($form, $form_state, 'views_ui_config_item_form', $name); + // Add a 'remove' button. + $form['buttons']['remove'] = array( + '#type' => 'submit', + '#value' => t('Remove'), + '#submit' => array(array($this, 'remove')), + '#limit_validation_errors' => array(array('override')), + ); } if ($save_ui_cache) { @@ -234,4 +238,22 @@ public function submit(array &$form, array &$form_state) { views_ui_cache_set($form_state['view']); } + /** + * Submit handler for removing an item from a view + */ + public function remove(&$form, &$form_state) { + // Store the item back on the view + list($was_defaulted, $is_defaulted) = $form_state['view']->getOverrideValues($form, $form_state); + $executable = $form_state['view']->get('executable'); + // If the display selection was changed toggle the override value. + if ($was_defaulted != $is_defaulted) { + $display = &$executable->displayHandlers->get($form_state['display_id']); + $display->optionsOverride($form, $form_state); + } + $executable->removeItem($form_state['display_id'], $form_state['type'], $form_state['id']); + + // Write to cache + views_ui_cache_set($form_state['view']); + } + } diff --git a/core/modules/views/views_ui/lib/Drupal/views_ui/Form/ViewsFormBase.php b/core/modules/views/views_ui/lib/Drupal/views_ui/Form/ViewsFormBase.php index ff23906..b8f7fd5 100644 --- a/core/modules/views/views_ui/lib/Drupal/views_ui/Form/ViewsFormBase.php +++ b/core/modules/views/views_ui/lib/Drupal/views_ui/Form/ViewsFormBase.php @@ -52,23 +52,13 @@ public function getFormState(ViewStorageInterface $view, $display_id, $js) { /** * Provides a generic entry point to handle AJAX forms. * - * @param string $js - * If this is an AJAX form, it will be the string 'ajax'. Otherwise, it will - * be 'nojs'. This determines the response. - * @param string $key - * A string representing a section of the Views UI. * @param \Drupal\views\ViewStorageInterface $view * The view being edited. * @param string|null $display_id * The display ID being edited, or NULL to load the first available display. - * @param string|null $type - * If $key is 'add-item' or 'config-item', this is the type of handler being - * edited. Otherwise, it is the subsection of the Views UI. For example, the - * 'display' section has 'access' as a subsection, or the 'config-item' has - * 'style' as a handler type. NULL if the section has no subsections. - * @param string|null $id - * If $key is 'config-item', then this will be the plugin ID of the handler. - * Otherwise it will be NULL. + * @param string $js + * If this is an AJAX form, it will be the string 'ajax'. Otherwise, it will + * be 'nojs'. This determines the response. * * @return array * An form for a specific operation in the Views UI, or an array of AJAX @@ -155,7 +145,7 @@ public function ajaxForm(ViewStorageInterface $view, $display_id, $js) { } elseif (!$form_state['ajax']) { // if nothing on the stack, non-js forms just go back to the main view editor. - return new RedirectResponse(url("admin/structure/views/view/{$view->id()}/edit", array('absolute' => TRUE))); + return new RedirectResponse(url("admin/structure/views/view/{$view->id()}/edit/$form_state[display_id]", array('absolute' => TRUE))); } else { $response = new AjaxResponse(); diff --git a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewUI.php b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewUI.php index 09c6410..97d633c 100644 --- a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewUI.php +++ b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewUI.php @@ -245,7 +245,7 @@ public function standardCancel($form, &$form_state) { * TODO: Is the hidden op operator still here somewhere, or is that part of the * docblock outdated? */ - public function getStandardButtons(&$form, &$form_state, $form_id, $name = NULL, $third = NULL, $submit = NULL) { + public function getStandardButtons(&$form, &$form_state, $form_id, $name = NULL) { $form['buttons'] = array( '#prefix' => '
', '#suffix' => '
', @@ -304,21 +304,6 @@ public function getStandardButtons(&$form, &$form_state, $form_id, $name = NULL, '#validate' => array(), ); - // Some forms specify a third button, with a name and submit handler. - if ($third) { - if (empty($submit)) { - $submit = 'third'; - } - $third_submit = function_exists($form_id . '_' . $submit) ? $form_id . '_' . $submit : array($this, 'standardCancel'); - - $form['buttons'][$submit] = array( - '#type' => 'submit', - '#value' => $third, - '#validate' => array(), - '#submit' => array($third_submit), - ); - } - // Compatibility, to be removed later: // TODO: When is "later"? // We used to set these items on the form, but now we want them on the $form_state: if (isset($form['#title'])) {