3 namespace Drupal\views\Element;
5 use Drupal\Core\Render\Element\RenderElement;
6 use Drupal\views\Views;
9 * Provides a render element to display a view.
11 * @RenderElement("view")
13 class View extends RenderElement {
18 public function getInfo() {
19 $class = get_class($this);
22 [$class, 'preRenderViewElement'],
25 '#display_id' => 'default',
33 * View element pre render callback.
35 public static function preRenderViewElement($element) {
36 // Allow specific Views displays to explicitly perform pre-rendering, for
37 // those displays that need to be able to know the fully built render array.
38 if (!empty($element['#pre_rendered'])) {
42 if (!isset($element['#view'])) {
43 $view = Views::getView($element['#name']);
46 $view = $element['#view'];
49 $element += $view->element;
50 $view->element = &$element;
51 // Mark the element as being prerendered, so other code like
52 // \Drupal\views\ViewExecutable::setCurrentPage knows that its no longer
53 // possible to manipulate the $element.
54 $view->element['#pre_rendered'] = TRUE;
57 if (isset($element['#response'])) {
58 $view->setResponse($element['#response']);
61 if ($view && $view->access($element['#display_id'])) {
62 if (!empty($element['#embed'])) {
63 $element['view_build'] = $view->preview($element['#display_id'], $element['#arguments']);
66 // Add contextual links to the view. We need to attach them to the dummy
67 // $view_array variable, since contextual_preprocess() requires that they
68 // be attached to an array (not an object) in order to process them. For
69 // our purposes, it doesn't matter what we attach them to, since once they
70 // are processed by contextual_preprocess() they will appear in the
71 // $title_suffix variable (which we will then render in
72 // views-view.html.twig).
73 $view->setDisplay($element['#display_id']);
74 // Add the result of the executed view as a child element so any
75 // #pre_render elements for the view will get processed. A #pre_render
76 // element cannot be added to the main element as this is already inside
77 // a #pre_render callback.
78 $element['view_build'] = $view->executeDisplay($element['#display_id'], $element['#arguments']);
80 if (isset($element['view_build']['#title'])) {
81 $element['#title'] = &$element['view_build']['#title'];
84 if (empty($view->display_handler->getPluginDefinition()['returns_response'])) {
85 // views_add_contextual_links() needs the following information in
86 // order to be attached to the view.
87 $element['#view_id'] = $view->storage->id();
88 $element['#view_display_show_admin_links'] = $view->getShowAdminLinks();
89 $element['#view_display_plugin_id'] = $view->display_handler->getPluginId();
90 views_add_contextual_links($element, 'view', $view->current_display);
93 if (empty($view->display_handler->getPluginDefinition()['returns_response'])) {
94 $element['#attributes']['class'][] = 'views-element-container';
95 $element['#theme_wrappers'] = ['container'];