/** * Puts the views data for a single field onto the views data. * * @param string $table * The table of the field to handle. * @param string $field_name * The name of the field to handle. * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition * The field definition defined in Entity::baseFieldDefinitions() * @param \Drupal\Core\Entity\Sql\TableMappingInterface $table_mapping * The table mapping information * @param array $table_data * A reference to a specific entity table (for example data_table) inside * the views data. */ 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; } }