Commit b8b13b47 authored by xjm's avatar xjm

Revert "Issue #2854926 by xjm, borisson_, boaloysius: Remove unneeded control...

Revert "Issue #2854926 by xjm, borisson_, boaloysius: Remove unneeded control structures in ContentEntityBase"

This reverts commit ccc65da7.
parent ccc65da7
...@@ -1014,9 +1014,10 @@ public function __isset($name) { ...@@ -1014,9 +1014,10 @@ public function __isset($name) {
if ($this->hasField($name)) { if ($this->hasField($name)) {
return TRUE; return TRUE;
} }
// For non-field properties, check the internal values. // For non-field properties, check the internal values.
return isset($this->values[$name]); else {
return isset($this->values[$name]);
}
} }
/** /**
...@@ -1026,11 +1027,11 @@ public function __unset($name) { ...@@ -1026,11 +1027,11 @@ public function __unset($name) {
// Unsetting a field means emptying it. // Unsetting a field means emptying it.
if ($this->hasField($name)) { if ($this->hasField($name)) {
$this->get($name)->setValue(array()); $this->get($name)->setValue(array());
return TRUE;
} }
// For non-field properties, unset the internal value. // For non-field properties, unset the internal value.
unset($this->values[$name]); else {
unset($this->values[$name]);
}
} }
/** /**
...@@ -1066,62 +1067,60 @@ public function createDuplicate() { ...@@ -1066,62 +1067,60 @@ public function createDuplicate() {
public function __clone() { public function __clone() {
// Avoid deep-cloning when we are initializing a translation object, since // Avoid deep-cloning when we are initializing a translation object, since
// it will represent the same entity, only with a different active language. // it will represent the same entity, only with a different active language.
if ($this->translationInitialize) { if (!$this->translationInitialize) {
return TRUE; // The translation is a different object, and needs its own TypedData
} // adapter object.
$this->typedData = NULL;
// The translation is a different object, and needs its own TypedData $definitions = $this->getFieldDefinitions();
// adapter object.
$this->typedData = NULL; // The translation cache has to be cleared before cloning the fields
$definitions = $this->getFieldDefinitions(); // below so that the call to getTranslation() does not re-use the
// translation objects of the old entity but instead creates new
// The translation cache has to be cleared before cloning the fields // translation objects from the newly cloned entity. Otherwise the newly
// below so that the call to getTranslation() does not re-use the // cloned field item lists would hold references to the old translation
// translation objects of the old entity but instead creates new // objects in their $parent property after the call to setContext().
// translation objects from the newly cloned entity. Otherwise the newly $this->clearTranslationCache();
// cloned field item lists would hold references to the old translation
// objects in their $parent property after the call to setContext(). // Because the new translation objects that are created below are
$this->clearTranslationCache(); // themselves created by *cloning* the newly cloned entity we need to
// make sure that the references to property values are properly cloned
// Because the new translation objects that are created below are // before cloning the fields. Otherwise calling
// themselves created by *cloning* the newly cloned entity we need to // $items->getEntity()->isNew(), for example, would return the
// make sure that the references to property values are properly cloned // $enforceIsNew value of the old entity.
// before cloning the fields. Otherwise calling
// $items->getEntity()->isNew(), for example, would return the // Ensure the translations array is actually cloned by overwriting the
// $enforceIsNew value of the old entity. // original reference with one pointing to a copy of the array.
$translations = $this->translations;
// Ensure the translations array is actually cloned by overwriting the $this->translations = &$translations;
// original reference with one pointing to a copy of the array.
$translations = $this->translations; // Ensure that the following properties are actually cloned by
$this->translations = &$translations; // overwriting the original references with ones pointing to copies of
// them: enforceIsNew, newRevision, loadedRevisionId and fields.
// Ensure that the following properties are actually cloned by $enforce_is_new = $this->enforceIsNew;
// overwriting the original references with ones pointing to copies of $this->enforceIsNew = &$enforce_is_new;
// them: enforceIsNew, newRevision, loadedRevisionId and fields.
$enforce_is_new = $this->enforceIsNew; $new_revision = $this->newRevision;
$this->enforceIsNew = &$enforce_is_new; $this->newRevision = &$new_revision;
$new_revision = $this->newRevision; $original_revision_id = $this->loadedRevisionId;
$this->newRevision = &$new_revision; $this->loadedRevisionId = &$original_revision_id;
$original_revision_id = $this->loadedRevisionId; $fields = $this->fields;
$this->loadedRevisionId = &$original_revision_id; $this->fields = &$fields;
$fields = $this->fields; foreach ($this->fields as $name => $values) {
$this->fields = &$fields; $this->fields[$name] = array();
// Untranslatable fields may have multiple references for the same field
foreach ($this->fields as $name => $values) { // object keyed by language. To avoid creating different field objects
$this->fields[$name] = array(); // we retain just the original value, as references will be recreated
// Untranslatable fields may have multiple references for the same field // later as needed.
// object keyed by language. To avoid creating different field objects if (!$definitions[$name]->isTranslatable() && count($values) > 1) {
// we retain just the original value, as references will be recreated $values = array_intersect_key($values, array(LanguageInterface::LANGCODE_DEFAULT => TRUE));
// later as needed. }
if (!$definitions[$name]->isTranslatable() && count($values) > 1) { foreach ($values as $langcode => $items) {
$values = array_intersect_key($values, array(LanguageInterface::LANGCODE_DEFAULT => TRUE)); $this->fields[$name][$langcode] = clone $items;
} $this->fields[$name][$langcode]->setContext($name, $this->getTranslation($langcode)->getTypedData());
foreach ($values as $langcode => $items) { }
$this->fields[$name][$langcode] = clone $items;
$this->fields[$name][$langcode]->setContext($name, $this->getTranslation($langcode)->getTypedData());
} }
} }
} }
......
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