function ViewExecutable::setHandler

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

Sets the configuration of a handler instance on a given display.

Parameters

string $display_id: The machine name of the display.

string $type: The type of handler being set.

string $id: The ID of the handler being set.

array|null $item: An array of configuration for a handler, or NULL to remove this instance.

See also

set_item_option()

1 call to ViewExecutable::setHandler()
ViewExecutable::setHandlerOption in core/modules/views/src/ViewExecutable.php
Sets an option on a handler instance.

File

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

Class

ViewExecutable
Represents a view as a whole.

Namespace

Drupal\views

Code

public function setHandler($display_id, $type, $id, $item) {
    // Get info about the types so we can get the right data.
    $types = static::getHandlerTypes();
    // Initialize the display.
    $this->setDisplay($display_id);
    // Get the existing configuration.
    $fields = $this->displayHandlers
        ->get($display_id)
        ->getOption($types[$type]['plural']);
    if (isset($item)) {
        $fields[$id] = $item;
    }
    // Store.
    $this->displayHandlers
        ->get($display_id)
        ->setOption($types[$type]['plural'], $fields);
}

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