diff --git a/core/modules/entity/lib/Drupal/entity/Entity.php b/core/modules/entity/lib/Drupal/entity/Entity.php index 7e7302466be..151146a6842 100644 --- a/core/modules/entity/lib/Drupal/entity/Entity.php +++ b/core/modules/entity/lib/Drupal/entity/Entity.php @@ -65,6 +65,13 @@ class Entity implements EntityInterface { return isset($this->id) ? $this->id : NULL; } + /** + * Implements EntityInterface::uuid(). + */ + public function uuid() { + return isset($this->uuid) ? $this->uuid : NULL; + } + /** * Implements EntityInterface::isNew(). */ diff --git a/core/modules/entity/lib/Drupal/entity/EntityInterface.php b/core/modules/entity/lib/Drupal/entity/EntityInterface.php index 7aedb48a60d..ef95cc274eb 100644 --- a/core/modules/entity/lib/Drupal/entity/EntityInterface.php +++ b/core/modules/entity/lib/Drupal/entity/EntityInterface.php @@ -32,6 +32,17 @@ interface EntityInterface { */ public function id(); + /** + * Returns the entity UUID (Universally Unique Identifier). + * + * The UUID is guaranteed to be unique and can be used to identify an entity + * across multiple systems. + * + * @return string + * The UUID of the entity, or NULL if the entity does not have one. + */ + public function uuid(); + /** * Returns whether the entity is new. * diff --git a/core/modules/entity/lib/Drupal/entity/Tests/EntityUUIDTest.php b/core/modules/entity/lib/Drupal/entity/Tests/EntityUUIDTest.php index 75333b4a77a..e7607dc0986 100644 --- a/core/modules/entity/lib/Drupal/entity/Tests/EntityUUIDTest.php +++ b/core/modules/entity/lib/Drupal/entity/Tests/EntityUUIDTest.php @@ -41,35 +41,35 @@ class EntityUUIDTest extends WebTestBase { 'name' => $this->randomName(), 'uuid' => $uuid, )); - $this->assertIdentical($custom_entity->get('uuid'), $uuid); + $this->assertIdentical($custom_entity->uuid(), $uuid); // Save this entity, so we have more than one later. $custom_entity->save(); // Verify that a new UUID is generated upon creating an entity. $entity = entity_create('entity_test', array('name' => $this->randomName())); - $uuid = $entity->get('uuid'); + $uuid = $entity->uuid(); $this->assertTrue($uuid); // Verify that the new UUID is different. - $this->assertNotEqual($custom_entity->get('uuid'), $uuid); + $this->assertNotEqual($custom_entity->uuid(), $uuid); // Verify that the UUID is retained upon saving. $entity->save(); - $this->assertIdentical($entity->get('uuid'), $uuid); + $this->assertIdentical($entity->uuid(), $uuid); // Verify that the UUID is retained upon loading. $entity_loaded = entity_test_load($entity->id(), TRUE); - $this->assertIdentical($entity_loaded->get('uuid'), $uuid); + $this->assertIdentical($entity_loaded->uuid(), $uuid); // Verify that entity_load_by_uuid() loads the same entity. $entity_loaded_by_uuid = entity_load_by_uuid('entity_test', $uuid, TRUE); - $this->assertIdentical($entity_loaded_by_uuid->get('uuid'), $uuid); + $this->assertIdentical($entity_loaded_by_uuid->uuid(), $uuid); $this->assertEqual($entity_loaded_by_uuid, $entity_loaded); // Creating a duplicate needs to result in a new UUID. $entity_duplicate = $entity->createDuplicate(); - $this->assertNotEqual($entity_duplicate->get('uuid'), $entity->get('uuid')); - $this->assertNotNull($entity_duplicate->get('uuid')); + $this->assertNotEqual($entity_duplicate->uuid(), $entity->uuid()); + $this->assertNotNull($entity_duplicate->uuid()); $entity_duplicate->save(); $this->assertNotEqual($entity->id(), $entity_duplicate->id()); }