Commit 35b3d0fa authored by alexpott's avatar alexpott

Issue #1740492 by dawehner, damiankloip, dasjo, xjm: Implement a default entity views data handler.

parent 7f69cb44
......@@ -28,7 +28,7 @@ class SqlContentEntityStorageSchema implements EntitySchemaHandlerInterface {
/**
* The storage field definitions for this entity type.
*
* @var \Drupal\Core\Field\FieldDefinitionInterface[]
* @var \Drupal\Core\Field\FieldStorageDefinitionInterface[]
*/
protected $fieldStorageDefinitions;
......
......@@ -7,53 +7,32 @@
namespace Drupal\file;
use Drupal\views\EntityViewsDataInterface;
use Drupal\views\EntityViewsData;
/**
* Provides views data for the file entity type.
*/
class FileViewsData implements EntityViewsDataInterface {
class FileViewsData extends EntityViewsData {
/**
* {@inheritdoc}
*/
public function getViewsData() {
$data = array();
// Sets 'group' index for file_managed table.
$data['file_managed']['table']['group'] = t('File');
$data = parent::getViewsData();
// Advertise this table as a possible base table.
$data['file_managed']['table']['base'] = array(
'field' => 'fid',
'title' => t('File'),
'help' => t("Files maintained by Drupal and various modules."),
'defaults' => array(
'field' => 'filename'
),
);
$data['file_managed']['table']['entity type'] = 'file';
// @TODO There is no corresponding information in entity metadata.
$data['file_managed']['table']['base']['help'] = t('Files maintained by Drupal and various modules.');
$data['file_managed']['table']['base']['defaults']['field'] = 'filename';
$data['file_managed']['table']['wizard_id'] = 'file_managed';
// Describes fid field in file_managed table.
$data['file_managed']['fid'] = array(
'title' => t('File ID'),
'help' => t('The ID of the file.'),
'field' => array(
'id' => 'file',
),
'argument' => array(
$data['file_managed']['fid']['field']['id'] ='file';
$data['file_managed']['fid']['argument'] = array(
'id' => 'file_fid',
// The field to display in the summary.
'name field' => 'filename',
'numeric' => TRUE,
),
'filter' => array(
'id' => 'numeric',
),
'sort' => array(
'id' => 'standard',
),
'relationship' => array(
);
$data['file_managed']['fid']['relationship'] = array(
'title' => t('File usage'),
'help' => t('Relate file entities to their usage.'),
'id' => 'standard',
......@@ -61,64 +40,14 @@ public function getViewsData() {
'base field' => 'fid',
'field' => 'fid',
'label' => t('File usage'),
),
);
// Describes filename field in file_managed table.
$data['file_managed']['filename'] = array(
'title' => t('Name'),
'help' => t('The name of the file.'),
'field' => array(
'id' => 'file',
),
'sort' => array(
'id' => 'standard',
),
'filter' => array(
'id' => 'string',
),
'argument' => array(
'id' => 'string',
),
);
$data['file_managed']['filename']['field']['id'] = 'file';
// Describes uri field in file_managed table.
$data['file_managed']['uri'] = array(
'title' => t('Path'),
'help' => t('The path of the file.'),
'field' => array(
'id' => 'file_uri',
),
'sort' => array(
'id' => 'standard',
),
'filter' => array(
'id' => 'string',
),
'argument' => array(
'id' => 'string',
),
);
$data['file_managed']['uri']['field']['id'] = 'file_uri';
// Describes filemime field in file_managed table.
$data['file_managed']['filemime'] = array(
'title' => t('Mime type'),
'help' => t('The mime type of the file.'),
'field' => array(
'id' => 'file_filemime',
),
'sort' => array(
'id' => 'standard',
),
'filter' => array(
'id' => 'string',
),
'argument' => array(
'id' => 'string',
),
);
$data['file_managed']['filemime']['field']['id'] = 'file_filemime';
// Describes extension field in file_managed table.
$data['file_managed']['extension'] = array(
'title' => t('Extension'),
'help' => t('The extension of the file.'),
......@@ -129,79 +58,14 @@ public function getViewsData() {
),
);
// Describes filesize field in file_managed table.
$data['file_managed']['filesize'] = array(
'title' => t('Size'),
'help' => t('The size of the file.'),
'field' => array(
'id' => 'file_size',
),
'sort' => array(
'id' => 'standard',
),
'filter' => array(
'id' => 'numeric',
),
);
// Describes status field in file_managed table.
$data['file_managed']['status'] = array(
'title' => t('Status'),
'help' => t('The status of the file.'),
'field' => array(
'id' => 'file_status',
),
'sort' => array(
'id' => 'standard',
),
'filter' => array(
'id' => 'file_status',
),
);
// Describes created field in file_managed table.
$data['file_managed']['created'] = array(
'title' => t('Upload date'),
'help' => t('The date the file was uploaded.'),
'field' => array(
'id' => 'date',
),
'sort' => array(
'id' => 'date',
),
'filter' => array(
'id' => 'date',
),
);
$data['file_managed']['filesize']['field']['id'] = 'file_size';
// Describes changed field in file_managed table.
$data['file_managed']['changed'] = array(
'title' => t('Modified date'),
'help' => t('The date the file was last changed.'),
'field' => array(
'id' => 'date',
),
'sort' => array(
'id' => 'date',
),
'filter' => array(
'id' => 'date',
),
);
$data['file_managed']['status']['field']['id'] = 'file_status';
$data['file_managed']['status']['filter']['id'] = 'file_status';
// Describes uid field in file_managed table.
$data['file_managed']['uid'] = array(
'title' => t('User who uploaded'),
'help' => t('The user that uploaded the file.'),
'relationship' => array(
'title' => t('User who uploaded'),
'label' => t('User who uploaded'),
'base' => 'users',
'base field' => 'uid',
),
);
$data['file_managed']['uid']['relationship']['title'] = t('User who uploaded');
$data['file_managed']['uid']['relationship']['label'] = t('User who uploaded');
// Sets 'group' index for file_usage table.
$data['file_usage']['table']['group'] = t('File Usage');
// Provide field-type-things to several base tables; on the core files table
......@@ -499,4 +363,3 @@ public function getViewsData() {
}
}
This diff is collapsed.
......@@ -310,7 +310,8 @@
* 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.
* to provide views data for the entity type. You can autogenerate most of
* the views data by extending \Drupal\views\EntityViewsData.
* - 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
......
......@@ -29,7 +29,8 @@
* "default" = "Drupal\entity_test\EntityTestForm",
* "delete" = "Drupal\entity_test\EntityTestDeleteForm"
* },
* "translation" = "Drupal\content_translation\ContentTranslationHandler"
* "translation" = "Drupal\content_translation\ContentTranslationHandler",
* "views_data" = "Drupal\views\EntityViewsData"
* },
* base_table = "entity_test",
* fieldable = TRUE,
......
......@@ -24,7 +24,8 @@
* "default" = "Drupal\entity_test\EntityTestForm",
* "delete" = "Drupal\entity_test\EntityTestDeleteForm"
* },
* "translation" = "Drupal\content_translation\ContentTranslationHandler"
* "translation" = "Drupal\content_translation\ContentTranslationHandler",
* "views_data" = "Drupal\views\EntityViewsData"
* },
* base_table = "entity_test_mul",
* data_table = "entity_test_mul_property_data",
......
......@@ -23,7 +23,8 @@
* "default" = "Drupal\entity_test\EntityTestForm",
* "delete" = "Drupal\entity_test\EntityTestDeleteForm"
* },
* "translation" = "Drupal\content_translation\ContentTranslationHandler"
* "translation" = "Drupal\content_translation\ContentTranslationHandler",
* "views_data" = "Drupal\views\EntityViewsData"
* },
* base_table = "entity_test_mulrev",
* data_table = "entity_test_mulrev_property_data",
......
......@@ -23,7 +23,8 @@
* "default" = "Drupal\entity_test\EntityTestForm",
* "delete" = "Drupal\entity_test\EntityTestDeleteForm"
* },
* "translation" = "Drupal\content_translation\ContentTranslationHandler"
* "translation" = "Drupal\content_translation\ContentTranslationHandler",
* "views_data" = "Drupal\views\EntityViewsData"
* },
* base_table = "entity_test_rev",
* revision_table = "entity_test_rev_revision",
......
This diff is collapsed.
......@@ -26,9 +26,10 @@
* 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.
* "views_data" annotation in the entity class. You can autogenerate big parts
* of the ingration if you extend the \Drupal\views\EntityViewsData base
* 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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment