Commit 17fcc164 authored by alexpott's avatar alexpott

Issue #2319671 by dawehner, jhodgdon, xjm, alexpott: ViewsDataController:...

Issue #2319671 by dawehner, jhodgdon, xjm, alexpott: ViewsDataController: Step1: Move entity views data into controllers.
parent b3695e87
This diff is collapsed.
This diff is collapsed.
......@@ -27,6 +27,7 @@
* "storage" = "Drupal\comment\CommentStorage",
* "access" = "Drupal\comment\CommentAccessControlHandler",
* "view_builder" = "Drupal\comment\CommentViewBuilder",
* "views_data" = "Drupal\comment\CommentViewsData",
* "form" = {
* "default" = "Drupal\comment\CommentForm",
* "delete" = "Drupal\comment\Form\DeleteForm"
......
This diff is collapsed.
......@@ -24,7 +24,8 @@
* controllers = {
* "storage" = "Drupal\file\FileStorage",
* "access" = "Drupal\file\FileAccessControlHandler",
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder"
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
* "views_data" = "Drupal\file\FileViewsData",
* },
* base_table = "file_managed",
* entity_keys = {
......
This diff is collapsed.
This diff is collapsed.
......@@ -27,6 +27,7 @@
* "storage" = "Drupal\node\NodeStorage",
* "view_builder" = "Drupal\node\NodeViewBuilder",
* "access" = "Drupal\node\NodeAccessControlHandler",
* "views_data" = "Drupal\node\NodeViewsData",
* "form" = {
* "default" = "Drupal\node\NodeForm",
* "delete" = "Drupal\node\Form\NodeDeleteForm",
......
This diff is collapsed.
......@@ -309,6 +309,8 @@
* entities will use \Drupal\Core\Entity\ContentEntityDatabaseStorage, and
* config entities will use \Drupal\Core\Config\Entity\ConfigEntityStorage.
* You can extend one of these classes to provide custom behavior.
* - views_data: A class implementing \Drupal\views\EntityViewsDataInterface
* to provide views data for the entity type.
* - For content entities, the annotation will refer to a number of database
* tables and their fields. These annotation properties, such as 'base_table',
* 'data_table', 'entity_keys', etc., are documented on
......
<?php
/**
* @file
* Provide views data for entity_test.module.
*/
/**
* Implements hook_views_data().
*/
function entity_test_views_data() {
$data = array();
$data['entity_test']['table']['group'] = t('Entity test');
$data['entity_test']['table']['base'] = array(
'field' => 'id',
'title' => t('Entity test'),
);
$data['entity_test']['table']['entity type'] = 'entity_test';
$data['entity_test']['id'] = array(
'title' => t('ID'),
'help' => t('Primary Key: Unique entity-test item ID.'),
'argument' => array(
'id' => 'numeric',
),
'field' => array(
'id' => 'numeric',
),
'filter' => array(
'id' => 'numeric',
),
'sort' => array(
'id' => 'standard',
),
);
$data['entity_test']['uuid'] = array(
'title' => t('UUID'),
'help' => t('Unique Key: Universally unique identifier for this entity.'),
'argument' => array(
'id' => 'string',
),
'field' => array(
'id' => 'standard',
'click sortable' => FALSE,
),
'filter' => array(
'id' => 'string',
),
'sort' => array(
'id' => 'standard',
),
);
if (\Drupal::moduleHandler()->moduleExists('langcode')) {
$data['entity_test']['langcode'] = array(
'title' => t('Language'),
'help' => t('The {language}.langcode of the original variant of this test entity.'),
'field' => array(
'id' => 'language',
),
'filter' => array(
'id' => 'language',
),
'argument' => array(
'id' => 'language',
),
'sort' => array(
'id' => 'standard',
),
);
}
$data['entity_test']['name'] = array(
'title' => t('Name'),
'help' => t('The name of the test entity.'),
'field' => array(
'id' => 'standard',
),
'filter' => array(
'id' => 'string',
),
'argument' => array(
'id' => 'string',
),
'sort' => array(
'id' => 'standard',
),
);
$data['entity_test']['user_id'] = array(
'title' => t('Name'),
'help' => t('The name of the test entity.'),
'field' => array(
'id' => 'user',
),
'filter' => array(
'id' => 'user_name',
),
'argument' => array(
'id' => 'uid',
),
'sort' => array(
'id' => 'standard',
),
'relationship' => array(
'title' => t('UID'),
'help' => t('The The {users}.uid of the associated user.'),
'base' => 'users',
'base field' => 'uid',
'id' => 'standard',
'label' => t('UID'),
),
);
return $data;
}
......@@ -23,6 +23,7 @@
* controllers = {
* "list_builder" = "Drupal\entity_test\EntityTestListBuilder",
* "view_builder" = "Drupal\entity_test\EntityTestViewBuilder",
* "views_data" = "Drupal\entity_test\EntityTestViewsData",
* "access" = "Drupal\entity_test\EntityTestAccessControlHandler",
* "form" = {
* "default" = "Drupal\entity_test\EntityTestForm",
......
<?php
/**
* @file
* Contains \Drupal\entity_test\EntityTestViewsData.
*/
namespace Drupal\entity_test;
use Drupal\views\EntityViewsDataInterface;
/**
* Provides views data for the entity_test entity type.
*/
class EntityTestViewsData implements EntityViewsDataInterface {
/**
* {@inheritdoc}
*/
public function getViewsData() {
$data = array();
$data['entity_test']['table']['group'] = t('Entity test');
$data['entity_test']['table']['base'] = array(
'field' => 'id',
'title' => t('Entity test'),
);
$data['entity_test']['table']['entity type'] = 'entity_test';
$data['entity_test']['id'] = array(
'title' => t('ID'),
'help' => t('Primary Key: Unique entity-test item ID.'),
'argument' => array(
'id' => 'numeric',
),
'field' => array(
'id' => 'numeric',
),
'filter' => array(
'id' => 'numeric',
),
'sort' => array(
'id' => 'standard',
),
);
$data['entity_test']['uuid'] = array(
'title' => t('UUID'),
'help' => t('Unique Key: Universally unique identifier for this entity.'),
'argument' => array(
'id' => 'string',
),
'field' => array(
'id' => 'standard',
'click sortable' => FALSE,
),
'filter' => array(
'id' => 'string',
),
'sort' => array(
'id' => 'standard',
),
);
if (\Drupal::moduleHandler()->moduleExists('langcode')) {
$data['entity_test']['langcode'] = array(
'title' => t('Language'),
'help' => t('The {language}.langcode of the original variant of this test entity.'),
'field' => array(
'id' => 'language',
),
'filter' => array(
'id' => 'language',
),
'argument' => array(
'id' => 'language',
),
'sort' => array(
'id' => 'standard',
),
);
}
$data['entity_test']['name'] = array(
'title' => t('Name'),
'help' => t('The name of the test entity.'),
'field' => array(
'id' => 'standard',
),
'filter' => array(
'id' => 'string',
),
'argument' => array(
'id' => 'string',
),
'sort' => array(
'id' => 'standard',
),
);
$data['entity_test']['user_id'] = array(
'title' => t('Name'),
'help' => t('The name of the test entity.'),
'field' => array(
'id' => 'user',
),
'filter' => array(
'id' => 'user_name',
),
'argument' => array(
'id' => 'uid',
),
'sort' => array(
'id' => 'standard',
),
'relationship' => array(
'title' => t('UID'),
'help' => t('The The {users}.uid of the associated user.'),
'base' => 'users',
'base field' => 'uid',
'id' => 'standard',
'label' => t('UID'),
),
);
return $data;
}
}
......@@ -24,6 +24,7 @@
* "storage" = "Drupal\taxonomy\TermStorage",
* "view_builder" = "Drupal\taxonomy\TermViewBuilder",
* "access" = "Drupal\taxonomy\TermAccessControlHandler",
* "views_data" = "Drupal\taxonomy\TermViewsData",
* "form" = {
* "default" = "Drupal\taxonomy\TermForm",
* "delete" = "Drupal\taxonomy\Form\TermDeleteForm"
......
This diff is collapsed.
......@@ -8,342 +8,6 @@
use Drupal\Core\Entity\ContentEntityDatabaseStorage;
use Drupal\field\FieldStorageConfigInterface;
/**
* Implements hook_views_data().
*/
function taxonomy_views_data() {
$data = array();
$data['taxonomy_term_data']['table']['group'] = t('Taxonomy term');
$data['taxonomy_term_data']['table']['base'] = array(
'field' => 'tid',
'title' => t('Term'),
'help' => t('Taxonomy terms are attached to nodes.'),
'access query tag' => 'term_access',
);
$data['taxonomy_term_data']['table']['entity type'] = 'taxonomy_term';
$data['taxonomy_term_data']['table']['wizard_id'] = 'taxonomy_term';
$data['taxonomy_term_data']['table']['join'] = array(
// This is provided for the many_to_one argument.
'taxonomy_index' => array(
'field' => 'tid',
'left_field' => 'tid',
),
);
$data['taxonomy_term_field_data']['table']['group'] = t('Taxonomy term');
$data['taxonomy_term_field_data']['table']['entity type'] = 'taxonomy_term';
$data['taxonomy_term_field_data']['table']['join']['taxonomy_term_data'] = array(
'type' => 'INNER',
'left_field' => 'tid',
'field' => 'tid',
);
$data['taxonomy_term_data']['tid'] = array(
'title' => t('Term ID'),
'help' => t('The tid of a taxonomy term.'),
'field' => array(
'id' => 'numeric',
),
'sort' => array(
'id' => 'standard',
),
'argument' => array(
'id' => 'taxonomy',
'name field' => 'name',
'zero is null' => TRUE,
),
'filter' => array(
'title' => t('Term'),
'help' => t('Taxonomy term chosen from autocomplete or select widget.'),
'id' => 'taxonomy_index_tid',
'hierarchy table' => 'taxonomy_term_hierarchy',
'numeric' => TRUE,
),
);
$data['taxonomy_term_data']['tid_raw'] = array(
'title' => t('Term ID'),
'help' => t('The tid of a taxonomy term.'),
'real field' => 'tid',
'filter' => array(
'id' => 'numeric',
'allow empty' => TRUE,
),
);
$data['taxonomy_term_data']['tid_representative'] = array(
'relationship' => array(
'title' => t('Representative node'),
'label' => t('Representative node'),
'help' => t('Obtains a single representative node for each term, according to a chosen sort criterion.'),
'id' => 'groupwise_max',
'relationship field' => 'tid',
'outer field' => 'taxonomy_term_data.tid',
'argument table' => 'taxonomy_term_field_data',
'argument field' => 'tid',
'base' => 'node',
'field' => 'nid',
'relationship' => 'node:term_node_tid'
),
);
$data['taxonomy_term_field_data']['name'] = array(
'title' => t('Name'),
'help' => t('The taxonomy term name.'),
'field' => array(
'id' => 'taxonomy',
),
'sort' => array(
'id' => 'standard',
),
'filter' => array(
'id' => 'string',
'help' => t('Taxonomy term name.'),
),
'argument' => array(
'id' => 'string',
'help' => t('Taxonomy term name.'),
'many to one' => TRUE,
'empty field name' => t('Uncategorized'),
),
);
$data['taxonomy_term_field_data']['weight'] = array(
'title' => t('Weight'),
'help' => t('The term weight field'),
'field' => array(
'id' => 'numeric',
),
'sort' => array(
'id' => 'standard',
),
'filter' => array(
'id' => 'numeric',
),
'argument' => array(
'id' => 'numeric',
),
);
$data['taxonomy_term_field_data']['description__value'] = array(
'title' => t('Term description'),
'help' => t('The description associated with a taxonomy term.'),
'field' => array(
'id' => 'markup',
'format' => array('field' => 'description__format'),
'click sortable' => FALSE,
),
'filter' => array(
'id' => 'string',
),
);
$data['taxonomy_term_data']['vid'] = array(
'title' => t('Vocabulary'),
'help' => t('Filter the results of "Taxonomy: Term" to a particular vocabulary.'),
'filter' => array(
'id' => 'bundle',
),
);
$data['taxonomy_term_field_data']['langcode'] = array(
'title' => t('Language'), // The item it appears as on the UI,
'help' => t('Language of the term'),
'field' => array(
'id' => 'taxonomy_term_language',
),
'sort' => array(
'id' => 'standard',
),
'filter' => array(
'id' => 'language',
),
'argument' => array(
'id' => 'language',
),
);
$data['taxonomy_term_data']['edit_term'] = array(
'field' => array(
'title' => t('Term edit link'),
'help' => t('Provide a simple link to edit the term.'),
'id' => 'term_link_edit',
'click sortable' => FALSE,
),
);
$data['taxonomy_term_field_data']['changed'] = array(
'title' => t('Updated date'),
'help' => t('The date the term was last updated.'),
'field' => array(
'id' => 'date',
),
'sort' => array(
'id' => 'date'
),
'filter' => array(
'id' => 'date',
),
);
$data['taxonomy_term_field_data']['changed_fulldate'] = array(
'title' => t('Updated date'),
'help' => t('Date in the form of CCYYMMDD.'),
'argument' => array(
'field' => 'changed',
'id' => 'date_fulldate',
),
);
$data['taxonomy_term_field_data']['changed_year_month'] = array(
'title' => t('Updated year + month'),
'help' => t('Date in the form of YYYYMM.'),
'argument' => array(
'field' => 'changed',
'id' => 'date_year_month',
),
);
$data['taxonomy_term_field_data']['changed_year'] = array(
'title' => t('Updated year'),
'help' => t('Date in the form of YYYY.'),
'argument' => array(
'field' => 'changed',
'id' => 'date_year',
),
);
$data['taxonomy_term_field_data']['changed_month'] = array(
'title' => t('Updated month'),
'help' => t('Date in the form of MM (01 - 12).'),
'argument' => array(
'field' => 'changed',
'id' => 'date_month',
),
);
$data['taxonomy_term_field_data']['changed_day'] = array(
'title' => t('Updated day'),
'help' => t('Date in the form of DD (01 - 31).'),
'argument' => array(
'field' => 'changed',
'id' => 'date_day',
),
);
$data['taxonomy_term_field_data']['changed_week'] = array(
'title' => t('Updated week'),
'help' => t('Date in the form of WW (01 - 53).'),
'argument' => array(
'field' => 'changed',
'id' => 'date_week',
),
);
if (\Drupal::moduleHandler()->moduleExists('content_translation')) {
$data['taxonomy_term_data']['translation_link'] = array(
'title' => t('Translation link'),
'help' => t('Provide a link to the translations overview for taxonomy terms.'),
'field' => array(
'id' => 'content_translation_link',
),
);
}
$data['taxonomy_index']['table']['group'] = t('Taxonomy term');
$data['taxonomy_index']['table']['join'] = array(
'taxonomy_term_data' => array(
// links directly to taxonomy_term_data via tid
'left_field' => 'tid',
'field' => 'tid',
),
'node' => array(
// links directly to node via nid
'left_field' => 'nid',
'field' => 'nid',
),
'taxonomy_term_hierarchy' => array(
'left_field' => 'tid',
'field' => 'tid',
),
);
$data['taxonomy_index']['nid'] = array(
'title' => t('Content with term'),
'help' => t('Relate all content tagged with a term.'),
'relationship' => array(
'id' => 'standard',
'base' => 'node',
'base field' => 'nid',
'label' => t('node'),
'skip base' => 'node',
),
);
// @todo This stuff needs to move to a node field since really it's all about
// nodes.
$data['taxonomy_index']['tid'] = array(
'group' => t('Content'),
'title' => t('Has taxonomy term ID'),
'help' => t('Display content if it has the selected taxonomy terms.'),
'argument' => array(
'id' => 'taxonomy_index_tid',
'name table' => 'taxonomy_term_field_data',
'name field' => 'name',
'empty field name' => t('Uncategorized'),
'numeric' => TRUE,
'skip base' => 'taxonomy_term_data',
),
'filter' => array(
'title' => t('Has taxonomy term'),
'id' => 'taxonomy_index_tid',
'hierarchy table' => 'taxonomy_term_hierarchy',
'numeric' => TRUE,
'skip base' => 'taxonomy_term_data',
'allow empty' => TRUE,
),
);
$data['taxonomy_term_hierarchy']['table']['group'] = t('Taxonomy term');
$data['taxonomy_term_hierarchy']['table']['join'] = array(
'taxonomy_term_hierarchy' => array(
// Link to self through left.parent = right.tid (going down in depth).
'left_field' => 'tid',
'field' => 'parent',
),
'taxonomy_term_data' => array(
// Link directly to taxonomy_term_data via tid.
'left_field' => 'tid',
'field' => 'tid',
),
);
$data['taxonomy_term_hierarchy']['parent'] = array(
'title' => t('Parent term'),
'help' => t('The parent term of the term. This can produce duplicate entries if you are using a vocabulary that allows multiple parents.'),
'relationship' => array(
'base' => 'taxonomy_term_data',
'field' => 'parent',
'label' => t('Parent'),
'id' => 'standard',
),
'filter' => array(
'help' => t('Filter the results of "Taxonomy: Term" by the parent pid.'),
'id' => 'numeric',
),
'argument' => array(
'help' => t('The parent term of the term.'),
'id' => 'taxonomy',
),
);
return $data;
}
/**
* Implements hook_views_data_alter().
*/
......
......@@ -28,6 +28,7 @@
* "access" = "Drupal\user\UserAccessControlHandler",
* "list_builder" = "Drupal\user\UserListBuilder",
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
* "views_data" = "Drupal\user\UserViewsData",
* "form" = {
* "default" = "Drupal\user\ProfileForm",
* "cancel" = "Drupal\user\Form\UserCancelForm",
......
This diff is collapsed.
This diff is collapsed.
<?php
/**
* @file
* Contains \Drupal\views\EntityViewsDataInterface.
*/
namespace Drupal\views;
/**
* Provides an interface to integrate an entity type with views.
*/
interface EntityViewsDataInterface {
/**
* Returns views data for the entity type.
*
* @return array
* Views data in the format of hook_views_data().
*/
public function getViewsData();
}
......@@ -22,8 +22,13 @@
* field). See the @link views_plugins Views plugins topic @endlink for
* more information.
* - Provide data: Data types can be provided to Views by implementing
* hook_views_data(), and data types provided by other modules can be
* altered by implementing hook_views_data_alter().
* hook_views_data(), and data types provided by other modules can be altered
* by implementing hook_views_data_alter(). To provide views data for an
* entity, create a class implementing
* \Drupal\views\EntityViewsDataInterface and reference this in the
* "views_data" annotation in the entity class. See the
* @link entity_api Entity API topic @endlink for more information about
* entities.
* - Implement hooks: A few operations in Views can be influenced by hooks.
* See the @link Views hooks topic @endlink for a list.
* - Theming: See the @link views_templates Views templates topic @endlink
......@@ -88,6 +93,13 @@ function hook_views_analyze(Drupal\views\ViewExecutable $view) {
* The table and fields are processed in Views using various plugins. See