Chris@0: $table_data) { Chris@0: // Add the relationship only on the target_id field. Chris@0: $data[$table_name][$field_storage->getName() . '_target_id']['relationship'] = [ Chris@0: 'id' => 'standard', Chris@0: 'base' => 'file_managed', Chris@0: 'entity type' => 'file', Chris@0: 'base field' => 'fid', Chris@0: 'label' => t('image from @field_name', ['@field_name' => $field_storage->getName()]), Chris@0: ]; Chris@0: } Chris@0: Chris@0: return $data; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Implements hook_field_views_data_views_data_alter(). Chris@0: * Chris@0: * Views integration to provide reverse relationships on image fields. Chris@0: */ Chris@0: function image_field_views_data_views_data_alter(array &$data, FieldStorageConfigInterface $field_storage) { Chris@0: $entity_type_id = $field_storage->getTargetEntityTypeId(); Chris@0: $field_name = $field_storage->getName(); Chris@0: $entity_manager = \Drupal::entityManager(); Chris@0: $entity_type = $entity_manager->getDefinition($entity_type_id); Chris@0: $pseudo_field_name = 'reverse_' . $field_name . '_' . $entity_type_id; Chris@0: /** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */ Chris@0: $table_mapping = $entity_manager->getStorage($entity_type_id)->getTableMapping(); Chris@0: Chris@0: list($label) = views_entity_field_label($entity_type_id, $field_name); Chris@0: Chris@0: $data['file_managed'][$pseudo_field_name]['relationship'] = [ Chris@0: 'title' => t('@entity using @field', ['@entity' => $entity_type->getLabel(), '@field' => $label]), Chris@0: 'label' => t('@field_name', ['@field_name' => $field_name]), Chris@0: 'help' => t('Relate each @entity with a @field set to the image.', ['@entity' => $entity_type->getLabel(), '@field' => $label]), Chris@0: 'group' => $entity_type->getLabel(), Chris@0: 'id' => 'entity_reverse', Chris@0: 'base' => $entity_type->getDataTable() ?: $entity_type->getBaseTable(), Chris@0: 'entity_type' => $entity_type_id, Chris@0: 'base field' => $entity_type->getKey('id'), Chris@0: 'field_name' => $field_name, Chris@0: 'field table' => $table_mapping->getDedicatedDataTableName($field_storage), Chris@0: 'field field' => $field_name . '_target_id', Chris@0: 'join_extra' => [ Chris@0: 0 => [ Chris@0: 'field' => 'deleted', Chris@0: 'value' => 0, Chris@0: 'numeric' => TRUE, Chris@0: ], Chris@0: ], Chris@0: ]; Chris@0: }