function EntityField::query

Same name in other branches
  1. 8.9.x core/modules/views/src/Plugin/views/field/EntityField.php \Drupal\views\Plugin\views\field\EntityField::query()
  2. 10 core/modules/views/src/Plugin/views/field/EntityField.php \Drupal\views\Plugin\views\field\EntityField::query()
  3. 11.x core/modules/views/src/Plugin/views/field/EntityField.php \Drupal\views\Plugin\views\field\EntityField::query()

Called to add the field to a query.

By default, all needed data is taken from entities loaded by the query plugin. Columns are added only if they are used in groupings.

Overrides FieldPluginBase::query

File

core/modules/views/src/Plugin/views/field/EntityField.php, line 237

Class

EntityField
A field that displays entity field data.

Namespace

Drupal\views\Plugin\views\field

Code

public function query($use_groupby = FALSE) {
    $fields = $this->additional_fields;
    // No need to add the entity type.
    $entity_type_key = array_search('entity_type', $fields);
    if ($entity_type_key !== FALSE) {
        unset($fields[$entity_type_key]);
    }
    if ($use_groupby) {
        // Add the fields that we're actually grouping on.
        $options = [];
        if ($this->options['group_column'] != 'entity_id') {
            $options = [
                $this->options['group_column'] => $this->options['group_column'],
            ];
        }
        $options += is_array($this->options['group_columns']) ? $this->options['group_columns'] : [];
        // Go through the list and determine the actual column name from field api.
        $fields = [];
        $table_mapping = $this->getTableMapping();
        $field_definition = $this->getFieldStorageDefinition();
        foreach ($options as $column) {
            $fields[$column] = $table_mapping->getFieldColumnName($field_definition, $column);
        }
        $this->group_fields = $fields;
    }
    // Add additional fields (and the table join itself) if needed.
    if ($this->add_field_table($use_groupby)) {
        $this->ensureMyTable();
        $this->addAdditionalFields($fields);
    }
    // Let the entity field renderer alter the query if needed.
    $this->getEntityFieldRenderer()
        ->query($this->query, $this->relationship);
}

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