diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index b7f5a1a9be79c3d34746af0e0a43d412a160f57a..4e8bf52cc7512e922524e4a074d9f26e823e1295 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -1145,6 +1145,9 @@ public function __set($name, $value) { * Implements the magic method for isset(). */ public function __isset($name) { + if ($name == 'original') { + return parent::__isset('original'); + } // "Official" Field API fields are always set. For non-field properties, // check the internal values. return $this->hasField($name) ? TRUE : isset($this->values[$name]); @@ -1154,6 +1157,9 @@ public function __isset($name) { * Implements the magic method for unset(). */ public function __unset($name) { + if ($name == 'original') { + parent::__unset('original'); + } // Unsetting a field means emptying it. if ($this->hasField($name)) { $this->get($name)->setValue([]); diff --git a/core/lib/Drupal/Core/Entity/EntityBase.php b/core/lib/Drupal/Core/Entity/EntityBase.php index 4e57bd926cf94e33751476cf3b9208f73cff99c1..129d3ddbfc9913456dd7d697ad9a3a2d936e028e 100644 --- a/core/lib/Drupal/Core/Entity/EntityBase.php +++ b/core/lib/Drupal/Core/Entity/EntityBase.php @@ -719,4 +719,27 @@ public function __set($name, $value) { $this->$name = $value; } + /** + * {@inheritdoc} + */ + public function __isset($name) { + if ($name == 'original') { + @trigger_error("Checking for the original property is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Use \Drupal\Core\Entity\EntityInterface::getOriginal() instead. See https://www.drupal.org/node/3295826", E_USER_DEPRECATED); + return $this->getOriginal(); + } + return isset($this->$name); + } + + /** + * {@inheritdoc} + */ + public function __unset($name) { + if ($name == 'original') { + @trigger_error("Unsetting the original property is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Use \Drupal\Core\Entity\EntityInterface::setOriginal() instead. See https://www.drupal.org/node/3295826", E_USER_DEPRECATED); + $this->setOriginal(NULL); + return; + } + unset($this->$name); + } + } diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityOriginalDeprecationTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityOriginalDeprecationTest.php index 37dbec81a9b9fb98b20dd979fdb07b4cbb89813d..3160bd752417dfe51ffae8943bb0d5a095c1382b 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityOriginalDeprecationTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityOriginalDeprecationTest.php @@ -29,6 +29,20 @@ public function testOriginalMagicGetSet(): void { $entity->setOriginal(clone $entity); $this->assertInstanceOf(EntityTest::class, $entity->original); + + $this->expectDeprecation('Checking for the original property is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Use \Drupal\Core\Entity\EntityInterface::getOriginal() instead. See https://www.drupal.org/node/3295826'); + $entity = EntityTest::create(['name' => 'original is deprecated']); + $this->assertFalse(isset($entity->original)); + + $entity->setOriginal(clone $entity); + $this->assertTrue(isset($entity->original)); + + $this->expectDeprecation('Unsetting the original property is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Use \Drupal\Core\Entity\EntityInterface::setOriginal() instead. See https://www.drupal.org/node/3295826'); + $entity = EntityTest::create(['name' => 'original is deprecated']); + + $entity->setOriginal(clone $entity); + unset($entity->original); + $this->assertNull($entity->getOriginal()); } }