diff --git a/core/modules/views/lib/Drupal/views/Form/ViewsExposedForm.php b/core/modules/views/lib/Drupal/views/Form/ViewsExposedForm.php index ae3da03..c7db13b 100644 --- a/core/modules/views/lib/Drupal/views/Form/ViewsExposedForm.php +++ b/core/modules/views/lib/Drupal/views/Form/ViewsExposedForm.php @@ -10,6 +10,7 @@ use Drupal\Component\Utility\String; use Drupal\Core\Form\FormBase; use Drupal\views\ExposedFormCache; +use Drupal\views\Views; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -64,8 +65,10 @@ public function buildForm(array $form, array &$form_state) { // multiple times per page. $form_state['must_validate'] = TRUE; /** @var \Drupal\views\ViewExecutable $view */ - $view = $form_state['view']; - $display = &$form_state['display']; + $view = Views::getView($form_state['view_id']); + $view->setDisplay($form_state['display_id']); + $view->initHandlers(); + $display = &$view->display_handler->display; $form_state['input'] = $view->getExposedInput(); @@ -119,7 +122,7 @@ public function buildForm(array $form, array &$form_state) { // $form['#attributes']['class'] = array('views-exposed-form'); /** @var \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase $exposed_form_plugin */ - $exposed_form_plugin = $form_state['exposed_form_plugin']; + $exposed_form_plugin = $view->display_handler->getPlugin('exposed_form'); $exposed_form_plugin->exposedFormAlter($form, $form_state); // Save the form. @@ -132,15 +135,19 @@ public function buildForm(array $form, array &$form_state) { * {@inheritdoc} */ public function validateForm(array &$form, array &$form_state) { + $view = Views::getView($form_state['view_id']); + $view->setDisplay($form_state['display_id']); + $view->initHandlers(); + foreach (array('field', 'filter') as $type) { /** @var \Drupal\views\Plugin\views\HandlerBase[] $handlers */ - $handlers = &$form_state['view']->$type; + $handlers = &$view->$type; foreach ($handlers as $key => $handler) { $handlers[$key]->validateExposed($form, $form_state); } } /** @var \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase $exposed_form_plugin */ - $exposed_form_plugin = $form_state['exposed_form_plugin']; + $exposed_form_plugin = $view->display_handler->getPlugin('exposed_form'); $exposed_form_plugin->exposedFormValidate($form, $form_state); } @@ -148,24 +155,28 @@ public function validateForm(array &$form, array &$form_state) { * {@inheritdoc} */ public function submitForm(array &$form, array &$form_state) { + $view = Views::getView($form_state['view_id']); + $view->setDisplay($form_state['display_id']); + $view->initHandlers(); + foreach (array('field', 'filter') as $type) { /** @var \Drupal\views\Plugin\views\HandlerBase[] $handlers */ - $handlers = &$form_state['view']->$type; + $handlers = &$view->$type; foreach ($handlers as $key => $info) { $handlers[$key]->submitExposed($form, $form_state); } } - $form_state['view']->exposed_data = $form_state['values']; - $form_state['view']->exposed_raw_input = array(); + $view->exposed_data = $form_state['values']; + $view->exposed_raw_input = array(); $exclude = array('submit', 'form_build_id', 'form_id', 'form_token', 'exposed_form_plugin', '', 'reset'); /** @var \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginBase $exposed_form_plugin */ - $exposed_form_plugin = $form_state['exposed_form_plugin']; + $exposed_form_plugin = $view->display_handler->getPlugin('exposed_form'); $exposed_form_plugin->exposedFormSubmit($form, $form_state, $exclude); foreach ($form_state['values'] as $key => $value) { if (!in_array($key, $exclude)) { - $form_state['view']->exposed_raw_input[$key] = $value; + $view->exposed_raw_input[$key] = $value; } } } diff --git a/core/modules/views/lib/Drupal/views/Form/ViewsForm.php b/core/modules/views/lib/Drupal/views/Form/ViewsForm.php index cc01f8d..382aa56 100644 --- a/core/modules/views/lib/Drupal/views/Form/ViewsForm.php +++ b/core/modules/views/lib/Drupal/views/Form/ViewsForm.php @@ -14,6 +14,7 @@ use Drupal\Core\Form\FormInterface; use Drupal\Core\Routing\UrlGeneratorInterface; use Drupal\views\ViewExecutable; +use Drupal\views\Views; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; @@ -113,10 +114,14 @@ public function getFormID() { /** * {@inheritdoc} */ - public function buildForm(array $form, array &$form_state, ViewExecutable $view = NULL, $output = NULL) { + public function buildForm(array $form, array &$form_state, $view_id = NULL, $display_id = NULL, $output = NULL) { $form_state['step'] = isset($form_state['step']) ? $form_state['step'] : 'views_form_views_form'; $form_state['step_controller']['views_form_views_form'] = 'Drupal\views\Form\ViewsFormMainForm'; + $view = Views::getView($view_id); + $view->setDisplay($display_id); + $view->initHandlers(); + // Cache the built form to prevent it from being rebuilt prior to validation // and submission, which could lead to data being processed incorrectly, // because the views rows (and thus, the form elements as well) have changed diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/exposed_form/ExposedFormPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/exposed_form/ExposedFormPluginBase.php index 82e4184..945d73e 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/exposed_form/ExposedFormPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/exposed_form/ExposedFormPluginBase.php @@ -120,8 +120,8 @@ public function buildOptionsForm(&$form, &$form_state) { public function renderExposedForm($block = FALSE) { // Deal with any exposed filters we may have, before building. $form_state = array( - 'view' => &$this->view, - 'display' => &$this->view->display_handler->display, + 'view_id' => $this->view->storage->id(), + 'display_id' => $this->view->current_display, 'method' => 'get', 'rerender' => TRUE, 'no_redirect' => TRUE, @@ -139,7 +139,6 @@ public function renderExposedForm($block = FALSE) { $form_state['ajax'] = TRUE; } - $form_state['exposed_form_plugin'] = $this; $form = \Drupal::formBuilder()->buildForm('\Drupal\views\Form\ViewsExposedForm', $form_state); if (!$this->view->display_handler->displaysExposed() || (!$block && $this->view->display_handler->getOption('exposed_block'))) { @@ -245,6 +244,8 @@ public function exposedFormAlter(&$form, &$form_state) { '#weight' => 10, ); + $exposed_filters = array(); + // Get an array of exposed filters, keyed by identifier option. foreach ($this->view->filter as $id => $handler) { if ($handler->canExpose() && $handler->isExposed() && !empty($handler->options['expose']['identifier'])) { diff --git a/core/modules/views/lib/Drupal/views/ViewExecutable.php b/core/modules/views/lib/Drupal/views/ViewExecutable.php index ae17eec..0acea1f 100644 --- a/core/modules/views/lib/Drupal/views/ViewExecutable.php +++ b/core/modules/views/lib/Drupal/views/ViewExecutable.php @@ -261,7 +261,7 @@ class ViewExecutable extends DependencySerialization { * * @var array */ - public $field; + public $field = array(); /** * Stores the argument handlers which are initialized on this view. @@ -271,7 +271,7 @@ class ViewExecutable extends DependencySerialization { * * @var array */ - public $argument; + public $argument = array(); /** * Stores the sort handlers which are initialized on this view. @@ -280,7 +280,7 @@ class ViewExecutable extends DependencySerialization { * * @var array */ - public $sort; + public $sort = array(); /** * Stores the filter handlers which are initialized on this view. @@ -290,7 +290,7 @@ class ViewExecutable extends DependencySerialization { * * @var array */ - public $filter; + public $filter = array(); /** * Stores the relationship handlers which are initialized on this view. @@ -300,7 +300,7 @@ class ViewExecutable extends DependencySerialization { * * @var array */ - public $relationship; + public $relationship = array(); /** * Stores the area handlers for the header which are initialized on this view. @@ -309,7 +309,7 @@ class ViewExecutable extends DependencySerialization { * * @var array */ - public $header; + public $header = array(); /** * Stores the area handlers for the footer which are initialized on this view. @@ -318,7 +318,7 @@ class ViewExecutable extends DependencySerialization { * * @var array */ - public $footer; + public $footer = array(); /** * Stores the area handlers for the empty text which are initialized on this view. @@ -327,7 +327,7 @@ class ViewExecutable extends DependencySerialization { * * @var array */ - public $empty; + public $empty = array(); /** * Stores the current response object. diff --git a/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc index ae967bd..2ac1698 100644 --- a/core/modules/views/views.theme.inc +++ b/core/modules/views/views.theme.inc @@ -122,7 +122,7 @@ function template_preprocess_views_view(&$variables) { $container = \Drupal::getContainer(); $form_object = new ViewsForm($container->get('controller_resolver'), $container->get('url_generator'), $container->get('request'), $view->storage->id(), $view->current_display); - $form = \Drupal::formBuilder()->getForm($form_object, $view, $output); + $form = \Drupal::formBuilder()->getForm($form_object, $view->storage->id(), $view->current_display, $output); // The form is requesting that all non-essential views elements be hidden, // usually because the rendered step is not a view result. if ($form['show_view_elements']['#value'] == FALSE) {