Skip to content
Snippets Groups Projects
Commit 59b45093 authored by Jess's avatar Jess
Browse files

Issue #2854926 by xjm, himanshu-dixit, borisson_, boaloysius, alexpott: Remove...

Issue #2854926 by xjm, himanshu-dixit, borisson_, boaloysius, alexpott: Remove unneeded control structures in ContentEntityBase
parent c4c65216
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -1010,14 +1010,9 @@ public function __set($name, $value) {
* Implements the magic method for isset().
*/
public function __isset($name) {
// "Official" Field API fields are always set.
if ($this->hasField($name)) {
return TRUE;
}
// For non-field properties, check the internal values.
else {
return isset($this->values[$name]);
}
// "Official" Field API fields are always set. For non-field properties,
// check the internal values.
return $this->hasField($name) ? TRUE : isset($this->values[$name]);
}
/**
......@@ -1067,60 +1062,62 @@ public function createDuplicate() {
public function __clone() {
// Avoid deep-cloning when we are initializing a translation object, since
// it will represent the same entity, only with a different active language.
if (!$this->translationInitialize) {
// The translation is a different object, and needs its own TypedData
// adapter object.
$this->typedData = NULL;
$definitions = $this->getFieldDefinitions();
// The translation cache has to be cleared before cloning the fields
// below so that the call to getTranslation() does not re-use the
// translation objects of the old entity but instead creates new
// translation objects from the newly cloned entity. Otherwise the newly
// cloned field item lists would hold references to the old translation
// objects in their $parent property after the call to setContext().
$this->clearTranslationCache();
// Because the new translation objects that are created below are
// themselves created by *cloning* the newly cloned entity we need to
// make sure that the references to property values are properly cloned
// before cloning the fields. Otherwise calling
// $items->getEntity()->isNew(), for example, would return the
// $enforceIsNew value of the old entity.
// Ensure the translations array is actually cloned by overwriting the
// original reference with one pointing to a copy of the array.
$translations = $this->translations;
$this->translations = &$translations;
// Ensure that the following properties are actually cloned by
// overwriting the original references with ones pointing to copies of
// them: enforceIsNew, newRevision, loadedRevisionId and fields.
$enforce_is_new = $this->enforceIsNew;
$this->enforceIsNew = &$enforce_is_new;
$new_revision = $this->newRevision;
$this->newRevision = &$new_revision;
$original_revision_id = $this->loadedRevisionId;
$this->loadedRevisionId = &$original_revision_id;
$fields = $this->fields;
$this->fields = &$fields;
foreach ($this->fields as $name => $values) {
$this->fields[$name] = array();
// Untranslatable fields may have multiple references for the same field
// object keyed by language. To avoid creating different field objects
// we retain just the original value, as references will be recreated
// later as needed.
if (!$definitions[$name]->isTranslatable() && count($values) > 1) {
$values = array_intersect_key($values, array(LanguageInterface::LANGCODE_DEFAULT => TRUE));
}
foreach ($values as $langcode => $items) {
$this->fields[$name][$langcode] = clone $items;
$this->fields[$name][$langcode]->setContext($name, $this->getTranslation($langcode)->getTypedData());
}
if ($this->translationInitialize) {
return;
}
// The translation is a different object, and needs its own TypedData
// adapter object.
$this->typedData = NULL;
$definitions = $this->getFieldDefinitions();
// The translation cache has to be cleared before cloning the fields
// below so that the call to getTranslation() does not re-use the
// translation objects of the old entity but instead creates new
// translation objects from the newly cloned entity. Otherwise the newly
// cloned field item lists would hold references to the old translation
// objects in their $parent property after the call to setContext().
$this->clearTranslationCache();
// Because the new translation objects that are created below are
// themselves created by *cloning* the newly cloned entity we need to
// make sure that the references to property values are properly cloned
// before cloning the fields. Otherwise calling
// $items->getEntity()->isNew(), for example, would return the
// $enforceIsNew value of the old entity.
// Ensure the translations array is actually cloned by overwriting the
// original reference with one pointing to a copy of the array.
$translations = $this->translations;
$this->translations = &$translations;
// Ensure that the following properties are actually cloned by
// overwriting the original references with ones pointing to copies of
// them: enforceIsNew, newRevision, loadedRevisionId and fields.
$enforce_is_new = $this->enforceIsNew;
$this->enforceIsNew = &$enforce_is_new;
$new_revision = $this->newRevision;
$this->newRevision = &$new_revision;
$original_revision_id = $this->loadedRevisionId;
$this->loadedRevisionId = &$original_revision_id;
$fields = $this->fields;
$this->fields = &$fields;
foreach ($this->fields as $name => $values) {
$this->fields[$name] = array();
// Untranslatable fields may have multiple references for the same field
// object keyed by language. To avoid creating different field objects
// we retain just the original value, as references will be recreated
// later as needed.
if (!$definitions[$name]->isTranslatable() && count($values) > 1) {
$values = array_intersect_key($values, array(LanguageInterface::LANGCODE_DEFAULT => TRUE));
}
foreach ($values as $langcode => $items) {
$this->fields[$name][$langcode] = clone $items;
$this->fields[$name][$langcode]->setContext($name, $this->getTranslation($langcode)->getTypedData());
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment