ViewExecutable::addHandler

public ViewExecutable::addHandler($display_id, $type, $table, $field, $options = array(), $id = NULL)

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

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

Class

ViewExecutable
Represents a view as a whole.

Namespace

Drupal\views

Code

public function addHandler($display_id, $type, $table, $field, $options = array(), $id = NULL) {
  $types = $this::getHandlerTypes();
  $this->setDisplay($display_id);

  $data = $this->viewsData->get($table);
  $fields = $this->displayHandlers->get($display_id)->getOption($types[$type]['plural']);

  if (empty($id)) {
    $id = $this->generateHandlerId($field, $fields);
  }

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

  $fields[$id] = array(
    'id' => $id,
    'table' => $table,
    'field' => $field,
  ) + $options;

  if (isset($data['table']['entity type'])) {
    $fields[$id]['entity_type'] = $data['table']['entity type'];
  }
  if (isset($data[$field]['entity field'])) {
    $fields[$id]['entity_field'] = $data[$field]['entity field'];
  }

  // Load the plugin ID if available.
  if (isset($data[$field][$handler_type]['id'])) {
    $fields[$id]['plugin_id'] = $data[$field][$handler_type]['id'];
  }

  $this->displayHandlers->get($display_id)->setOption($types[$type]['plural'], $fields);

  return $id;
}
doc_Drupal
2016-10-29 09:54:16
Comments
Leave a Comment

Please login to continue.