From 57d257481eff8f4b7aa9f31eba1231e80e66469f Mon Sep 17 00:00:00 2001 From: Florian Weber Date: Fri, 15 Jun 2012 11:48:22 +0200 Subject: [PATCH] Issue #1615240: Remove entity_label() in favor of EntityInterface::label(). --- core/modules/entity/entity.module | 27 ++++++-------------- core/modules/entity/lib/Drupal/entity/Entity.php | 2 -- .../Drupal/field/Tests/EntityPropertiesTest.php | 2 +- .../tests/modules/field_test/field_test.entity.inc | 3 +++ .../Drupal/user/Tests/UserEntityCallbacksTest.php | 6 ++--- 5 files changed, 15 insertions(+), 25 deletions(-) diff --git a/core/modules/entity/entity.module b/core/modules/entity/entity.module index daaa9f6..d15b57d 100644 --- a/core/modules/entity/entity.module +++ b/core/modules/entity/entity.module @@ -6,6 +6,7 @@ */ use Drupal\entity\EntityMalformedException; +use Drupal\entity\EntityInterface; /** * Implements hook_help(). @@ -414,31 +415,19 @@ function entity_uri($entity_type, $entity) { /** * Returns the label of an entity. * - * See the 'label callback' component of the hook_entity_info() return value - * for more information. + * This is a wrapper for EntityInterface::label(). This function should only + * be used as a callback, e.g. for menu title callbacks. * - * @param $entity_type - * The entity type; e.g., 'node' or 'user'. - * @param $entity + * @param Drupal\entity\EntityInterface $entity * The entity for which to generate the label. * * @return - * The entity label, or FALSE if not found. + * The label of the entity, or NULL if there is no label defined. * - * @todo - * Remove once all entity types are implementing the EntityInterface. + * @see EntityInterface::label() */ -function entity_label($entity_type, $entity) { - $label = FALSE; - $info = entity_get_info($entity_type); - if (isset($info['label callback'])) { - $label = $info['label callback']($entity_type, $entity); - } - elseif (!empty($info['entity keys']['label']) && isset($entity->{$info['entity keys']['label']})) { - $label = $entity->{$info['entity keys']['label']}; - } - - return $label; +function entity_page_label(EntityInterface $entity) { + return $entity->label(); } /** diff --git a/core/modules/entity/lib/Drupal/entity/Entity.php b/core/modules/entity/lib/Drupal/entity/Entity.php index f0f5a76..3fa0ead 100644 --- a/core/modules/entity/lib/Drupal/entity/Entity.php +++ b/core/modules/entity/lib/Drupal/entity/Entity.php @@ -86,8 +86,6 @@ class Entity implements EntityInterface { /** * Implements EntityInterface::label(). - * - * @see entity_label() */ public function label() { $label = FALSE; diff --git a/core/modules/field/lib/Drupal/field/Tests/EntityPropertiesTest.php b/core/modules/field/lib/Drupal/field/Tests/EntityPropertiesTest.php index 00a4430..7a2712f 100644 --- a/core/modules/field/lib/Drupal/field/Tests/EntityPropertiesTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/EntityPropertiesTest.php @@ -36,7 +36,7 @@ class EntityPropertiesTest extends FieldTestBase { $entity = field_test_create_stub_entity(); foreach ($entity_types as $entity_type) { - $label = entity_label($entity_type, $entity); + $label = entity_create($entity_type, (array) $entity)->label(); switch ($entity_type) { case 'test_entity_no_label': diff --git a/core/modules/field/tests/modules/field_test/field_test.entity.inc b/core/modules/field/tests/modules/field_test/field_test.entity.inc index 9185b85..31d20f1 100644 --- a/core/modules/field/tests/modules/field_test/field_test.entity.inc +++ b/core/modules/field/tests/modules/field_test/field_test.entity.inc @@ -81,6 +81,7 @@ function field_test_entity_info() { 'fieldable' => TRUE, 'field cache' => FALSE, 'base table' => 'test_entity', + 'revision table' => 'test_entity_revision', 'entity keys' => array( 'id' => 'ftid', 'revision' => 'ftvid', @@ -94,6 +95,7 @@ function field_test_entity_info() { 'fieldable' => TRUE, 'field cache' => FALSE, 'base table' => 'test_entity', + 'revision table' => 'test_entity_revision', 'entity keys' => array( 'id' => 'ftid', 'revision' => 'ftvid', @@ -108,6 +110,7 @@ function field_test_entity_info() { 'fieldable' => TRUE, 'field cache' => FALSE, 'base table' => 'test_entity', + 'revision table' => 'test_entity_revision', 'label callback' => 'field_test_entity_label_callback', 'entity keys' => array( 'id' => 'ftid', diff --git a/core/modules/user/lib/Drupal/user/Tests/UserEntityCallbacksTest.php b/core/modules/user/lib/Drupal/user/Tests/UserEntityCallbacksTest.php index a8fd35b..dc85ade 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserEntityCallbacksTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserEntityCallbacksTest.php @@ -25,19 +25,19 @@ class UserEntityCallbacksTest extends WebTestBase { parent::setUp('user'); $this->account = $this->drupalCreateUser(); - $this->anonymous = drupal_anonymous_user(); + $this->anonymous = entity_create('user', (array) drupal_anonymous_user()); } /** * Test label callback. */ function testLabelCallback() { - $this->assertEqual(entity_label('user', $this->account), $this->account->name, t('The username should be used as label')); + $this->assertEqual($this->account->label(), $this->account->name, t('The username should be used as label')); // Setup a random anonymous name to be sure the name is used. $name = $this->randomName(); variable_set('anonymous', $name); - $this->assertEqual(entity_label('user', $this->anonymous), $name, t('The variable anonymous should be used for name of uid 0')); + $this->assertEqual($this->anonymous->label(), $name, t('The variable anonymous should be used for name of uid 0')); } /** -- 1.7.10.3