function EntityViewsData::processViewsDataForEntityReference

Same name in other branches
  1. 9 core/modules/views/src/EntityViewsData.php \Drupal\views\EntityViewsData::processViewsDataForEntityReference()
  2. 8.9.x core/modules/views/src/EntityViewsData.php \Drupal\views\EntityViewsData::processViewsDataForEntityReference()
  3. 11.x core/modules/views/src/EntityViewsData.php \Drupal\views\EntityViewsData::processViewsDataForEntityReference()

Processes the views data for an entity reference field.

Parameters

string $table: The table the language field is added to.

\Drupal\Core\Field\FieldDefinitionInterface $field_definition: The field definition.

array $views_field: The views field data.

string $field_column_name: The field column being processed.

File

core/modules/views/src/EntityViewsData.php, line 628

Class

EntityViewsData
Provides generic views integration for entities.

Namespace

Drupal\views

Code

protected function processViewsDataForEntityReference($table, FieldDefinitionInterface $field_definition, array &$views_field, $field_column_name) {
    // @todo Should the actual field handler respect that this just renders a
    //   number?
    // @todo Create an optional entity field handler, that can render the
    //   entity.
    // @see https://www.drupal.org/node/2322949
    if ($entity_type_id = $field_definition->getItemDefinition()
        ->getSetting('target_type')) {
        $entity_type = $this->entityTypeManager
            ->getDefinition($entity_type_id);
        if ($entity_type instanceof ContentEntityType) {
            $views_field['relationship'] = [
                'base' => $this->getViewsTableForEntityType($entity_type),
                'base field' => $entity_type->getKey('id'),
                'label' => $entity_type->getLabel(),
                'title' => $entity_type->getLabel(),
                'id' => 'standard',
            ];
            $views_field['field']['id'] = 'field';
            // Provide an argument plugin that has a meaningful titleQuery()
            // implementation getting the entity label.
            $views_field['argument']['id'] = 'entity_target_id';
            $views_field['argument']['target_entity_type_id'] = $entity_type_id;
            $views_field['filter']['id'] = 'numeric';
            $views_field['sort']['id'] = 'standard';
        }
        else {
            $views_field['field']['id'] = 'field';
            $views_field['argument']['id'] = 'string';
            $views_field['filter']['id'] = 'string';
            $views_field['sort']['id'] = 'standard';
        }
    }
    if ($field_definition->getName() == $this->entityType
        ->getKey('bundle')) {
        $views_field['filter']['id'] = 'bundle';
    }
}

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