class View

Same name in this branch
  1. 11.x core/modules/views/src/Entity/View.php \Drupal\views\Entity\View
  2. 11.x core/modules/views/src/Plugin/views/area/View.php \Drupal\views\Plugin\views\area\View
Same name and namespace in other branches
  1. 9 core/modules/views/src/Element/View.php \Drupal\views\Element\View
  2. 9 core/modules/views/src/Entity/View.php \Drupal\views\Entity\View
  3. 9 core/modules/views/src/Plugin/views/area/View.php \Drupal\views\Plugin\views\area\View
  4. 8.9.x core/modules/views/src/Element/View.php \Drupal\views\Element\View
  5. 8.9.x core/modules/views/src/Entity/View.php \Drupal\views\Entity\View
  6. 8.9.x core/modules/views/src/Plugin/views/area/View.php \Drupal\views\Plugin\views\area\View
  7. 10 core/modules/views/src/Element/View.php \Drupal\views\Element\View
  8. 10 core/modules/views/src/Entity/View.php \Drupal\views\Entity\View
  9. 10 core/modules/views/src/Plugin/views/area/View.php \Drupal\views\Plugin\views\area\View

Provides a render element to display a view.

Attributes

#[RenderElement('view')]
#[ConfigEntityType(id: 'view', label: new TranslatableMarkup('View', ['context' => 'View entity type']), label_collection: new TranslatableMarkup('Views', ['context' => 'View entity type']), label_singular: new TranslatableMarkup('view', ['context' => 'View entity type']), label_plural: new TranslatableMarkup('views', ['context' => 'View entity type']), entity_keys: ['id' => 'id', 'label' => 'label', 'status' => 'status'], admin_permission: 'administer views', label_count: ['singular' => '@count view', 'plural' => '@count views'], config_export: ['id', 'label', 'module', 'description', 'tag', 'base_table', 'base_field', 'display'])]
#[ViewsArea("view")]

Hierarchy

Expanded class hierarchy of View

1 file declares its use of View
ViewsBlock.php in core/modules/views/src/Plugin/Block/ViewsBlock.php
307 string references to 'View'
Access::query in core/modules/node/src/Plugin/views/filter/Access.php
See _node_access_where_sql() for a non-views query based implementation.
AccountTakeoverGadgetChainTest::setUp in core/tests/Drupal/KernelTests/Core/User/AccountTakeoverGadgetChainTest.php
AddFormBase::processInputValues in core/modules/media_library/src/Form/AddFormBase.php
Creates media items from source field input values.
AddHandler::buildForm in core/modules/views_ui/src/Form/Ajax/AddHandler.php
Form constructor.
Analyze::buildForm in core/modules/views_ui/src/Form/Ajax/Analyze.php
Form constructor.

... See full list

File

core/modules/views/src/Element/View.php, line 13

Namespace

Drupal\views\Element
View source
class View extends RenderElementBase {
  
  /**
   * {@inheritdoc}
   */
  public function getInfo() {
    return [
      '#pre_render' => [
        [
          static::class,
          'preRenderViewElement',
        ],
      ],
      '#name' => NULL,
      '#display_id' => 'default',
      '#arguments' => [],
      '#embed' => TRUE,
      '#cache' => [],
    ];
  }
  
  /**
   * View element pre render callback.
   */
  public static function preRenderViewElement($element) {
    // Allow specific Views displays to explicitly perform pre-rendering, for
    // those displays that need to be able to know the fully built render array.
    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;
    // Mark the element as being prerendered, so other code like
    // \Drupal\views\ViewExecutable::setCurrentPage knows that its no longer
    // possible to manipulate the $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 {
        // Add contextual links to the view. We need to attach them to the dummy
        // $view_array variable, since contextual_preprocess() requires that
        // they be attached to an array (not an object) in order to process
        // them. For our purposes, it doesn't matter what we attach them to,
        // since once they are processed by contextual_preprocess() they will
        // appear in the $title_suffix variable (which we will then render in
        // views-view.html.twig).
        $view->setDisplay($element['#display_id']);
        // Add the result of the executed view as a child element so any
        // #pre_render elements for the view will get processed. A #pre_render
        // element cannot be added to the main element as this is already inside
        // a #pre_render callback.
        $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'])) {
          // views_add_contextual_links() needs the following information in
          // order to be attached to the view.
          $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;
  }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
PluginInspectionInterface::getPluginDefinition public function Gets the definition of the plugin implementation. 7
PluginInspectionInterface::getPluginId public function Gets the plugin ID of the plugin instance. 3
RenderElementBase::preRenderAjaxForm public static function Adds Ajax information about an element to communicate with JavaScript. 2
RenderElementBase::preRenderGroup public static function Adds members of this group as actual elements for rendering. 2
RenderElementBase::processAjaxForm public static function Form element processing handler for the #ajax form property. 3
RenderElementBase::processGroup public static function Arranges elements into groups. 2
RenderElementBase::setAttributes public static function Sets a form element's class attribute. Overrides ElementInterface::setAttributes 2
View::getInfo public function Returns the element properties for this element. Overrides ElementInterface::getInfo
View::preRenderViewElement public static function View element pre render callback.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.