Commit 91acb77f authored by catch's avatar catch

Issue #2027795 by Berdir, amateescu: Optimize content entity serialization.

parent 18828bde
......@@ -332,15 +332,28 @@ protected function clearTranslationCache() {
}
}
/**
* {@inheritdoc}
*/
public function __sleep() {
// Get the values of instantiated field objects, only serialize the values.
foreach ($this->fields as $name => $fields) {
foreach ($fields as $langcode => $field) {
$this->values[$name][$langcode] = $field->getValue();
}
}
$this->fields = array();
$this->fieldDefinitions = NULL;
$this->clearTranslationCache();
return array_keys(get_object_vars($this));
}
/**
* Magic __wakeup() implementation.
*/
public function __wakeup() {
$this->init();
// @todo This should be done before serializing the entity, but we would
// need to provide the full list of data to be serialized. See the
// dedicated issue at https://drupal.org/node/2027795.
$this->clearTranslationCache();
}
/**
......
......@@ -33,6 +33,20 @@ public function isEmpty() {
return TRUE;
}
/**
* {@inheritdoc}
*/
public function getValue() {
$values = parent::getValue();
// If there is an unsaved entity, return it as part of the field item values
// to ensure idempotency of getValue() / setValue().
if (empty($this->target_id) && !empty($this->entity)) {
$values['entity'] = $this->entity;
}
return $values;
}
/**
* {@inheritdoc}
*/
......
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