You are here

protected function FieldPluginBase::addAdditionalFields in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views/src/Plugin/views/field/FieldPluginBase.php \Drupal\views\Plugin\views\field\FieldPluginBase::addAdditionalFields()

Add 'additional' fields to the query.

Parameters

$fields: An array of fields. The key is an identifier used to later find the field alias used. The value is either a string in which case it's assumed to be a field on this handler's table; or it's an array in the form of

array(
  'table' => $tablename,
  'field' => $fieldname,
);
7 calls to FieldPluginBase::addAdditionalFields()
EntityField::query in core/modules/views/src/Plugin/views/field/EntityField.php
Called to add the field to a query.
FieldPluginBase::query in core/modules/views/src/Plugin/views/field/FieldPluginBase.php
Called to add the field to a query.
LinkBase::query in core/modules/views/src/Plugin/views/field/LinkBase.php
Called to add the field to a query.
NodeNewComments::query in core/modules/comment/src/Plugin/views/field/NodeNewComments.php
Called to add the field to a query.
Permissions::query in core/modules/user/src/Plugin/views/field/Permissions.php
Called to add the field to a query.

... See full list

File

core/modules/views/src/Plugin/views/field/FieldPluginBase.php, line 162

Class

FieldPluginBase
Base class for views fields.

Namespace

Drupal\views\Plugin\views\field

Code

protected function addAdditionalFields($fields = NULL) {
  if (!isset($fields)) {

    // notice check
    if (empty($this->additional_fields)) {
      return;
    }
    $fields = $this->additional_fields;
  }
  $group_params = [];
  if ($this->options['group_type'] != 'group') {
    $group_params = [
      'function' => $this->options['group_type'],
    ];
  }
  if (!empty($fields) && is_array($fields)) {
    foreach ($fields as $identifier => $info) {
      if (is_array($info)) {
        if (isset($info['table'])) {
          $table_alias = $this->query
            ->ensureTable($info['table'], $this->relationship);
        }
        else {
          $table_alias = $this->tableAlias;
        }
        if (empty($table_alias)) {
          trigger_error(sprintf("Handler %s tried to add additional_field %s but %s could not be added!", $this->definition['id'], $identifier, $info['table']), E_USER_WARNING);
          $this->aliases[$identifier] = 'broken';
          continue;
        }
        $params = [];
        if (!empty($info['params'])) {
          $params = $info['params'];
        }
        $params += $group_params;
        $this->aliases[$identifier] = $this->query
          ->addField($table_alias, $info['field'], NULL, $params);
      }
      else {
        $this->aliases[$info] = $this->query
          ->addField($this->tableAlias, $info, NULL, $group_params);
      }
    }
  }
}