Issue #2088241 by Xano: ConfigEntityInterface::setOriginalID() should return .

8.0.x
webchick 2013-10-08 21:30:26 -07:00
parent b0408d9daf
commit b8c9f78058
5 changed files with 55 additions and 27 deletions

View File

@ -25,7 +25,7 @@ abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface
*
* @var string
*/
protected $originalID;
protected $originalId;
/**
* The enabled/disabled status of the configuration entity.
@ -44,22 +44,24 @@ abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface
// Configuration entity IDs are strings, and '0' is a valid ID.
$original_id = $this->id();
if ($original_id !== NULL && $original_id !== '') {
$this->setOriginalID($original_id);
$this->setOriginalId($original_id);
}
}
/**
* Implements ConfigEntityInterface::getOriginalID().
* {@inheritdoc}
*/
public function getOriginalID() {
return $this->originalID;
public function getOriginalId() {
return $this->originalId;
}
/**
* Implements ConfigEntityInterface::setOriginalID().
* {@inheritdoc}
*/
public function setOriginalID($id) {
$this->originalID = $id;
public function setOriginalId($id) {
$this->originalId = $id;
return $this;
}
/**
@ -122,7 +124,7 @@ abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface
public function createDuplicate() {
$duplicate = parent::createDuplicate();
// Prevent the new duplicate from being misinterpreted as a rename.
$duplicate->setOriginalID(NULL);
$duplicate->setOriginalId(NULL);
return $duplicate;
}

View File

@ -20,7 +20,7 @@ interface ConfigEntityInterface extends EntityInterface {
* @return string|null
* The original ID, if any.
*/
public function getOriginalID();
public function getOriginalId();
/**
* Sets the original ID.
@ -28,9 +28,9 @@ interface ConfigEntityInterface extends EntityInterface {
* @param string $id
* The new ID to set as original ID.
*
* @return void
* @return self
*/
public function setOriginalID($id);
public function setOriginalId($id);
/**
* Enables the configuration entity.

View File

@ -90,8 +90,8 @@ class CustomBlockType extends ConfigEntityBase implements CustomBlockTypeInterfa
entity_invoke_bundle_hook('create', 'custom_block', $this->id());
custom_block_add_body_field($this->id);
}
elseif ($this->originalID != $this->id) {
entity_invoke_bundle_hook('rename', 'custom_block', $this->originalID, $this->id);
elseif ($this->getOriginalId() != $this->id) {
entity_invoke_bundle_hook('rename', 'custom_block', $this->getOriginalId(), $this->id);
}
}

View File

@ -7,6 +7,7 @@
namespace Drupal\config\Tests;
use Drupal\Core\Entity\EntityInterface;
use Drupal\simpletest\DrupalUnitTestBase;
/**
@ -21,6 +22,13 @@ class ConfigEntityUnitTest extends DrupalUnitTestBase {
*/
public static $modules = array('config_test');
/**
* The config_test entity storage controller.
*
* @var \Drupal\config_test\ConfigTestStorageController
*/
protected $storage;
public static function getInfo() {
return array(
'name' => 'Configuration entity methods',
@ -29,32 +37,40 @@ class ConfigEntityUnitTest extends DrupalUnitTestBase {
);
}
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->storage = $this->container->get('entity.manager')->getStorageController('config_test');
}
/**
* Tests storage controller methods.
*/
public function testStorageControllerMethods() {
$controller = $this->container->get('entity.manager')->getStorageController('config_test');
$info = entity_get_info('config_test');
$expected = $info['config_prefix'] . '.';
$this->assertIdentical($controller->getConfigPrefix(), $expected);
$this->assertIdentical($this->storage->getConfigPrefix(), $expected);
// Test the static extractID() method.
$expected_id = 'test_id';
$config_name = $info['config_prefix'] . '.' . $expected_id;
$this->assertIdentical($controller::getIDFromConfigName($config_name, $info['config_prefix']), $expected_id);
$storage = $this->storage;
$this->assertIdentical($storage::getIDFromConfigName($config_name, $info['config_prefix']), $expected_id);
// Create three entities, two with the same style.
$style = $this->randomName(8);
for ($i = 0; $i < 2; $i++) {
$entity = $controller->create(array(
$entity = $this->storage->create(array(
'id' => $this->randomName(),
'label' => $this->randomString(),
'style' => $style,
));
$entity->save();
}
$entity = $controller->create(array(
$entity = $this->storage->create(array(
'id' => $this->randomName(),
'label' => $this->randomString(),
// Use a different length for the entity to ensure uniqueness.
@ -62,12 +78,22 @@ class ConfigEntityUnitTest extends DrupalUnitTestBase {
));
$entity->save();
$entities = $controller->loadByProperties();
$entities = $this->storage->loadByProperties();
$this->assertEqual(count($entities), 3, 'Three entities are loaded when no properties are specified.');
$entities = $controller->loadByProperties(array('style' => $style));
$entities = $this->storage->loadByProperties(array('style' => $style));
$this->assertEqual(count($entities), 2, 'Two entities are loaded when the style property is specified.');
$this->assertEqual(reset($entities)->get('style'), $style, 'The loaded entities have the style value specified.');
}
/**
* Tests getOriginalId() and setOriginalId().
*/
protected function testGetOriginalId() {
$entity = $this->storage->create(array());
$id = $this->randomName();
$this->assertIdentical(spl_object_hash($entity->setOriginalId($id)), spl_object_hash($entity));
$this->assertIdentical($entity->getOriginalId(), $id);
}
}

View File

@ -920,17 +920,17 @@ class ViewUI implements ViewStorageInterface {
}
/**
* Implements \Drupal\Core\Config\Entity\ConfigEntityInterface::getOriginalID().
* {@inheritdoc}
*/
public function getOriginalID() {
return $this->storage->getOriginalID();
public function getOriginalId() {
return $this->storage->getOriginalId();
}
/**
* Implements \Drupal\Core\Config\Entity\ConfigEntityInterface::setOriginalID().
* {@inheritdoc}
*/
public function setOriginalID($id) {
return $this->storage->setOriginalID($id);
public function setOriginalId($id) {
return $this->storage->setOriginalId($id);
}
/**