EntityViewsData::mapFieldDefinition

protected EntityViewsData::mapFieldDefinition($table, $field_name, FieldDefinitionInterface $field_definition, TableMappingInterface $table_mapping, &$table_data)

Puts the views data for a single field onto the views data.

Parameters

string $table: The table of the field to handle.

string $field_name: The name of the field to handle.

\Drupal\Core\Field\FieldDefinitionInterface $field_definition: The field definition defined in Entity::baseFieldDefinitions()

\Drupal\Core\Entity\Sql\TableMappingInterface $table_mapping: The table mapping information

array $table_data: A reference to a specific entity table (for example data_table) inside the views data.

File

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

Class

EntityViewsData
Provides generic views integration for entities.

Namespace

Drupal\views

Code

protected function mapFieldDefinition($table, $field_name, FieldDefinitionInterface $field_definition, TableMappingInterface $table_mapping, &$table_data) {
  // Create a dummy instance to retrieve property definitions.
  $field_column_mapping = $table_mapping->getColumnNames($field_name);
  $field_schema = $this->getFieldStorageDefinitions()[$field_name]->getSchema();

  $field_definition_type = $field_definition->getType();
  // Add all properties to views table data. We need an entry for each
  // column of each field, with the first one given special treatment.
  // @todo Introduce concept of the "main" column for a field, rather than
  //   assuming the first one is the main column. See also what the
  //   mapSingleFieldViewsData() method does with $first.
  $multiple = (count($field_column_mapping) > 1);
  $first = TRUE;
  foreach ($field_column_mapping as $field_column_name => $schema_field_name) {
    $views_field_name = ($multiple) ? $field_name . '__' . $field_column_name : $field_name;
    $table_data[$views_field_name] = $this->mapSingleFieldViewsData($table, $field_name, $field_definition_type, $field_column_name, $field_schema['columns'][$field_column_name]['type'], $first, $field_definition);

    $table_data[$views_field_name]['entity field'] = $field_name;
    $first = FALSE;
  }
}
doc_Drupal
2016-10-29 09:09:11
Comments
Leave a Comment

Please login to continue.