function ViewExecutable::setDisplay

Same name in other branches
  1. 9 core/modules/views/src/ViewExecutable.php \Drupal\views\ViewExecutable::setDisplay()
  2. 8.9.x core/modules/views/src/ViewExecutable.php \Drupal\views\ViewExecutable::setDisplay()
  3. 11.x core/modules/views/src/ViewExecutable.php \Drupal\views\ViewExecutable::setDisplay()

Sets the current display.

Parameters

string $display_id: The ID of the display to mark as current.

Return value

bool TRUE if the display was correctly set, FALSE otherwise.

13 calls to ViewExecutable::setDisplay()
ViewExecutable::addHandler in core/modules/views/src/ViewExecutable.php
Adds an instance of a handler to the view.
ViewExecutable::build in core/modules/views/src/ViewExecutable.php
Builds the query for the view.
ViewExecutable::buildRenderable in core/modules/views/src/ViewExecutable.php
Builds the render array outline for the given display.
ViewExecutable::executeDisplay in core/modules/views/src/ViewExecutable.php
Executes the given display, with the given arguments.
ViewExecutable::getHandler in core/modules/views/src/ViewExecutable.php
Gets the configuration of a handler instance on a given display.

... See full list

File

core/modules/views/src/ViewExecutable.php, line 838

Class

ViewExecutable
Represents a view as a whole.

Namespace

Drupal\views

Code

public function setDisplay($display_id = NULL) {
    // If we have not already initialized the display, do so.
    if (!isset($this->current_display)) {
        // This will set the default display and instantiate the default display
        // plugin.
        $this->initDisplay();
    }
    // If no display ID is passed, we either have initialized the default or
    // already have a display set.
    if (!isset($display_id)) {
        return TRUE;
    }
    $display_id = $this->chooseDisplay($display_id);
    // Ensure the requested display exists.
    if (!$this->displayHandlers
        ->has($display_id)) {
        $this->getLogger('views')
            ->warning('setDisplay() called with invalid display ID "@display_id".', [
            '@display_id' => $display_id,
        ]);
        return FALSE;
    }
    // Reset if the display has changed. It could be called multiple times for
    // the same display, especially in the UI.
    if ($this->current_display != $display_id) {
        // Set the current display.
        $this->current_display = $display_id;
        // Reset the style and row plugins.
        $this->style_plugin = NULL;
        $this->plugin_name = NULL;
        $this->rowPlugin = NULL;
    }
    if ($display = $this->displayHandlers
        ->get($display_id)) {
        // Set a shortcut.
        $this->display_handler = $display;
        return TRUE;
    }
    return FALSE;
}

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