View.php in Drupal 9
File
core/modules/views/src/Element/View.php
View source
<?php
namespace Drupal\views\Element;
use Drupal\Core\Render\Element\RenderElement;
use Drupal\views\Exception\ViewRenderElementException;
use Drupal\views\Views;
class View extends RenderElement {
public function getInfo() {
$class = static::class;
return [
'#pre_render' => [
[
$class,
'preRenderViewElement',
],
],
'#name' => NULL,
'#display_id' => 'default',
'#arguments' => [],
'#embed' => TRUE,
'#cache' => [],
];
}
public static function preRenderViewElement($element) {
if (!empty($element['#pre_rendered'])) {
return $element;
}
if (!isset($element['#view'])) {
$view = Views::getView($element['#name']);
if (!$view) {
throw new ViewRenderElementException("Invalid View name ({$element['#name']}) given.");
}
}
else {
$view = $element['#view'];
}
$element += $view->element;
$view->element =& $element;
$view->element['#pre_rendered'] = TRUE;
if (isset($element['#response'])) {
$view
->setResponse($element['#response']);
}
if ($view && $view
->access($element['#display_id'])) {
if (!empty($element['#embed'])) {
$element['view_build'] = $view
->preview($element['#display_id'], $element['#arguments']);
}
else {
$view
->setDisplay($element['#display_id']);
$element['view_build'] = $view
->executeDisplay($element['#display_id'], $element['#arguments']);
if (isset($element['view_build']['#title'])) {
$element['#title'] =& $element['view_build']['#title'];
}
if (empty($view->display_handler
->getPluginDefinition()['returns_response'])) {
$element['#view_id'] = $view->storage
->id();
$element['#view_display_show_admin_links'] = $view
->getShowAdminLinks();
$element['#view_display_plugin_id'] = $view->display_handler
->getPluginId();
views_add_contextual_links($element, 'view', $view->current_display);
}
}
if (empty($view->display_handler
->getPluginDefinition()['returns_response'])) {
$element['#attributes']['class'][] = 'views-element-container';
$element['#theme_wrappers'] = [
'container',
];
}
}
return $element;
}
}
Classes
Name |
Description |
View |
Provides a render element to display a view. |