Commit 48ddeb48 authored by alexpott's avatar alexpott

Issue #2024963 by Berdir: Move baseFieldDefinitions from storage to entity classes.

parent 52771351
......@@ -437,14 +437,6 @@ public function save(EntityInterface $entity) {
return $return;
}
/**
* {@inheritdoc}
*/
public function baseFieldDefinitions() {
// @todo: Define abstract once all entity types have been converted.
return array();
}
/**
* Invokes a hook on behalf of the entity.
*
......
......@@ -552,14 +552,6 @@ protected function invokeHook($hook, EntityInterface $entity) {
module_invoke_all('entity_' . $hook, $entity, $this->entityType);
}
/**
* {@inheritdoc}
*/
public function baseFieldDefinitions() {
// @todo: Define abstract once all entity types have been converted.
return array();
}
/**
* Implements \Drupal\Core\Entity\EntityStorageControllerInterface::getQueryServiceName().
*/
......
......@@ -634,4 +634,11 @@ public function initTranslation($langcode) {
// http://drupal.org/node/2004244
}
/**
* {@inheritdoc}
*/
public static function baseFieldDefinitions($entity_type) {
return array();
}
}
......@@ -619,4 +619,11 @@ public function initTranslation($langcode) {
$this->decorated->initTranslation($langcode);
}
/**
* {@inheritdoc}
*/
public static function baseFieldDefinitions($entity_type) {
return array();
}
}
......@@ -326,4 +326,20 @@ public function isTranslatable();
*/
public function initTranslation($langcode);
/**
* Defines the base fields of the entity type.
*
* @param string $entity_type
* The entity type to return properties for. Useful when a single class is
* used for multiple, possibly dynamic entity types.
*
* @return array
* An array of entity field definitions as specified by
* \Drupal\Core\Entity\EntityManager::getFieldDefinitions(), keyed by field
* name.
*
* @see \Drupal\Core\Entity\EntityManager::getFieldDefinitions()
*/
public static function baseFieldDefinitions($entity_type);
}
......@@ -395,8 +395,9 @@ public function getFieldDefinitions($entity_type, $bundle = NULL) {
$this->entityFieldInfo[$entity_type] = $cache->data;
}
else {
$class = $this->factory->getPluginClass($entity_type, $this->getDefinition($entity_type));
$this->entityFieldInfo[$entity_type] = array(
'definitions' => $this->getStorageController($entity_type)->baseFieldDefinitions(),
'definitions' => $class::baseFieldDefinitions($entity_type),
// Contains definitions of optional (per-bundle) fields.
'optional' => array(),
// An array keyed by bundle name containing the optional fields added
......
......@@ -136,18 +136,6 @@ public function delete(array $entities);
*/
public function save(EntityInterface $entity);
/**
* Defines the base fields of the entity type.
*
* @return array
* An array of entity field definitions as specified by
* \Drupal\Core\Entity\EntityManager::getFieldDefinitions(), keyed by field
* name.
*
* @see \Drupal\Core\Entity\EntityManager::getFieldDefinitions()
*/
public function baseFieldDefinitions();
/**
* Gets the name of the service for the query for this entity storage.
*
......
......@@ -264,4 +264,82 @@ protected function clearBlockCacheDefinitions() {
}
}
/**
* {@inheritdoc}
*/
public static function baseFieldDefinitions($entity_type) {
$fields['fid'] = array(
'label' => t('ID'),
'description' => t('The ID of the aggregor feed.'),
'type' => 'integer_field',
'read-only' => TRUE,
);
$fields['title'] = array(
'label' => t('Title'),
'description' => t('The title of the feed.'),
'type' => 'string_field',
);
$fields['langcode'] = array(
'label' => t('Language code'),
'description' => t('The feed language code.'),
'type' => 'language_field',
);
$fields['url'] = array(
'label' => t('URL'),
'description' => t('The URL to the feed.'),
'type' => 'uri_field',
);
$fields['refresh'] = array(
'label' => t('Refresh'),
'description' => t('How often to check for new feed items, in seconds.'),
'type' => 'integer_field',
);
$fields['checked'] = array(
'label' => t('Checked'),
'description' => t('Last time feed was checked for new items, as Unix timestamp.'),
'type' => 'integer_field',
);
$fields['queued'] = array(
'label' => t('Queued'),
'description' => t('Time when this feed was queued for refresh, 0 if not queued.'),
'type' => 'integer_field',
);
$fields['link'] = array(
'label' => t('Link'),
'description' => t('The link of the feed.'),
'type' => 'uri_field',
);
$fields['description'] = array(
'label' => t('Description'),
'description' => t("The parent website's description that comes from the !description element in the feed.", array('!description' => '<description>')),
'type' => 'string_field',
);
$fields['image'] = array(
'label' => t('image'),
'description' => t('An image representing the feed.'),
'type' => 'uri_field',
);
$fields['hash'] = array(
'label' => t('Hash'),
'description' => t('Calculated hash of the feed data, used for validating cache.'),
'type' => 'string_field',
);
$fields['etag'] = array(
'label' => t('Etag'),
'description' => t('Entity tag HTTP response header, used for validating cache.'),
'type' => 'string_field',
);
$fields['modified'] = array(
'label' => t('Modified'),
'description' => t('When the feed was last modified, as a Unix timestamp.'),
'type' => 'integer_field',
);
$fields['block'] = array(
'label' => t('Block'),
'description' => t('Number of items to display in the feed’s block.'),
'type' => 'integer_field',
);
return $fields;
}
}
......@@ -154,4 +154,57 @@ public function postSave(EntityStorageControllerInterface $storage_controller, $
public static function preDelete(EntityStorageControllerInterface $storage_controller, array $entities) {
$storage_controller->deleteCategories($entities);
}
/**
* {@inheritdoc}
*/
public static function baseFieldDefinitions($entity_type) {
$fields['iid'] = array(
'label' => t('ID'),
'description' => t('The ID of the aggregor item.'),
'type' => 'integer_field',
'read-only' => TRUE,
);
$fields['fid'] = array(
'label' => t('Aggregator feed ID'),
'description' => t('The ID of the aggregator feed.'),
'type' => 'integer_field',
);
$fields['title'] = array(
'label' => t('Title'),
'description' => t('The title of the feed item.'),
'type' => 'string_field',
);
$fields['langcode'] = array(
'label' => t('Language code'),
'description' => t('The feed item language code.'),
'type' => 'language_field',
);
$fields['link'] = array(
'label' => t('Link'),
'description' => t('The link of the feed item.'),
'type' => 'uri_field',
);
$fields['author'] = array(
'label' => t('Author'),
'description' => t('The author of the feed item.'),
'type' => 'string_field',
);
$fields['description'] = array(
'label' => t('Description'),
'description' => t('The body of the feed item.'),
'type' => 'string_field',
);
$fields['timestamp'] = array(
'label' => t('Posted timestamp'),
'description' => t('Posted date of the feed item, as a Unix timestamp.'),
'type' => 'integer_field',
);
$fields['guid'] = array(
'label' => t('GUID'),
'description' => t('Unique identifier for the feed item.'),
'type' => 'string_field',
);
return $fields;
}
}
......@@ -27,84 +27,6 @@ protected function attachLoad(&$queried_entities, $load_revision = FALSE) {
$this->loadCategories($queried_entities);
}
/**
* Implements Drupal\Core\Entity\DataBaseStorageControllerNG::baseFieldDefinitions().
*/
public function baseFieldDefinitions() {
$fields['fid'] = array(
'label' => t('ID'),
'description' => t('The ID of the aggregor feed.'),
'type' => 'integer_field',
'read-only' => TRUE,
);
$fields['title'] = array(
'label' => t('Title'),
'description' => t('The title of the feed.'),
'type' => 'string_field',
);
$fields['langcode'] = array(
'label' => t('Language code'),
'description' => t('The feed language code.'),
'type' => 'language_field',
);
$fields['url'] = array(
'label' => t('URL'),
'description' => t('The URL to the feed.'),
'type' => 'uri_field',
);
$fields['refresh'] = array(
'label' => t('Refresh'),
'description' => t('How often to check for new feed items, in seconds.'),
'type' => 'integer_field',
);
$fields['checked'] = array(
'label' => t('Checked'),
'description' => t('Last time feed was checked for new items, as Unix timestamp.'),
'type' => 'integer_field',
);
$fields['queued'] = array(
'label' => t('Queued'),
'description' => t('Time when this feed was queued for refresh, 0 if not queued.'),
'type' => 'integer_field',
);
$fields['link'] = array(
'label' => t('Link'),
'description' => t('The link of the feed.'),
'type' => 'uri_field',
);
$fields['description'] = array(
'label' => t('Description'),
'description' => t("The parent website's description that comes from the !description element in the feed.", array('!description' => '<description>')),
'type' => 'string_field',
);
$fields['image'] = array(
'label' => t('image'),
'description' => t('An image representing the feed.'),
'type' => 'uri_field',
);
$fields['hash'] = array(
'label' => t('Hash'),
'description' => t('Calculated hash of the feed data, used for validating cache.'),
'type' => 'string_field',
);
$fields['etag'] = array(
'label' => t('Etag'),
'description' => t('Entity tag HTTP response header, used for validating cache.'),
'type' => 'string_field',
);
$fields['modified'] = array(
'label' => t('Modified'),
'description' => t('When the feed was last modified, as a Unix timestamp.'),
'type' => 'integer_field',
);
$fields['block'] = array(
'label' => t('Block'),
'description' => t('Number of items to display in the feed’s block.'),
'type' => 'integer_field',
);
return $fields;
}
/**
* {@inheritdoc}
*/
......
......@@ -28,59 +28,6 @@ protected function attachLoad(&$queried_entities, $load_revision = FALSE) {
$this->loadCategories($queried_entities);
}
/**
* Implements Drupal\Core\Entity\DataBaseStorageControllerNG::baseFieldDefinitions().
*/
public function baseFieldDefinitions() {
$fields['iid'] = array(
'label' => t('ID'),
'description' => t('The ID of the aggregor item.'),
'type' => 'integer_field',
'read-only' => TRUE,
);
$fields['fid'] = array(
'label' => t('Aggregator feed ID'),
'description' => t('The ID of the aggregator feed.'),
'type' => 'integer_field',
);
$fields['title'] = array(
'label' => t('Title'),
'description' => t('The title of the feed item.'),
'type' => 'string_field',
);
$fields['langcode'] = array(
'label' => t('Language code'),
'description' => t('The feed item language code.'),
'type' => 'language_field',
);
$fields['link'] = array(
'label' => t('Link'),
'description' => t('The link of the feed item.'),
'type' => 'uri_field',
);
$fields['author'] = array(
'label' => t('Author'),
'description' => t('The author of the feed item.'),
'type' => 'string_field',
);
$fields['description'] = array(
'label' => t('Description'),
'description' => t('The body of the feed item.'),
'type' => 'string_field',
);
$fields['timestamp'] = array(
'label' => t('Posted timestamp'),
'description' => t('Posted date of the feed item, as a Unix timestamp.'),
'type' => 'integer_field',
);
$fields['guid'] = array(
'label' => t('GUID'),
'description' => t('Unique identifier for the feed item.'),
'type' => 'string_field',
);
return $fields;
}
/**
* {@inheritdoc}
*/
......
......@@ -36,47 +36,4 @@ protected function attachLoad(&$blocks, $load_revision = FALSE) {
parent::attachLoad($blocks, $load_revision);
}
/**
* Implements \Drupal\Core\Entity\DataBaseStorageControllerNG::basePropertyDefinitions().
*/
public function baseFieldDefinitions() {
$properties['id'] = array(
'label' => t('ID'),
'description' => t('The custom block ID.'),
'type' => 'integer_field',
'read-only' => TRUE,
);
$properties['uuid'] = array(
'label' => t('UUID'),
'description' => t('The custom block UUID.'),
'type' => 'uuid_field',
);
$properties['revision_id'] = array(
'label' => t('Revision ID'),
'description' => t('The revision ID.'),
'type' => 'integer_field',
);
$properties['langcode'] = array(
'label' => t('Language code'),
'description' => t('The comment language code.'),
'type' => 'language_field',
);
$properties['info'] = array(
'label' => t('Subject'),
'description' => t('The custom block name.'),
'type' => 'string_field',
);
$properties['type'] = array(
'label' => t('Block type'),
'description' => t('The block type.'),
'type' => 'string_field',
);
$properties['log'] = array(
'label' => t('Revision log message'),
'description' => t('The revision log message.'),
'type' => 'string_field',
);
return $properties;
}
}
......@@ -235,4 +235,47 @@ public function delete() {
parent::delete();
}
/**
* {@inheritdoc}
*/
public static function baseFieldDefinitions($entity_type) {
$properties['id'] = array(
'label' => t('ID'),
'description' => t('The custom block ID.'),
'type' => 'integer_field',
'read-only' => TRUE,
);
$properties['uuid'] = array(
'label' => t('UUID'),
'description' => t('The custom block UUID.'),
'type' => 'uuid_field',
);
$properties['revision_id'] = array(
'label' => t('Revision ID'),
'description' => t('The revision ID.'),
'type' => 'integer_field',
);
$properties['langcode'] = array(
'label' => t('Language code'),
'description' => t('The comment language code.'),
'type' => 'language_field',
);
$properties['info'] = array(
'label' => t('Subject'),
'description' => t('The custom block name.'),
'type' => 'string_field',
);
$properties['type'] = array(
'label' => t('Block type'),
'description' => t('The block type.'),
'type' => 'string_field',
);
$properties['log'] = array(
'label' => t('Revision log message'),
'description' => t('The revision log message.'),
'type' => 'string_field',
);
return $properties;
}
}
......@@ -100,111 +100,6 @@ public function updateNodeStatistics($nid) {
}
}
/**
* {@inheritdoc}
*/
public function baseFieldDefinitions() {
$properties['cid'] = array(
'label' => t('ID'),
'description' => t('The comment ID.'),
'type' => 'integer_field',
'read-only' => TRUE,
);
$properties['uuid'] = array(
'label' => t('UUID'),
'description' => t('The comment UUID.'),
'type' => 'uuid_field',
);
$properties['pid'] = array(
'label' => t('Parent ID'),
'description' => t('The parent comment ID if this is a reply to a comment.'),
'type' => 'entity_reference_field',
'settings' => array('target_type' => 'comment'),
);
$properties['nid'] = array(
'label' => t('Node ID'),
'description' => t('The ID of the node of which this comment is a reply.'),
'type' => 'entity_reference_field',
'settings' => array('target_type' => 'node'),
'required' => TRUE,
);
$properties['langcode'] = array(
'label' => t('Language code'),
'description' => t('The comment language code.'),
'type' => 'language_field',
);
$properties['subject'] = array(
'label' => t('Subject'),
'description' => t('The comment title or subject.'),
'type' => 'string_field',
);
$properties['uid'] = array(
'label' => t('User ID'),
'description' => t('The user ID of the comment author.'),
'type' => 'entity_reference_field',
'settings' => array(
'target_type' => 'user',
'default_value' => 0,
),
);
$properties['name'] = array(
'label' => t('Name'),
'description' => t("The comment author's name."),
'type' => 'string_field',
'settings' => array('default_value' => ''),
);
$properties['mail'] = array(
'label' => t('e-mail'),
'description' => t("The comment author's e-mail address."),
'type' => 'string_field',
);
$properties['homepage'] = array(
'label' => t('Homepage'),
'description' => t("The comment author's home page address."),
'type' => 'string_field',
);
$properties['hostname'] = array(
'label' => t('Hostname'),
'description' => t("The comment author's hostname."),
'type' => 'string_field',
);
$properties['created'] = array(
'label' => t('Created'),
'description' => t('The time that the comment was created.'),
'type' => 'integer_field',
);
$properties['changed'] = array(
'label' => t('Changed'),
'description' => t('The time that the comment was last edited.'),
'type' => 'integer_field',
);
$properties['status'] = array(
'label' => t('Publishing status'),
'description' => t('A boolean indicating whether the comment is published.'),
'type' => 'boolean_field',
);
$properties['thread'] = array(
'label' => t('Thread place'),
'description' => t("The alphadecimal representation of the comment's place in a thread, consisting of a base 36 string prefixed by an integer indicating its length."),
'type' => 'string_field',
);
$properties['node_type'] = array(
// @todo: The bundle property should be stored so it's queryable.
'label' => t('Node type'),
'description' => t("The comment node type."),
'type' => 'string_field',
'queryable' => FALSE,
);
$properties['new'] = array(
'label' => t('Comment new marker'),
'description' => t("The comment 'new' marker for the current user (0 read, 1 new, 2 updated)."),
'type' => 'integer_field',
'computed' => TRUE,
'class' => '\Drupal\comment\CommentNewItem',
);
return $properties;
}
/**
* {@inheritdoc}
*/
......
......@@ -354,4 +354,109 @@ public function permalink() {
return $url;
}
/**
* {@inheritdoc}
*/
public static function baseFieldDefinitions($entity_type) {
$properties['cid'] = array(
'label' => t('ID'),
'description' => t('The comment ID.'),
'type' => 'integer_field',
'read-only' => TRUE,
);
$properties['uuid'] = array(
'label' => t('UUID'),
'description' => t('The comment UUID.'),
'type' => 'uuid_field',
);
$properties['pid'] = array(
'label' => t('Parent ID'),
'description' => t('The parent comment ID if this is a reply to a comment.'),
'type' => 'entity_reference_field',
'settings' => array('target_type' => 'comment'),
);
$properties['nid'] = array(
'label' => t('Node ID'),
'description' => t('The ID of the node of which this comment is a reply.'),
'type' => 'entity_reference_field',
'settings' => array('target_type' => 'node'),
'required' => TRUE,
);
$properties['langcode'] = array(
'label' => t('Language code'),
'description' => t('The comment language code.'),
'type' => 'language_field',
);
$properties['subject'] = array(
'label' => t('Subject'),
'description' => t('The comment title or subject.'),
'type' => 'string_field',
);
$properties['uid'] = array(
'label' => t('User ID'),
'description' => t('The user ID of the comment author.'),
'type' => 'entity_reference_field',
'settings' => array(
'target_type' => 'user',
'default_value' => 0,
),
);
$properties['name'] = array(
'label' => t('Name'),
'description' => t("The comment author's name."),
'type' => 'string_field',