summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxjm2017-02-23 00:23:06 +0000
committerxjm2017-02-23 00:23:06 +0000
commitccc65da733005958bf39cb1f64cfdde6e35c3ebe (patch)
tree56d746c8c1522f7ceae34c87b93211bcc6903c48
parent7e506626a260eb93eaebbc81b5d8e3a858dc5c6b (diff)
Issue #2854926 by xjm, borisson_, boaloysius: Remove unneeded control structures in ContentEntityBase
-rw-r--r--core/lib/Drupal/Core/Entity/ContentEntityBase.php121
1 files changed, 61 insertions, 60 deletions
diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php
index 5cd27c7..78982a8 100644
--- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php
+++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php
@@ -1014,10 +1014,9 @@ abstract class ContentEntityBase extends Entity implements \IteratorAggregate, C
if ($this->hasField($name)) {
return TRUE;
}
+
// For non-field properties, check the internal values.
- else {
- return isset($this->values[$name]);
- }
+ return isset($this->values[$name]);
}
/**
@@ -1027,11 +1026,11 @@ abstract class ContentEntityBase extends Entity implements \IteratorAggregate, C
// Unsetting a field means emptying it.
if ($this->hasField($name)) {
$this->get($name)->setValue(array());
+ return TRUE;
}
+
// For non-field properties, unset the internal value.
- else {
- unset($this->values[$name]);
- }
+ unset($this->values[$name]);
}
/**
@@ -1067,60 +1066,62 @@ abstract class ContentEntityBase extends Entity implements \IteratorAggregate, C
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 TRUE;
+ }
+
+ // 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());
}
}
}