Commit c58b08ae authored by webchick's avatar webchick
Browse files

Issue #1761040 by sun, tim.plunkett, fago, effulgentsia: Rename Storable,...

Issue #1761040 by sun, tim.plunkett, fago, effulgentsia: Rename Storable, Entity, and Configurable to Entity, ContentEntity, and ConfigEntity.
parent 620eaf7b
......@@ -42,7 +42,7 @@ Configuration system
- Daniel F. Kudwien 'sun' http://drupal.org/user/54136
- Alex Pott 'alexpott' http://drupal.org/user/157725
Configurable entity system
Configuration entity system
- Daniel F. Kudwien 'sun' http://drupal.org/user/54136
- Tim Plunkett 'tim.plunkett' http://drupal.org/user/241634
......
......@@ -7,12 +7,13 @@
namespace Drupal\comment;
use Drupal\entity\ContentEntityInterface;
use Drupal\entity\Entity;
/**
* Defines the comment entity class.
*/
class Comment extends Entity {
class Comment extends Entity implements ContentEntityInterface {
/**
* The comment ID.
......
......@@ -7,7 +7,7 @@
namespace Drupal\comment;
use Drupal\entity\StorableInterface;
use Drupal\entity\EntityInterface;
use Drupal\entity\DatabaseStorageController;
use LogicException;
......@@ -58,7 +58,7 @@ protected function attachLoad(&$comments, $load_revision = FALSE) {
* @see comment_int_to_alphadecimal()
* @see comment_alphadecimal_to_int()
*/
protected function preSave(StorableInterface $comment) {
protected function preSave(EntityInterface $comment) {
global $user;
if (!isset($comment->status)) {
......@@ -151,7 +151,7 @@ protected function preSave(StorableInterface $comment) {
/**
* Overrides Drupal\entity\DatabaseStorageController::postSave().
*/
protected function postSave(StorableInterface $comment, $update) {
protected function postSave(EntityInterface $comment, $update) {
$this->releaseThreadLock();
// Update the {node_comment_statistics} table prior to executing the hook.
$this->updateNodeStatistics($comment->nid);
......
......@@ -31,7 +31,7 @@
* A configuration object containing the old configuration data.
*/
function hook_config_import_create($name, $new_config, $old_config) {
// Only configurable entities require custom handling. Any other module
// Only configuration entities require custom handling. Any other module
// settings can be synchronized directly.
if (strpos($name, 'config_test.dynamic.') !== 0) {
return FALSE;
......@@ -60,7 +60,7 @@ function hook_config_import_create($name, $new_config, $old_config) {
* A configuration object containing the old configuration data.
*/
function hook_config_import_change($name, $new_config, $old_config) {
// Only configurable entities require custom handling. Any other module
// Only configuration entities require custom handling. Any other module
// settings can be synchronized directly.
if (strpos($name, 'config_test.dynamic.') !== 0) {
return FALSE;
......@@ -78,8 +78,8 @@ function hook_config_import_change($name, $new_config, $old_config) {
$config_test->original->$property = $value;
}
// Iterate through each property of the new config, copying it to the
// configurable test object.
// Iterate through each property of the new config, copying it to the test
// object.
foreach ($new_config->get() as $property => $value) {
$config_test->$property = $value;
}
......@@ -107,7 +107,7 @@ function hook_config_import_change($name, $new_config, $old_config) {
* A configuration object containing the old configuration data.
*/
function hook_config_import_delete($name, $new_config, $old_config) {
// Only configurable entities require custom handling. Any other module
// Only configuration entities require custom handling. Any other module
// settings can be synchronized directly.
if (strpos($name, 'config_test.dynamic.') !== 0) {
return FALSE;
......
......@@ -2,23 +2,23 @@
/**
* @file
* Definition of Drupal\config\ConfigurableBase.
* Definition of Drupal\config\ConfigEntityBase.
*/
namespace Drupal\config;
use Drupal\entity\StorableBase;
use Drupal\entity\Entity;
/**
* Defines a base configurable entity class.
* Defines a base configuration entity class.
*/
abstract class ConfigurableBase extends StorableBase implements ConfigurableInterface {
abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface {
/**
* The original ID of the configurable entity.
* The original ID of the configuration entity.
*
* The ID of a configurable entity is a unique string (machine name). When a
* configurable entity is updated and its machine name is renamed, the
* The ID of a configuration entity is a unique string (machine name). When a
* configuration entity is updated and its machine name is renamed, the
* original ID needs to be known.
*
* @var string
......@@ -38,7 +38,7 @@ public function __construct(array $values = array(), $entity_type) {
}
/**
* Implements ConfigurableInterface::getOriginalID().
* Implements ConfigEntityInterface::getOriginalID().
*/
public function getOriginalID() {
return $this->originalID;
......@@ -47,8 +47,8 @@ public function getOriginalID() {
/**
* Overrides Entity::isNew().
*
* EntityInterface::enforceIsNew() is not supported by configurable entities,
* since each Configurable is unique.
* EntityInterface::enforceIsNew() is not supported by configuration entities,
* since each configuration entity is unique.
*/
final public function isNew() {
return !$this->id();
......@@ -57,8 +57,8 @@ final public function isNew() {
/**
* Overrides Entity::bundle().
*
* EntityInterface::bundle() is not supported by configurable entities, since
* a Configurable is a bundle.
* EntityInterface::bundle() is not supported by configuration entities, since
* a configuration entity is a bundle.
*/
final public function bundle() {
return $this->entityType;
......@@ -68,7 +68,7 @@ final public function bundle() {
* Overrides Entity::get().
*
* EntityInterface::get() implements support for fieldable entities, but
* configurable entities are not fieldable.
* configuration entities are not fieldable.
*/
public function get($property_name, $langcode = NULL) {
// @todo: Add support for translatable properties being not fields.
......@@ -79,7 +79,7 @@ public function get($property_name, $langcode = NULL) {
* Overrides Entity::set().
*
* EntityInterface::set() implements support for fieldable entities, but
* configurable entities are not fieldable.
* configuration entities are not fieldable.
*/
public function set($property_name, $value, $langcode = NULL) {
// @todo: Add support for translatable properties being not fields.
......@@ -87,7 +87,7 @@ public function set($property_name, $value, $langcode = NULL) {
}
/**
* Helper callback for uasort() to sort Configurable entities by weight and label.
* Helper callback for uasort() to sort configuration entities by weight and label.
*/
public static function sort($a, $b) {
$a_weight = isset($a->weight) ? $a->weight : 0;
......
......@@ -2,17 +2,17 @@
/**
* @file
* Definition of Drupal\config\ConfigurableInterface.
* Definition of Drupal\config\ConfigEntityInterface.
*/
namespace Drupal\config;
use Drupal\entity\StorableInterface;
use Drupal\entity\EntityInterface;
/**
* Defines the interface common for all configurable entities.
* Defines the interface common for all configuration entities.
*/
interface ConfigurableInterface extends StorableInterface {
interface ConfigEntityInterface extends EntityInterface {
/**
* Returns the original ID.
......
......@@ -8,11 +8,11 @@
namespace Drupal\config;
use Drupal\Component\Uuid\Uuid;
use Drupal\entity\StorableInterface;
use Drupal\entity\EntityInterface;
use Drupal\entity\StorageControllerInterface;
/**
* Defines the storage controller class for configurable entities.
* Defines the storage controller class for configuration entities.
*/
class ConfigStorageController implements StorageControllerInterface {
......@@ -153,7 +153,7 @@ protected function buildQuery($ids, $revision_id = FALSE) {
$config_class = $this->entityInfo['entity class'];
$prefix = $this->entityInfo['config prefix'] . '.';
// Load all of the configurables.
// Load all of the configuration entities.
if ($ids === NULL) {
$names = drupal_container()->get('config.storage')->listAll($prefix);
$result = array();
......@@ -166,7 +166,7 @@ protected function buildQuery($ids, $revision_id = FALSE) {
else {
$result = array();
foreach ($ids as $id) {
// Add the prefix to the ID to serve as the configurable name.
// Add the prefix to the ID to serve as the configuration object name.
$config = config($prefix . $id);
if (!$config->isNew()) {
$result[$id] = new $config_class($config->get(), $this->entityType);
......@@ -254,7 +254,7 @@ public function delete($ids) {
/**
* Implements Drupal\entity\StorageControllerInterface::save().
*/
public function save(StorableInterface $entity) {
public function save(EntityInterface $entity) {
$prefix = $this->entityInfo['config prefix'] . '.';
// Load the stored entity, if any.
......@@ -306,7 +306,7 @@ public function save(StorableInterface $entity) {
*
* Used before the entity is saved and before invoking the presave hook.
*/
protected function preSave(StorableInterface $entity) {
protected function preSave(EntityInterface $entity) {
}
/**
......@@ -319,8 +319,8 @@ protected function preSave(StorableInterface $entity) {
* (bool) TRUE if the entity has been updated, or FALSE if it has been
* inserted.
*/
protected function postSave(StorableInterface $entity, $update) {
// Delete the original configurable entity, in case the entity ID was
protected function postSave(EntityInterface $entity, $update) {
// Delete the original configuration entity, in case the entity ID was
// renamed.
if ($update && !empty($entity->original) && $entity->{$this->idKey} !== $entity->original->{$this->idKey}) {
// @todo This should just delete the original config object without going
......@@ -353,7 +353,7 @@ protected function postDelete($entities) {
* @param $entity
* The entity object.
*/
protected function invokeHook($hook, StorableInterface $entity) {
protected function invokeHook($hook, EntityInterface $entity) {
// Invoke the hook.
module_invoke_all($this->entityType . '_' . $hook, $entity);
// Invoke the respective entity-level hook.
......
......@@ -2,7 +2,7 @@
/**
* @file
* Definition of Drupal\config\Tests\ConfigConfigurableTest.
* Definition of Drupal\config\Tests\ConfigEntityTest.
*/
namespace Drupal\config\Tests;
......@@ -10,9 +10,9 @@
use Drupal\simpletest\WebTestBase;
/**
* Tests configurable entities.
* Tests configuration entities.
*/
class ConfigConfigurableTest extends WebTestBase {
class ConfigEntityTest extends WebTestBase {
/**
* Modules to enable.
......@@ -23,8 +23,8 @@ class ConfigConfigurableTest extends WebTestBase {
public static function getInfo() {
return array(
'name' => 'Configurable entities',
'description' => 'Tests configurable entities.',
'name' => 'Configuration entities',
'description' => 'Tests configuration entities.',
'group' => 'Configuration',
);
}
......@@ -38,7 +38,7 @@ function testCRUD() {
$label2 = $this->randomName();
$label3 = $this->randomName();
// Create a configurable entity.
// Create a configuration entity.
$edit = array(
'id' => $id,
'label' => $label1,
......@@ -47,7 +47,7 @@ function testCRUD() {
$this->assertResponse(200);
$this->assertText($label1);
// Update the configurable entity.
// Update the configuration entity.
$this->assertLinkByHref('admin/structure/config_test/manage/' . $id);
$edit = array(
'label' => $label2,
......@@ -57,14 +57,14 @@ function testCRUD() {
$this->assertNoText($label1);
$this->assertText($label2);
// Delete the configurable entity.
// Delete the configuration entity.
$this->assertLinkByHref('admin/structure/config_test/manage/' . $id . '/delete');
$this->drupalPost('admin/structure/config_test/manage/' . $id . '/delete', array(), 'Delete');
$this->assertResponse(200);
$this->assertNoText($label1);
$this->assertNoText($label2);
// Re-create a configurable entity.
// Re-create a configuration entity.
$edit = array(
'id' => $id,
'label' => $label1,
......@@ -73,7 +73,7 @@ function testCRUD() {
$this->assertResponse(200);
$this->assertText($label1);
// Rename the configurable entity's ID/machine name.
// Rename the configuration entity's ID/machine name.
$this->assertLinkByHref('admin/structure/config_test/manage/' . $id);
$edit = array(
'id' => strtolower($this->randomName()),
......
......@@ -26,12 +26,12 @@ public static function getInfo() {
*/
function testModuleInstallation() {
$default_config = 'config_test.system';
$default_configurable = 'config_test.dynamic.default';
$default_configuration_entity = 'config_test.dynamic.default';
// Verify that default module config does not exist before installation yet.
$config = config($default_config);
$this->assertIdentical($config->isNew(), TRUE);
$config = config($default_configurable);
$config = config($default_configuration_entity);
$this->assertIdentical($config->isNew(), TRUE);
// Install the test module.
......@@ -40,15 +40,15 @@ function testModuleInstallation() {
// Verify that default module config exists.
$config = config($default_config);
$this->assertIdentical($config->isNew(), FALSE);
$config = config($default_configurable);
$config = config($default_configuration_entity);
$this->assertIdentical($config->isNew(), FALSE);
// Verify that configuration import callback was invoked for the dynamic
// configurable entity.
// configuration entity.
$this->assertTrue($GLOBALS['hook_config_import']);
// Verify that config_test API hooks were invoked for the dynamic default
// configurable entity.
// configuration entity.
$this->assertFalse(isset($GLOBALS['hook_config_test']['load']));
$this->assertTrue(isset($GLOBALS['hook_config_test']['presave']));
$this->assertTrue(isset($GLOBALS['hook_config_test']['insert']));
......
......@@ -46,8 +46,8 @@ function config_test_config_import_change($name, $new_config, $old_config) {
$config_test->original->$property = $value;
}
// Iterate through each property of the new config, copying it to the
// configurable test object.
// Iterate through each property of the new config, copying it to the test
// object.
foreach ($new_config->get() as $property => $value) {
$config_test->$property = $value;
}
......@@ -177,7 +177,7 @@ function config_test_delete($id) {
*/
function config_test_list_page() {
$entities = entity_load_multiple('config_test');
uasort($entities, 'Drupal\config\ConfigurableBase::sort');
uasort($entities, 'Drupal\config\ConfigEntityBase::sort');
$rows = array();
foreach ($entities as $config_test) {
......
......@@ -7,29 +7,29 @@
namespace Drupal\config_test;
use Drupal\config\ConfigurableBase;
use Drupal\config\ConfigEntityBase;
/**
* Defines the ConfigTest configurable entity.
* Defines the ConfigTest configuration entity.
*/
class ConfigTest extends ConfigurableBase {
class ConfigTest extends ConfigEntityBase {
/**
* The machine name for the configurable.
* The machine name for the configuration entity.
*
* @var string
*/
public $id;
/**
* The UUID for the configurable.
* The UUID for the configuration entity.
*
* @var string
*/
public $uuid;
/**
* The human-readable name of the configurable.
* The human-readable name of the configuration entity.
*
* @var string
*/
......
<?php
/**
* @file
* Definition of Drupal\entity\ContentEntityInterface.
*/
namespace Drupal\entity;
/**
* Defines a common interface for all content entity objects.
*/
interface ContentEntityInterface extends EntityInterface {
}
......@@ -174,7 +174,7 @@ public function load(array $ids = NULL) {
if (!empty($this->entityInfo['entity class'])) {
// We provide the necessary arguments for PDO to create objects of the
// specified entity class.
// @see Drupal\entity\StorableInterface::__construct()
// @see Drupal\entity\EntityInterface::__construct()
$query_result->setFetchMode(PDO::FETCH_CLASS, $this->entityInfo['entity class'], array(array(), $this->entityType));
}
$queried_entities = $query_result->fetchAllAssoc($this->idKey);
......@@ -457,7 +457,7 @@ public function delete($ids) {
/**
* Implements Drupal\entity\EntityStorageControllerInterface::save().
*/
public function save(StorableInterface $entity) {
public function save(EntityInterface $entity) {
$transaction = db_transaction();
try {
// Load the stored entity, if any.
......@@ -502,7 +502,7 @@ public function save(StorableInterface $entity) {
*
* Used before the entity is saved and before invoking the presave hook.
*/
protected function preSave(StorableInterface $entity) { }
protected function preSave(EntityInterface $entity) { }
/**
* Acts on a saved entity before the insert or update hook is invoked.
......@@ -514,7 +514,7 @@ protected function preSave(StorableInterface $entity) { }
* (bool) TRUE if the entity has been updated, or FALSE if it has been
* inserted.
*/
protected function postSave(StorableInterface $entity, $update) { }
protected function postSave(EntityInterface $entity, $update) { }
/**
* Acts on entities before they are deleted.
......@@ -538,7 +538,7 @@ protected function postDelete($entities) { }
* @param $entity
* The entity object.
*/
protected function invokeHook($hook, StorableInterface $entity) {
protected function invokeHook($hook, EntityInterface $entity) {
if (!empty($this->entityInfo['fieldable']) && function_exists($function = 'field_attach_' . $hook)) {
$function($this->entityType, $entity);
}
......
<
......@@ -17,6 +17,271 @@
* This class can be used as-is by simple entity types. Entity types requiring
* special handling can extend the class.
*/
class Entity extends StorableBase implements EntityInterface {
class Entity implements EntityInterface {
/**
* The language code of the entity's default language.
*
* @var string
*/
public $langcode = LANGUAGE_NOT_SPECIFIED;
/**
* The entity type.
*
* @var string
*/
protected $entityType;
/**
* Boolean indicating whether the entity should be forced to be new.
*
* @var bool
*/
protected $enforceIsNew;
/**
* Indicates whether this is the current revision.
*
* @var bool
*/
public $isCurrentRevision = TRUE;
/**
* Constructs a new entity object.
*/
public function __construct(array $values = array(), $entity_type) {
$this->entityType = $entity_type;
// Set initial values.
foreach ($values as $key => $value) {
$this->$key = $value;
}
}
/**
* Implements EntityInterface::id().
*/
public function id() {
return isset($this->id) ? $this->id : NULL;
}
/**
* Implements EntityInterface::uuid().
*/
public function uuid() {
return isset($this->uuid) ? $this->uuid : NULL;
}
/**
* Implements EntityInterface::isNew().
*/
public function isNew() {
return !empty($this->enforceIsNew) || !$this->id();
}
/**
* Implements EntityInterface::enforceIsNew().
*/
public function enforceIsNew($value = TRUE) {
$this->enforceIsNew = $value;
}
/**
* Implements EntityInterface::entityType().
*/
public function entityType() {
return $this->entityType;
}
/**
* Implements EntityInterface::bundle().
*/
public function bundle() {
return $this->entityType;
}
/**
* Implements EntityInterface::label().
*/
public function label($langcode = NULL) {
$label = NULL;
$entity_info = $this->entityInfo();
if (isset($entity_info['label callback']) && function_exists($entity_info['label callback'])) {
$label = $entity_info['label callback']($this->entityType, $this, $langcode);
}
elseif (!empty($entity_info['entity keys']['label']) && isset($this->{$entity_info['entity keys']['label']})) {
$label = $this->{$entity_info['entity keys']['label']};
}
return $label;
}
/**
* Implements EntityInterface::uri().
*/
public function uri() {
$bundle = $this->bundle();
// A bundle-specific callback takes precedence over the generic one for the
// entity type.
$entity_info = $this->entityInfo();
if (isset($entity_info['bundles'][$bundle]['uri callback'])) {