Chris@0: [ Chris@0: [$class, 'preRenderViewElement'], Chris@0: ], Chris@0: '#name' => NULL, Chris@0: '#display_id' => 'default', Chris@0: '#arguments' => [], Chris@0: '#embed' => TRUE, Chris@0: '#cache' => [], Chris@0: ]; Chris@0: } Chris@0: Chris@0: /** Chris@0: * View element pre render callback. Chris@0: */ Chris@0: public static function preRenderViewElement($element) { Chris@0: // Allow specific Views displays to explicitly perform pre-rendering, for Chris@0: // those displays that need to be able to know the fully built render array. Chris@0: if (!empty($element['#pre_rendered'])) { Chris@0: return $element; Chris@0: } Chris@0: Chris@0: if (!isset($element['#view'])) { Chris@0: $view = Views::getView($element['#name']); Chris@0: } Chris@0: else { Chris@0: $view = $element['#view']; Chris@0: } Chris@0: Chris@0: $element += $view->element; Chris@0: $view->element = &$element; Chris@0: // Mark the element as being prerendered, so other code like Chris@0: // \Drupal\views\ViewExecutable::setCurrentPage knows that its no longer Chris@0: // possible to manipulate the $element. Chris@0: $view->element['#pre_rendered'] = TRUE; Chris@0: Chris@0: if (isset($element['#response'])) { Chris@0: $view->setResponse($element['#response']); Chris@0: } Chris@0: Chris@0: if ($view && $view->access($element['#display_id'])) { Chris@0: if (!empty($element['#embed'])) { Chris@0: $element['view_build'] = $view->preview($element['#display_id'], $element['#arguments']); Chris@0: } Chris@0: else { Chris@0: // Add contextual links to the view. We need to attach them to the dummy Chris@0: // $view_array variable, since contextual_preprocess() requires that they Chris@0: // be attached to an array (not an object) in order to process them. For Chris@0: // our purposes, it doesn't matter what we attach them to, since once they Chris@0: // are processed by contextual_preprocess() they will appear in the Chris@0: // $title_suffix variable (which we will then render in Chris@0: // views-view.html.twig). Chris@0: $view->setDisplay($element['#display_id']); Chris@0: // Add the result of the executed view as a child element so any Chris@0: // #pre_render elements for the view will get processed. A #pre_render Chris@0: // element cannot be added to the main element as this is already inside Chris@0: // a #pre_render callback. Chris@0: $element['view_build'] = $view->executeDisplay($element['#display_id'], $element['#arguments']); Chris@0: Chris@0: if (isset($element['view_build']['#title'])) { Chris@0: $element['#title'] = &$element['view_build']['#title']; Chris@0: } Chris@0: Chris@0: if (empty($view->display_handler->getPluginDefinition()['returns_response'])) { Chris@0: // views_add_contextual_links() needs the following information in Chris@0: // order to be attached to the view. Chris@0: $element['#view_id'] = $view->storage->id(); Chris@0: $element['#view_display_show_admin_links'] = $view->getShowAdminLinks(); Chris@0: $element['#view_display_plugin_id'] = $view->display_handler->getPluginId(); Chris@0: views_add_contextual_links($element, 'view', $view->current_display); Chris@0: } Chris@0: } Chris@0: if (empty($view->display_handler->getPluginDefinition()['returns_response'])) { Chris@0: $element['#attributes']['class'][] = 'views-element-container'; Chris@0: $element['#theme_wrappers'] = ['container']; Chris@0: } Chris@0: } Chris@0: Chris@0: return $element; Chris@0: } Chris@0: Chris@0: }