From f8673ac410db0cedd8c49f0cbc7c99c0a35ec3b7 Mon Sep 17 00:00:00 2001 From: Dries Date: Tue, 16 Oct 2012 14:23:44 -0400 Subject: [PATCH] Issue #1813832 by andypost: Fixed Allow use '0' as id for entity. --- core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php | 3 ++- core/lib/Drupal/Core/Entity/Entity.php | 3 ++- .../config/lib/Drupal/config/Tests/ConfigEntityTest.php | 5 ++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index 77ffa8cfb1f7..1258395455c8 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -51,7 +51,8 @@ abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface * since each configuration entity is unique. */ final public function isNew() { - return !$this->id(); + $id = $this->id(); + return !isset($id); } /** diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index 8f462de71540..7f5ae872cb4e 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -91,7 +91,8 @@ class Entity implements IteratorAggregate, EntityInterface { * Implements EntityInterface::isNew(). */ public function isNew() { - return !empty($this->enforceIsNew) || !$this->id(); + $id = $this->id(); + return !empty($this->enforceIsNew) || !isset($id); } /** diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php index 532979c3110b..494f5e0e5fc1 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php @@ -78,13 +78,16 @@ class ConfigEntityTest extends WebTestBase { // Rename the configuration entity's ID/machine name. $this->assertLinkByHref('admin/structure/config_test/manage/' . $id); $edit = array( - 'id' => strtolower($this->randomName()), + 'id' => '0', 'label' => $label3, ); $this->drupalPost('admin/structure/config_test/manage/' . $id, $edit, 'Save'); $this->assertResponse(200); $this->assertNoText($label1); $this->assertText($label3); + $this->drupalPost('admin/structure/config_test/manage/0/delete', array(), 'Delete'); + $this->assertResponse(200); + $this->assertNoText($label3); } }