public function ViewExecutable::addItem

Adds an instance of a handler to the view.

Items may be fields, filters, sort criteria, or arguments.

Parameters

string $display_id: The machine name of the display.

string $type: The type of handler being added.

string $table: The name of the table this handler is from.

string $field: The name of the field this handler is from.

array $options: (optional) Extra options for this instance. Defaults to an empty array.

string $id: (optional) A unique ID for this handler instance. Defaults to NULL, in which case one will be generated.

Return value

string The unique ID for this handler instance.

File

drupal/core/modules/views/lib/Drupal/views/ViewExecutable.php, line 2064
Definition of Drupal\views\ViewExecutable.

Class

ViewExecutable
An object to contain all of the data to generate a view, plus the member functions to build the view query, execute the query and render the output.

Namespace

Drupal\views

Code

public function addItem($display_id, $type, $table, $field, $options = array(), $id = NULL) {
  $types = $this::viewsHandlerTypes();
  $this
    ->setDisplay($display_id);
  $fields = $this->displayHandlers[$display_id]
    ->getOption($types[$type]['plural']);
  if (empty($id)) {
    $id = $this
      ->generateItemId($field, $fields);
  }

  // If the desired type is not found, use the original value directly.
  $handler_type = !empty($types[$type]['type']) ? $types[$type]['type'] : $type;

  // @todo This variable is never used.
  $handler = views_get_handler($table, $field, $handler_type);
  $fields[$id] = array(
    'id' => $id,
    'table' => $table,
    'field' => $field,
  ) + $options;
  $this->displayHandlers[$display_id]
    ->setOption($types[$type]['plural'], $fields);
  return $id;
}