diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index 87b43f7..b99e187 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -268,4 +268,32 @@ public function url($rel = 'edit-form', $options = array()) { return parent::url($rel, $options); } + /** + * 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 getExportProperties(). + $keys = array_keys($this->getExportProperties()); + $keys[] = 'entityTypeId'; + return $keys; + } + + /** + * Implements the magic __wakeup() method. + */ + public function __wakeup() { + // PHPUnit uses unserilalize() on a made up string as a trick when bypassing + // the contructor on mock object creation. Make sure we only run on objects + // that have been serialized through our __sleep() method. + if (isset($this->entityTypeId)) { + // Run the values from getExportProperties() through __construct(). + $values = array_intersect_key($this->getExportProperties(), get_object_vars($this)); + $this->__construct($values, $this->entityTypeId); + } + } + } diff --git a/core/modules/entity/lib/Drupal/entity/Entity/EntityFormDisplay.php b/core/modules/entity/lib/Drupal/entity/Entity/EntityFormDisplay.php index 18b8dc5..a46f805 100644 --- a/core/modules/entity/lib/Drupal/entity/Entity/EntityFormDisplay.php +++ b/core/modules/entity/lib/Drupal/entity/Entity/EntityFormDisplay.php @@ -144,23 +144,4 @@ public function getRenderer($field_name) { return $widget; } - /** - * {@inheritdoc} - */ - public function __sleep() { - // Only store the definition, not external objects or derived data. - $keys = array_keys($this->getExportProperties()); - $keys[] = 'entityTypeId'; - return $keys; - } - - /** - * {@inheritdoc} - */ - public function __wakeup() { - // Run the values from getExportProperties() through __construct(). - $values = array_intersect_key($this->getExportProperties(), get_object_vars($this)); - $this->__construct($values, $this->entityTypeId); - } - } diff --git a/core/modules/field/lib/Drupal/field/Entity/FieldConfig.php b/core/modules/field/lib/Drupal/field/Entity/FieldConfig.php index 503fe14..b5cb63a 100644 --- a/core/modules/field/lib/Drupal/field/Entity/FieldConfig.php +++ b/core/modules/field/lib/Drupal/field/Entity/FieldConfig.php @@ -689,27 +689,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 getExportProperties(). - return array_keys(array_intersect_key($this->getExportProperties(), get_object_vars($this))); - } - - /** - * Implements the magic __wakeup() method. - */ - public function __wakeup() { - // Run the values from getExportProperties() through __construct(). - $values = array_intersect_key($this->getExportProperties(), get_object_vars($this)); - $this->__construct($values); - } - - /** * {@inheritdoc} */ public static function createFromDataType($type) { diff --git a/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php b/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php index 6024061..ac6f18d 100644 --- a/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php +++ b/core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php @@ -611,27 +611,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 getExportProperties(). - return array_keys(array_intersect_key($this->getExportProperties(), get_object_vars($this))); - } - - /** - * Implements the magic __wakeup() method. - */ - public function __wakeup() { - // Run the values from getExportProperties() through __construct(). - $values = array_intersect_key($this->getExportProperties(), get_object_vars($this)); - $this->__construct($values); - } - /** * {@inheritdoc} */