diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index 210e259..d2f26f7 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Config\Entity; -use Drupal\Component\Plugin\ConfigurablePluginInterface; use Drupal\Component\Utility\String; use Drupal\Core\Cache\Cache; use Drupal\Core\Config\Schema\SchemaIncompleteException; @@ -23,7 +22,7 @@ * * @ingroup entity_api */ -abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface { +abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface, \Serializable { use PluginDependencyTrait { addDependency as addDependencyTrait; @@ -372,4 +371,21 @@ public function getConfigDependencyName() { return $this->getEntityType()->getConfigPrefix() . '.' . $this->id(); } + /** + * {@inheritdoc} + */ + public function serialize() { + $values = $this->toArray(); + $values['entityTypeID'] = $this->getEntityTypeId(); + return serialize($values); + } + + /** + * {@inheritdoc} + */ + public function unserialize($serialized) { + $values = unserialize($serialized); + return $this->__construct($values, $values['entityTypeID']); + } + } diff --git a/core/modules/entity/src/Entity/EntityFormDisplay.php b/core/modules/entity/src/Entity/EntityFormDisplay.php index 6457e23..3e88d0a 100644 --- a/core/modules/entity/src/Entity/EntityFormDisplay.php +++ b/core/modules/entity/src/Entity/EntityFormDisplay.php @@ -225,23 +225,4 @@ public function validateFormValues(ContentEntityInterface $entity, array &$form, } } - /** - * {@inheritdoc} - */ - public function __sleep() { - // Only store the definition, not external objects or derived data. - $keys = array_keys($this->toArray()); - $keys[] = 'entityTypeId'; - return $keys; - } - - /** - * {@inheritdoc} - */ - public function __wakeup() { - // Run the values from self::toArray() through __construct(). - $values = array_intersect_key($this->toArray(), get_object_vars($this)); - $this->__construct($values, $this->entityTypeId); - } - } diff --git a/core/modules/field/src/Entity/FieldInstanceConfig.php b/core/modules/field/src/Entity/FieldInstanceConfig.php index 8ce7afa..bfd9806 100644 --- a/core/modules/field/src/Entity/FieldInstanceConfig.php +++ b/core/modules/field/src/Entity/FieldInstanceConfig.php @@ -617,30 +617,6 @@ public function targetBundle() { return $this->bundle; } - /* - * Implements the magic __sleep() method. - * - * Using the Serialize interface and serialize() / unserialize() methods - * breaks entity forms in PHP 5.4. - * @todo Investigate in https://drupal.org/node/2074253. - */ - public function __sleep() { - // Only serialize properties from self::toArray(). - $properties = array_keys(array_intersect_key($this->toArray(), get_object_vars($this))); - // Serialize $entityTypeId property so that toArray() works when waking up. - $properties[] = 'entityTypeId'; - return $properties; - } - - /** - * Implements the magic __wakeup() method. - */ - public function __wakeup() { - // Run the values from self::toArray() through __construct(). - $values = array_intersect_key($this->toArray(), get_object_vars($this)); - $this->__construct($values); - } - /** * {@inheritdoc} */ diff --git a/core/modules/field/src/Entity/FieldStorageConfig.php b/core/modules/field/src/Entity/FieldStorageConfig.php index dcae40b..0133b1b 100644 --- a/core/modules/field/src/Entity/FieldStorageConfig.php +++ b/core/modules/field/src/Entity/FieldStorageConfig.php @@ -635,30 +635,6 @@ public function hasData() { } /** - * Implements the magic __sleep() method. - * - * Using the Serialize interface and serialize() / unserialize() methods - * breaks entity forms in PHP 5.4. - * @todo Investigate in https://drupal.org/node/2074253. - */ - public function __sleep() { - // Only serialize properties from self::toArray(). - $properties = array_keys(array_intersect_key($this->toArray(), get_object_vars($this))); - // Serialize $entityTypeId property so that toArray() works when waking up. - $properties[] = 'entityTypeId'; - return $properties; - } - - /** - * Implements the magic __wakeup() method. - */ - public function __wakeup() { - // Run the values from self::toArray() through __construct(). - $values = array_intersect_key($this->toArray(), get_object_vars($this)); - $this->__construct($values); - } - - /** * {@inheritdoc} */ public function getConstraints() { diff --git a/core/modules/tour/tests/src/Entity/TourTest.php b/core/modules/tour/tests/src/Entity/TourTest.php index 7b5f943..adb45ad 100644 --- a/core/modules/tour/tests/src/Entity/TourTest.php +++ b/core/modules/tour/tests/src/Entity/TourTest.php @@ -31,8 +31,17 @@ class TourTest extends UnitTestCase { * @dataProvider routeProvider */ public function testHasMatchingRoute($routes, $route_name, $route_params, $result) { - $tour = $this->getMockBuilder('\Drupal\tour\Entity\Tour') + // Tour::__construct() pulls the plugin.manager.tour.tip service from the + // container. Mock it and and place it there. + $tip_manager = $this->getMockBuilder('Drupal\tour\TipPluginManager') ->disableOriginalConstructor() + ->getMock(); + $container = new ContainerBuilder(); + $container->set('plugin.manager.tour.tip', $tip_manager); + \Drupal::setContainer($container); + + $tour = $this->getMockBuilder('\Drupal\tour\Entity\Tour') + ->setConstructorArgs(array(array(), 'tour')) ->setMethods(array('getRoutes')) ->getMock();