diff --git a/core/modules/views/lib/Drupal/views/Form/ViewsForm.php b/core/modules/views/lib/Drupal/views/Form/ViewsForm.php index cc01f8d..5c52880 100644 --- a/core/modules/views/lib/Drupal/views/Form/ViewsForm.php +++ b/core/modules/views/lib/Drupal/views/Form/ViewsForm.php @@ -113,7 +113,7 @@ 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, ViewExecutable $view = NULL, $output = array()) { $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'; diff --git a/core/modules/views/lib/Drupal/views/Form/ViewsFormMainForm.php b/core/modules/views/lib/Drupal/views/Form/ViewsFormMainForm.php index 98cdc4f..60af825 100644 --- a/core/modules/views/lib/Drupal/views/Form/ViewsFormMainForm.php +++ b/core/modules/views/lib/Drupal/views/Form/ViewsFormMainForm.php @@ -21,7 +21,7 @@ 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, ViewExecutable $view = NULL, $output = array()) { $form['#prefix'] = '
'; $form['#suffix'] = '
'; $form['#theme'] = 'form'; @@ -29,12 +29,10 @@ public function buildForm(array $form, array &$form_state, ViewExecutable $view // Add the output markup to the form array so that it's included when the form // array is passed to the theme function. - $form['output'] = array( - '#markup' => $output, - // This way any additional form elements will go before the view - // (below the exposed widgets). - '#weight' => 50, - ); + $form['output'] = $output; + // This way any additional form elements will go before the view + // (below the exposed widgets). + $form['output']['#weight'] = 50; $form['actions'] = array( '#type' => 'actions', 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 2d47e76..6a9be60 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 @@ -11,6 +11,7 @@ use Drupal\Core\Language\Language; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Theme\Registry; +use Drupal\views\Form\ViewsForm; use Drupal\views\Plugin\views\area\AreaPluginBase; use Drupal\views\ViewExecutable; use Drupal\views\Plugin\views\PluginBase; @@ -2130,23 +2131,18 @@ public function executeHookMenuLinkDefaults(array &$existing_links) { * Render this display. */ public function render() { - $view_id = $this->view->storage->id(); $element = array( '#theme' => $this->themeFunctions(), '#view' => $this->view, '#attached' => &$this->view->element['#attached'], - '#cache' => array( - 'keys' => array('views', 'view', $view_id, $this->view->current_display, $this->view->getCurrentPage()), - 'tags' => array('view' => array($view_id => $view_id)), - ), - '#pre_render' => array(array(get_class($this), 'preRender')), + '#pre_render' => array(array(get_class($this), 'elementPreRender')), ); return $element; } /** - * Pre render callback. + * Pre render callback for view display rendering. * * @see self::render() * @@ -2154,7 +2150,7 @@ public function render() { * * @return array */ - public static function preRender($element) { + public static function elementPreRender($element) { $view = $element['#view']; $empty = empty($view->result); @@ -2184,6 +2180,34 @@ public static function preRender($element) { $element['#attachment_after'] = $view->attachment_after; } + // If form fields were found in the view, reformat the view output as a form. + if ($view->hasFormElements()) { + // Only render row output if there are rows. Otherwise, render the empty + // region. + if (!empty($element['#rows'])) { + $output = $element['#rows']; + } + else { + $output = $element['#empty']; + } + + $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); + // 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) { + $element['#header'] = array(); + $element['#exposed'] = array(); + $element['#pager'] = array(); + $element['#footer'] = array(); + $element['#more'] = array(); + $element['#feed_icon'] = array(); + } + + $element['#rows'] = $form; + } + return $element; } diff --git a/core/modules/views/views.module b/core/modules/views/views.module index fe97638..5975432 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -917,11 +917,12 @@ function views_pre_render_views_form_views_form($element) { } // Apply substitutions to the rendered output. - $element['output']['#markup'] = str_replace($search, $replace, $element['output']['#markup']); + $element['output'] = array('#markup' => str_replace($search, $replace, drupal_render($element['output']))); // Sort, render and add remaining form fields. $children = element_children($element, TRUE); $element['#children'] = drupal_render_children($element, $children); + return $element; } diff --git a/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc index ce24634..7ec86e7 100644 --- a/core/modules/views/views.theme.inc +++ b/core/modules/views/views.theme.inc @@ -9,7 +9,6 @@ use Drupal\Component\Utility\Xss; use Drupal\Core\Language\Language; use Drupal\Core\Template\Attribute; -use Drupal\views\Form\ViewsForm; use Drupal\views\ViewExecutable; /** @@ -30,8 +29,6 @@ function template_preprocess_views_view(&$variables) { $variables['display_id'] = $view->current_display; // Basic classes. - $variables['css_class'] = ''; - $variables['attributes']['class'] = array(); $variables['attributes']['class'][] = 'view'; $variables['attributes']['class'][] = 'view-' . drupal_clean_css_identifier($variables['id']); @@ -67,36 +64,6 @@ function template_preprocess_views_view(&$variables) { $variables['dom_id'] = $view->dom_id; $variables['attributes']['class'][] = 'view-dom-id-' . $variables['dom_id']; } - - // If form fields were found in the view, reformat the view output as a form. - if ($view->hasFormElements()) { - // Copy the rows so as not to modify them by reference when rendering. - $rows = $variables['rows']; - // Only render row output if there are rows. Otherwise, render the empty - // region. - if (!empty($rows)) { - $output = drupal_render($rows); - } - else { - $empty = $variables['empty']; - $output = drupal_render($empty); - } - - $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); - // 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) { - $variables['header'] = ''; - $variables['exposed'] = ''; - $variables['pager'] = ''; - $variables['footer'] = ''; - $variables['more'] = ''; - $variables['feed_icon'] = ''; - } - $variables['rows'] = $form; - } } /**