From 453b2517f5c708e565f9d9c0005a3c97c3809999 Mon Sep 17 00:00:00 2001 From: webchick Date: Tue, 23 Oct 2012 19:56:52 -0700 Subject: [PATCH] Issue #1813832 by andypost, xjm, sun: Fixed Entity wrongly checks existence of ID in isNew() method. --- .../Drupal/Core/Config/Entity/ConfigEntityBase.php | 2 +- core/lib/Drupal/Core/Entity/Entity.php | 2 +- .../lib/Drupal/config/Tests/ConfigEntityTest.php | 13 +++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index 77ffa8cfb1f..a53007a31b4 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -51,7 +51,7 @@ abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface * since each configuration entity is unique. */ final public function isNew() { - return !$this->id(); + return $this->id() === NULL; } /** diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index 8f462de7154..7f58bdf31a1 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -91,7 +91,7 @@ class Entity implements IteratorAggregate, EntityInterface { * Implements EntityInterface::isNew(). */ public function isNew() { - return !empty($this->enforceIsNew) || !$this->id(); + return !empty($this->enforceIsNew) || $this->id() === NULL; } /** diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php index 532979c3110..45a16b92cfa 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php @@ -85,6 +85,19 @@ class ConfigEntityTest extends WebTestBase { $this->assertResponse(200); $this->assertNoText($label1); $this->assertText($label3); + + // Create a configuration entity with '0' machine name. + $edit = array( + 'id' => '0', + 'label' => '0', + ); + $this->drupalPost('admin/structure/config_test/add', $edit, 'Save'); + $this->assertResponse(200); + $message_insert = format_string('%label configuration has been created.', array('%label' => $edit['id'])); + $this->assertRaw($message_insert); + + $this->drupalPost('admin/structure/config_test/manage/0/delete', array(), 'Delete'); + $this->assertFalse(entity_load('config_test', '0'), 'Test entity deleted'); } }