Commit 8671e6c1 authored by webchick's avatar webchick

Issue #2071969 by yched: Fixed Serialize interface not reliable.

parent bc58322a
......@@ -710,21 +710,6 @@ public function offsetUnset($offset) {
}
}
/**
* {@inheritdoc}
*/
public function serialize() {
// Only store the definition, not external objects or derived data.
return serialize($this->getExportProperties());
}
/**
* {@inheritdoc}
*/
public function unserialize($serialized) {
$this->__construct(unserialize($serialized));
}
/**
* A list of columns that can not be used as field type columns.
*
......@@ -768,4 +753,26 @@ public function hasData() {
return FALSE;
}
/**
* 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);
}
}
......@@ -314,7 +314,9 @@ public function getExportProperties() {
// Additionally, include the field type, that is needed to be able to
// generate the field-type-dependant parts of the config schema.
$properties['field_type'] = $this->field->type;
if (isset($this->field->type)) {
$properties['field_type'] = $this->field->type;
}
return $properties;
}
......@@ -644,18 +646,24 @@ public function offsetUnset($offset) {
}
/**
* {@inheritdoc}
* 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 serialize() {
// Only store the definition, not external objects or derived data.
return serialize($this->getExportProperties());
public function __sleep() {
// Only serialize properties from getExportProperties().
return array_keys(array_intersect_key($this->getExportProperties(), get_object_vars($this)));
}
/**
* {@inheritdoc}
* Implements the magic __wakeup() method.
*/
public function unserialize($serialized) {
$this->__construct(unserialize($serialized));
public function __wakeup() {
// Run the values from getExportProperties() through __construct().
$values = array_intersect_key($this->getExportProperties(), get_object_vars($this));
$this->__construct($values);
}
}
......@@ -13,7 +13,7 @@
/**
* Provides an interface defining a field instance entity.
*/
interface FieldInstanceInterface extends ConfigEntityInterface, FieldDefinitionInterface, \ArrayAccess, \Serializable {
interface FieldInstanceInterface extends ConfigEntityInterface, FieldDefinitionInterface, \ArrayAccess {
/**
* Returns the field entity for this instance.
......
......@@ -13,7 +13,7 @@
/**
* Provides an interface defining a field entity.
*/
interface FieldInterface extends ConfigEntityInterface, FieldDefinitionInterface, \ArrayAccess, \Serializable {
interface FieldInterface extends ConfigEntityInterface, FieldDefinitionInterface, \ArrayAccess {
/**
* Returns the field schema.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment