diff --git a/core/modules/views/src/Form/ViewsExposedForm.php b/core/modules/views/src/Form/ViewsExposedForm.php index a425748..f29f36d 100644 --- a/core/modules/views/src/Form/ViewsExposedForm.php +++ b/core/modules/views/src/Form/ViewsExposedForm.php @@ -10,6 +10,7 @@ use Drupal\Component\Utility\String; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; +use Drupal\views\Views; use Drupal\views\ExposedFormCache; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -65,8 +66,8 @@ public function buildForm(array $form, FormStateInterface $form_state) { // multiple times per page. $form_state->setValidationEnforced(); /** @var \Drupal\views\ViewExecutable $view */ - $view = $form_state->get('view'); - $display = &$form_state->get('display'); + $view = views_get_current_view(); + $display = &$view->display_handler->display; $form_state->setUserInput($view->getExposedInput()); @@ -120,7 +121,7 @@ public function buildForm(array $form, FormStateInterface $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->get('exposed_form_plugin'); + $exposed_form_plugin = $view->display_handler->getPlugin('exposed_form'); $exposed_form_plugin->exposedFormAlter($form, $form_state); // Save the form. @@ -133,15 +134,17 @@ public function buildForm(array $form, FormStateInterface $form_state) { * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { + $view = views_get_current_view(); + foreach (array('field', 'filter') as $type) { /** @var \Drupal\views\Plugin\views\ViewsHandlerInterface[] $handlers */ - $handlers = &$form_state->get('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->get('exposed_form_plugin'); + $exposed_form_plugin = $view->display_handler->getPlugin('exposed_form'); $exposed_form_plugin->exposedFormValidate($form, $form_state); } @@ -149,22 +152,21 @@ public function validateForm(array &$form, FormStateInterface $form_state) { * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { + $view = views_get_current_view(); foreach (array('field', 'filter') as $type) { /** @var \Drupal\views\Plugin\views\ViewsHandlerInterface[] $handlers */ - $handlers = &$form_state->get('view')->$type; + $handlers = &$view->$type; foreach ($handlers as $key => $info) { $handlers[$key]->submitExposed($form, $form_state); } } - $view = $form_state->get('view'); $view->exposed_data = $form_state->getValues(); $view->exposed_raw_input = []; $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->get('exposed_form_plugin'); + $exposed_form_plugin = $view->display_handler->getPlugin('exposed_form'); $exposed_form_plugin->exposedFormSubmit($form, $form_state, $exclude); - foreach ($form_state->getValues() as $key => $value) { if (!in_array($key, $exclude)) { $view->exposed_raw_input[$key] = $value; diff --git a/core/modules/views/src/Form/ViewsForm.php b/core/modules/views/src/Form/ViewsForm.php index c1296b2..4b900b8 100644 --- a/core/modules/views/src/Form/ViewsForm.php +++ b/core/modules/views/src/Form/ViewsForm.php @@ -14,6 +14,7 @@ use Drupal\Core\Form\FormInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Routing\UrlGeneratorInterface; +use Drupal\views\Views; use Drupal\views\ViewExecutable; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RequestStack; @@ -78,24 +79,24 @@ class ViewsForm implements FormInterface, ContainerInjectionInterface { * @param string $view_display_id * The ID of the active view's display. */ - public function __construct(ClassResolverInterface $class_resolver, UrlGeneratorInterface $url_generator, RequestStack $requestStack, $view_id, $view_display_id) { + public function __construct(ClassResolverInterface $class_resolver, UrlGeneratorInterface $url_generator, RequestStack $requestStack, $view, $output) { $this->classResolver = $class_resolver; $this->urlGenerator = $url_generator; $this->requestStack = $requestStack; - $this->viewId = $view_id; - $this->viewDisplayId = $view_display_id; + $this->view = $view; + $this->output = $output; } /** * {@inheritdoc} */ - public static function create(ContainerInterface $container, $view_id = NULL, $view_display_id = NULL) { + public static function create(ContainerInterface $container, $view = NULL, $output = []) { return new static( $container->get('class_resolver'), $container->get('url_generator'), $container->get('request_stack'), - $view_id, - $view_display_id + $view, + $output ); } @@ -105,8 +106,8 @@ public static function create(ContainerInterface $container, $view_id = NULL, $v public function getFormID() { $parts = array( 'views_form', - $this->viewId, - $this->viewDisplayId, + $this->view->storage->id(), + $this->view->current_display, ); return implode('_', $parts); @@ -115,7 +116,7 @@ public function getFormID() { /** * {@inheritdoc} */ - public function buildForm(array $form, FormStateInterface $form_state, ViewExecutable $view = NULL, $output = []) { + public function buildForm(array $form, FormStateInterface $form_state) { if (!$step = $form_state->get('step')) { $step = 'views_form_views_form'; $form_state->set('step', $step); @@ -133,7 +134,7 @@ public function buildForm(array $form, FormStateInterface $form_state, ViewExecu $query = $this->requestStack->getCurrentRequest()->query->all(); $query = UrlHelper::filterQueryParameters($query, array(), ''); - $form['#action'] = $this->urlGenerator->generateFromPath($view->getUrl(), array('query' => $query)); + $form['#action'] = $this->urlGenerator->generateFromPath($this->view->getUrl(), array('query' => $query)); // Tell the preprocessor whether it should hide the header, footer, pager... $form['show_view_elements'] = array( '#type' => 'value', @@ -141,7 +142,7 @@ public function buildForm(array $form, FormStateInterface $form_state, ViewExecu ); $form_object = $this->getFormObject($form_state); - $form += $form_object->buildForm($form, $form_state, $view, $output); + $form += $form_object->buildForm($form, $form_state, $this->view, $this->output); return $form; } @@ -177,4 +178,13 @@ protected function getFormObject(FormStateInterface $form_state) { return $this->classResolver->getInstanceFromDefinition($form_step_class); } + public function __sleep() { + return []; + } + + public function __wakeup() { + // This is a huge hack, but let see if this resolves our issue. + $this->classResolver = \Drupal::getContainer()->get('class_resolver'); + } + } diff --git a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php index f370bea..5f5ca82 100644 --- a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php +++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php @@ -2144,7 +2144,6 @@ public function getMenuLinks() { */ public function render() { $rows = (!empty($this->view->result) || $this->view->style_plugin->evenEmpty()) ? $this->view->style_plugin->render($this->view->result) : array(); - $element = array( '#theme' => $this->themeFunctions(), '#view' => $this->view, @@ -2208,8 +2207,8 @@ public function elementPreRender(array $element) { $output = $element['#empty']; } - $form_object = ViewsForm::create(\Drupal::getContainer(), $view->storage->id(), $view->current_display); - $form = \Drupal::formBuilder()->getForm($form_object, $view, $output); + $form_object = ViewsForm::create(\Drupal::getContainer(), $view, $output); + $form = \Drupal::formBuilder()->getForm($form_object); // 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) { diff --git a/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php b/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php index e7aa591..7c1b029 100644 --- a/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php +++ b/core/modules/views/src/Plugin/views/exposed_form/ExposedFormPluginBase.php @@ -131,8 +131,8 @@ public function renderExposedForm($block = FALSE) { // Deal with any exposed filters we may have, before building. $form_state = (new FormState()) ->setStorage([ - 'view' => $this->view, - 'display' => &$this->view->display_handler->display, + 'view_id' => $this->view->storage->id(), + 'display_id' => $this->view->current_display, 'rerender' => TRUE, ]) ->setMethod('get') @@ -150,7 +150,6 @@ public function renderExposedForm($block = FALSE) { $form_state->set('ajax', TRUE); } - $form_state->set('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'))) { @@ -258,6 +257,8 @@ public function exposedFormAlter(&$form, FormStateInterface $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/src/Routing/ViewPageController.php b/core/modules/views/src/Routing/ViewPageController.php index 0bfa9a1..67aab4e 100644 --- a/core/modules/views/src/Routing/ViewPageController.php +++ b/core/modules/views/src/Routing/ViewPageController.php @@ -103,7 +103,6 @@ public function handle($view_id, $display_id, Request $request, RouteMatchInterf $args[] = $arg; } } - return $view->executeDisplay($display_id, $args); } diff --git a/core/modules/views/src/ViewExecutable.php b/core/modules/views/src/ViewExecutable.php index 94fbcc0..ba66b08 100644 --- a/core/modules/views/src/ViewExecutable.php +++ b/core/modules/views/src/ViewExecutable.php @@ -258,7 +258,7 @@ class ViewExecutable { * * @var array */ - public $field; + public $field = array(); /** * Stores the argument handlers which are initialized on this view. @@ -268,7 +268,7 @@ class ViewExecutable { * * @var array */ - public $argument; + public $argument = array(); /** * Stores the sort handlers which are initialized on this view. @@ -277,7 +277,7 @@ class ViewExecutable { * * @var array */ - public $sort; + public $sort = array(); /** * Stores the filter handlers which are initialized on this view. @@ -287,7 +287,7 @@ class ViewExecutable { * * @var array */ - public $filter; + public $filter = array(); /** * Stores the relationship handlers which are initialized on this view. @@ -297,7 +297,7 @@ class ViewExecutable { * * @var array */ - public $relationship; + public $relationship = array(); /** * Stores the area handlers for the header which are initialized on this view. @@ -306,7 +306,7 @@ class ViewExecutable { * * @var array */ - public $header; + public $header = array(); /** * Stores the area handlers for the footer which are initialized on this view. @@ -315,7 +315,7 @@ class ViewExecutable { * * @var array */ - public $footer; + public $footer = array(); /** * Stores the area handlers for the empty text which are initialized on this view. @@ -324,7 +324,7 @@ class ViewExecutable { * * @var array */ - public $empty; + public $empty = array(); /** * Stores the current response object.