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;
56 if (isset($element['#response'])) {
57 $view->setResponse($element['#response']);
60 if ($view && $view->access($element['#display_id'])) {
61 if (!empty($element['#embed'])) {
62 $element['view_build'] = $view->preview($element['#display_id'], $element['#arguments']);
65 // Add contextual links to the view. We need to attach them to the dummy
66 // $view_array variable, since contextual_preprocess() requires that they
67 // be attached to an array (not an object) in order to process them. For
68 // our purposes, it doesn't matter what we attach them to, since once they
69 // are processed by contextual_preprocess() they will appear in the
70 // $title_suffix variable (which we will then render in
71 // views-view.html.twig).
72 $view->setDisplay($element['#display_id']);
73 // Add the result of the executed view as a child element so any
74 // #pre_render elements for the view will get processed. A #pre_render
75 // element cannot be added to the main element as this is already inside
76 // a #pre_render callback.
77 $element['view_build'] = $view->executeDisplay($element['#display_id'], $element['#arguments']);
79 if (isset($element['view_build']['#title'])) {
80 $element['#title'] = &$element['view_build']['#title'];
83 if (empty($view->display_handler->getPluginDefinition()['returns_response'])) {
84 // views_add_contextual_links() needs the following information in
85 // order to be attached to the view.
86 $element['#view_id'] = $view->storage->id();
87 $element['#view_display_show_admin_links'] = $view->getShowAdminLinks();
88 $element['#view_display_plugin_id'] = $view->display_handler->getPluginId();
89 views_add_contextual_links($element, 'view', $view->current_display);
92 if (empty($view->display_handler->getPluginDefinition()['returns_response'])) {
93 $element['#attributes']['class'][] = 'views-element-container';
94 $element['#theme_wrappers'] = ['container'];