X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Flayout_builder%2Fsrc%2FSection.php;h=1ec0b8af10aea6d433106e59d99758836cdc8b4d;hb=5b8bb166bfa98770daef9de5c127fc2e6ef02340;hp=04b1cbb2c60eccecec18650a60d4e0382ab2a25d;hpb=af6d1fb995500ae68849458ee10d66abbdcfb252;p=yaffs-website diff --git a/web/core/modules/layout_builder/src/Section.php b/web/core/modules/layout_builder/src/Section.php index 04b1cbb2c..1ec0b8af1 100644 --- a/web/core/modules/layout_builder/src/Section.php +++ b/web/core/modules/layout_builder/src/Section.php @@ -322,8 +322,7 @@ class Section { /** * Returns an array representation of the section. * - * @internal - * This is intended for use by a storage mechanism for sections. + * Only use this method if you are implementing custom storage for sections. * * @return array * An array representation of the section component. @@ -338,4 +337,32 @@ class Section { ]; } + /** + * Creates an object from an array representation of the section. + * + * Only use this method if you are implementing custom storage for sections. + * + * @param array $section + * An array of section data in the format returned by ::toArray(). + * + * @return static + * The section object. + */ + public static function fromArray(array $section) { + return new static( + $section['layout_id'], + $section['layout_settings'], + array_map([SectionComponent::class, 'fromArray'], $section['components']) + ); + } + + /** + * Magic method: Implements a deep clone. + */ + public function __clone() { + foreach ($this->components as $uuid => $component) { + $this->components[$uuid] = clone $component; + } + } + }