diff -u b/core/modules/views/views.api.php b/core/modules/views/views.api.php --- b/core/modules/views/views.api.php +++ b/core/modules/views/views.api.php @@ -4,7 +4,6 @@ * @file * Describes hooks and plugins provided by the Views module. */ - /** * @defgroup views_plugins Views plugins * @@ -90,7 +89,6 @@ * @see \Drupal\views\Plugin\views\PluginBase * @see \Drupal\views\Plugin\views\HandlerBase */ - /** * @defgroup views_hooks Views hooks * @{ @@ -140,10 +138,8 @@ // timestamp_field INT(8) COMMENT 'Just a timestamp field.', // PRIMARY KEY(nid) // ); - // First, the entry $data['example_table']['table'] describes properties of // the actual table – not its content. - // The 'group' index will be used as a prefix in the UI for any of this // table's fields, sort criteria, etc. so it's easy to tell where they came // from. @@ -188,7 +184,6 @@ // footer or as no result behavior. // // The handler descriptions are described with examples below. - // Node ID table field. $data['example_table']['nid'] = array( 'title' => t('Example content'), @@ -229,7 +224,7 @@ 'help' => t('Just a numeric field.'), 'field' => array( 'id' => 'numeric', - ), + ), 'filter' => array( 'id' => 'numeric', ), @@ -327,7 +322,7 @@ } /** - * Override the default data for a Field API field. + * Override the default data for a Views API field data. * * Field module's implementation of hook_views_data() invokes this for each * field in the module that defines the field type (as declared in the field @@ -336,16 +331,16 @@ * If no hook implementation exists, hook_views_data() falls back to * field_views_field_default_views_data(). * - * @see field_views_data() - * @see hook_field_views_data_alter() - * @see hook_field_views_data_views_data_alter() - * * @param \Drupal\field\FieldInterface $field - * A field definition. + * A field definition. * * @return array - * An array of views data, in the same format as the return value of - * hook_views_data(). + * An array of views data, in the same format as the return value of + * hook_views_data(). + * + * @see field_views_data() + * @see hook_field_views_data_alter() + * @see hook_field_views_data_views_data_alter() */ function hook_field_views_data(\Drupal\field\FieldInterface $field) { $data = field_views_field_default_views_data($field); @@ -372,15 +367,40 @@ * @param array $result * An array of views table data provided for a single field. This has the same * format as the return value of hook_views_data(). - * @param \Drupal\field\FieldInterface $field - * A field definition. + * @param \Drupal\field\FieldConfigInterface $field + * A field config entity. * * @see field_views_data() * @see hook_field_views_data() * @see hook_field_views_data_views_data_alter() */ -function hook_field_views_data_alter(&$result, \Drupal\field\FieldInterface $field) { +function hook_field_views_data_alter(array &$result, \Drupal\field\FieldConfigInterface $field) { + $entity_type_id = $field->entity_type; + $field_name = $field->getName(); + $entity_type = \Drupal::entityManager()->getDefinition($entity_type_id); + $pseudo_field_name = 'reverse_' . $field_name . '_' . $entity_type_id; + list($label) = field_views_field_label($entity_type_id, $field_name); + + $data['file_managed'][$pseudo_field_name]['relationship'] = array( + 'title' => t('@entity using @field', array('@entity' => $entity_type->getLabel(), '@field' => $label)), + 'help' => t('Relate each @entity with a @field set to the image.', array('@entity' => $entity_type->getLabel(), '@field' => $label)), + 'id' => 'entity_reverse', + 'field_name' => $field_name, + 'entity_type' => $entity_type_id, + 'field table' => ContentEntityDatabaseStorage::_fieldTableName($field), + 'field field' => $field_name . '_target_id', + 'base' => $entity_type->getBaseTable(), + 'base field' => $entity_type->getKey('id'), + 'label' => t('!field_name', array('!field_name' => $field_name)), + 'join_extra' => array( + 0 => array( + 'field' => 'deleted', + 'value' => 0, + 'numeric' => TRUE, + ), + ), + ); } /**