Issue #2004336 by damiankloip: Default UUID key in ConfigEntityType.

8.0.x
Alex Pott 2014-03-08 10:58:15 +00:00
parent 7abce708dc
commit 0f35ae9f75
30 changed files with 13 additions and 195 deletions

View File

@ -241,11 +241,7 @@ function entity_revision_delete($entity_type, $revision_id) {
function entity_load_by_uuid($entity_type_id, $uuid, $reset = FALSE) {
$entity_type = \Drupal::entityManager()->getDefinition($entity_type_id);
// Configuration entities do not use annotations to set the UUID key.
if ($entity_type->isSubclassOf('Drupal\Core\Config\Entity\ConfigEntityInterface')) {
$uuid_key = 'uuid';
}
elseif (!$uuid_key = $entity_type->getKey('uuid')) {
if (!$uuid_key = $entity_type->getKey('uuid')) {
throw new EntityStorageException("Entity type $entity_type_id does not support UUIDs.");
}

View File

@ -174,11 +174,7 @@ abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface
* {@inheritdoc}
*/
public function createDuplicate() {
$duplicate = clone $this;
$duplicate->set($this->getEntityType()->getKey('id'), NULL);
// @todo Inject the UUID service into the Entity class once possible.
$duplicate->set('uuid', \Drupal::service('uuid')->generate());
$duplicate = parent::createDuplicate();
// Prevent the new duplicate from being misinterpreted as a rename.
$duplicate->setOriginalId(NULL);

View File

@ -48,6 +48,15 @@ class ConfigEntityType extends EntityType {
return $this->provider . '.' . $config_prefix;
}
/**
* {@inheritdoc}
*/
public function getKeys() {
// Always add a default 'uuid' key.
return array('uuid' => 'uuid') + parent::getKeys();
}
/**
* {@inheritdoc}
*/

View File

@ -48,13 +48,6 @@ class CustomBlockType extends ConfigEntityBase implements CustomBlockTypeInterfa
*/
public $id;
/**
* The custom block type UUID.
*
* @var string
*/
public $uuid;
/**
* The custom block type label.
*

View File

@ -48,13 +48,6 @@ class Block extends ConfigEntityBase implements BlockInterface, EntityWithPlugin
*/
public $id;
/**
* The block UUID.
*
* @var string
*/
public $uuid;
/**
* The plugin instance settings.
*

View File

@ -51,13 +51,6 @@ class Breakpoint extends ConfigEntityBase implements BreakpointInterface {
*/
public $id;
/**
* The breakpoint UUID.
*
* @var string
*/
public $uuid;
/**
* The breakpoint name (machine name) as specified by theme or module.
*

View File

@ -33,13 +33,6 @@ class BreakpointGroup extends ConfigEntityBase implements BreakpointGroupInterfa
*/
public $id;
/**
* The breakpoint group UUID.
*
* @var string
*/
public $uuid;
/**
* The breakpoint group machine name.
*

View File

@ -52,11 +52,11 @@ class ConfigImportUITest extends WebTestBase {
// Create new config entity.
$original_dynamic_data = array(
'id' => 'new',
'uuid' => '30df59bd-7b03-4cf7-bb35-d42fc49f0651',
'label' => 'New',
'weight' => 0,
'style' => '',
'status' => TRUE,
'uuid' => '30df59bd-7b03-4cf7-bb35-d42fc49f0651',
'langcode' => language_default()->id,
'protected_property' => '',
);

View File

@ -163,11 +163,11 @@ class ConfigImporterTest extends DrupalUnitTestBase {
// Create new config entity.
$original_dynamic_data = array(
'id' => 'new',
'uuid' => '30df59bd-7b03-4cf7-bb35-d42fc49f0651',
'label' => 'New',
'weight' => 0,
'style' => '',
'status' => TRUE,
'uuid' => '30df59bd-7b03-4cf7-bb35-d42fc49f0651',
'langcode' => language_default()->id,
'protected_property' => '',
);

View File

@ -48,13 +48,6 @@ class ConfigTest extends ConfigEntityBase implements ConfigTestInterface {
*/
public $id;
/**
* The UUID for the configuration entity.
*
* @var string
*/
public $uuid;
/**
* The human-readable name of the configuration entity.
*

View File

@ -48,13 +48,6 @@ class Category extends ConfigEntityBase implements CategoryInterface {
*/
public $id;
/**
* The category UUID.
*
* @var string
*/
public $uuid;
/**
* The category label.
*

View File

@ -24,13 +24,6 @@ abstract class EntityDisplayBase extends ConfigEntityBase implements EntityDispl
*/
public $id;
/**
* Unique UUID for the config entity.
*
* @var string
*/
public $uuid;
/**
* Entity type to be displayed.
*

View File

@ -21,13 +21,6 @@ abstract class EntityDisplayModeBase extends ConfigEntityBase implements EntityD
*/
public $id;
/**
* The UUID of the form or view mode.
*
* @var string
*/
public $uuid;
/**
* The human-readable name of the form or view mode.
*

View File

@ -65,15 +65,6 @@ class FieldConfig extends ConfigEntityBase implements FieldConfigInterface {
*/
public $name;
/**
* The field UUID.
*
* This is assigned automatically when the field is created.
*
* @var string
*/
public $uuid;
/**
* The name of the entity type the field can be attached to.
*

View File

@ -44,15 +44,6 @@ class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceConfi
*/
public $id;
/**
* The instance UUID.
*
* This is assigned automatically when the instance is created.
*
* @var string
*/
public $uuid;
/**
* The name of the field attached to the bundle by this instance.
*

View File

@ -68,13 +68,6 @@ class FilterFormat extends ConfigEntityBase implements FilterFormatInterface, En
*/
public $name;
/**
* The UUID for this entity.
*
* @var string
*/
public $uuid;
/**
* Weight of this format in the text format selector.
*

View File

@ -68,13 +68,6 @@ class ImageStyle extends ConfigEntityBase implements ImageStyleInterface, Entity
*/
public $label;
/**
* The UUID for this entity.
*
* @var string
*/
public $uuid;
/**
* The array of image effects for this image style.
*

View File

@ -49,15 +49,6 @@ class Language extends ConfigEntityBase implements LanguageInterface {
*/
public $id;
/**
* The language UUID.
*
* This is assigned automatically when the language is created.
*
* @var string
*/
public $uuid;
/**
* The human-readable label for the language.
*

View File

@ -45,15 +45,6 @@ class Migration extends ConfigEntityBase implements MigrationInterface {
*/
public $id;
/**
* The migration UUID.
*
* This is assigned automatically when the migration is created.
*
* @var string
*/
public $uuid;
/**
* The human-readable label for the migration.
*

View File

@ -53,13 +53,6 @@ class NodeType extends ConfigEntityBase implements NodeTypeInterface {
*/
public $type;
/**
* The UUID of the node type.
*
* @var string
*/
public $uuid;
/**
* The human-readable name of the node type.
*

View File

@ -47,13 +47,6 @@ class PictureMapping extends ConfigEntityBase implements PictureMappingInterface
*/
public $id;
/**
* The picture UUID.
*
* @var string
*/
public $uuid;
/**
* The picture label.
*

View File

@ -32,13 +32,6 @@ class RdfMapping extends ConfigEntityBase implements RdfMappingInterface {
*/
public $id;
/**
* UUID for the config entity.
*
* @var string
*/
public $uuid;
/**
* Entity type to be mapped.
*

View File

@ -65,13 +65,6 @@ class SearchPage extends ConfigEntityBase implements SearchPageInterface, Entity
*/
public $label;
/**
* The UUID of the search page entity.
*
* @var string
*/
public $uuid;
/**
* The configuration of the search page entity.
*

View File

@ -51,13 +51,6 @@ class ShortcutSet extends ConfigEntityBase implements ShortcutSetInterface {
*/
public $id;
/**
* The UUID for the configuration entity.
*
* @var string
*/
public $uuid;
/**
* The human-readable name of the configuration entity.
*

View File

@ -42,13 +42,6 @@ class Action extends ConfigEntityBase implements ActionConfigEntityInterface, En
*/
public $label;
/**
* The UUID of the action.
*
* @var string
*/
public $uuid;
/**
* The action type.
*

View File

@ -47,13 +47,6 @@ class DateFormat extends ConfigEntityBase implements DateFormatInterface {
*/
public $id;
/**
* The date format UUID.
*
* @var string
*/
public $uuid;
/**
* The human-readable name of the date format entity.
*

View File

@ -37,13 +37,6 @@ class Menu extends ConfigEntityBase implements MenuInterface {
*/
public $id;
/**
* The menu UUID.
*
* @var string
*/
public $uuid;
/**
* The human-readable name of the menu entity.
*

View File

@ -53,13 +53,6 @@ class Vocabulary extends ConfigEntityBase implements VocabularyInterface {
*/
public $vid;
/**
* The vocabulary UUID.
*
* @var string
*/
public $uuid;
/**
* Name of the vocabulary.
*

View File

@ -50,13 +50,6 @@ class Role extends ConfigEntityBase implements RoleInterface {
*/
public $id;
/**
* The UUID of this role.
*
* @var string
*/
public $uuid;
/**
* The human-readable label of this role.
*

View File

@ -95,13 +95,6 @@ class View extends ConfigEntityBase implements ViewStorageInterface {
*/
protected $base_field = 'nid';
/**
* The UUID for this entity.
*
* @var string
*/
public $uuid = NULL;
/**
* Stores a reference to the executable version of this view.
*