Skip to content
Snippets Groups Projects
Unverified Commit cd6c6710 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3013197 by tim.plunkett: Cloning an implementation of...

Issue #3013197 by tim.plunkett: Cloning an implementation of SectionListInterface does not deep clone the Section or SectionComponent objects
parent edfebee5
Branches
Tags
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
......@@ -356,4 +356,13 @@ public static function fromArray(array $section) {
);
}
/**
* Magic method: Implements a deep clone.
*/
public function __clone() {
foreach ($this->components as $uuid => $component) {
$this->components[$uuid] = clone $component;
}
}
}
......@@ -111,4 +111,17 @@ protected function hasSection($delta) {
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);
}
}
......@@ -137,6 +137,17 @@ public function testRemoveSection() {
$this->assertSections($expected);
}
/**
* 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.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment