summaryrefslogtreecommitdiffstats
path: root/core/modules
diff options
context:
space:
mode:
authorAlex Pott2018-11-14 12:48:46 (GMT)
committerAlex Pott2018-11-14 12:48:53 (GMT)
commit6ef9ab933ff21262ed630706fe14d4b76b5ae93b (patch)
treebd8a8ad0c2515820be6fc59565f66af5ce474fc9 /core/modules
parent3788f65ad4d2e750efc7fee851efec005dcbba6b (diff)
Issue #3013197 by tim.plunkett: Cloning an implementation of SectionListInterface does not deep clone the Section or SectionComponent objectsHEAD8.6.x
(cherry picked from commit cd6c6710283bc6b521103adee436b4cd15ed2af0)
Diffstat (limited to 'core/modules')
-rw-r--r--core/modules/layout_builder/src/Section.php9
-rw-r--r--core/modules/layout_builder/src/SectionStorage/SectionStorageTrait.php13
-rw-r--r--core/modules/layout_builder/tests/src/Kernel/SectionStorageTestBase.php11
3 files changed, 33 insertions, 0 deletions
diff --git a/core/modules/layout_builder/src/Section.php b/core/modules/layout_builder/src/Section.php
index 30d903a..1ec0b8a 100644
--- a/core/modules/layout_builder/src/Section.php
+++ b/core/modules/layout_builder/src/Section.php
@@ -356,4 +356,13 @@ class Section {
);
}
+ /**
+ * Magic method: Implements a deep clone.
+ */
+ public function __clone() {
+ foreach ($this->components as $uuid => $component) {
+ $this->components[$uuid] = clone $component;
+ }
+ }
+
}
diff --git a/core/modules/layout_builder/src/SectionStorage/SectionStorageTrait.php b/core/modules/layout_builder/src/SectionStorage/SectionStorageTrait.php
index 9d942c7..36729d2 100644
--- a/core/modules/layout_builder/src/SectionStorage/SectionStorageTrait.php
+++ b/core/modules/layout_builder/src/SectionStorage/SectionStorageTrait.php
@@ -111,4 +111,17 @@ trait SectionStorageTrait {
return isset($this->getSections()[$delta]);
}
+ /**
+ * Magic method: Implements a deep clone.
+ */
+ public function __clone() {
+ $sections = $this->getSections();
+
+ foreach ($sections as $delta => $item) {
+ $sections[$delta] = clone $item;
+ }
+
+ $this->setSections($sections);
+ }
+
}
diff --git a/core/modules/layout_builder/tests/src/Kernel/SectionStorageTestBase.php b/core/modules/layout_builder/tests/src/Kernel/SectionStorageTestBase.php
index 1879977..6c54d6c 100644
--- a/core/modules/layout_builder/tests/src/Kernel/SectionStorageTestBase.php
+++ b/core/modules/layout_builder/tests/src/Kernel/SectionStorageTestBase.php
@@ -138,6 +138,17 @@ abstract class SectionStorageTestBase extends EntityKernelTestBase {
}
/**
+ * Tests __clone().
+ */
+ public function testClone() {
+ $this->assertSame([], $this->sectionStorage->getSection(0)->getLayoutSettings());
+
+ $new_section_storage = clone $this->sectionStorage;
+ $new_section_storage->getSection(0)->setLayoutSettings(['asdf' => 'qwer']);
+ $this->assertSame([], $this->sectionStorage->getSection(0)->getLayoutSettings());
+ }
+
+ /**
* Asserts that the field list has the expected sections.
*
* @param \Drupal\layout_builder\Section[] $expected