Commit b0f063e8 authored by catch's avatar catch

Issue #2941763 by tim.plunkett, larowlan, xjm: Move elements of...

Issue #2941763 by tim.plunkett, larowlan, xjm: Move elements of \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplayStorage into a stand-alone service or static methods
parent b23ee08a
......@@ -5,7 +5,6 @@
use Drupal\Core\Config\Entity\ConfigEntityStorage;
use Drupal\Core\Entity\EntityInterface;
use Drupal\layout_builder\Section;
use Drupal\layout_builder\SectionComponent;
/**
* Provides storage for entity view display entities that have layouts.
......@@ -38,20 +37,7 @@ protected function mapFromStorageRecords(array $records) {
foreach ($records as $id => &$record) {
if (!empty($record['third_party_settings']['layout_builder']['sections'])) {
$sections = &$record['third_party_settings']['layout_builder']['sections'];
foreach ($sections as $section_delta => $section) {
$sections[$section_delta] = new Section(
$section['layout_id'],
$section['layout_settings'],
array_map(function (array $component) {
return (new SectionComponent(
$component['uuid'],
$component['region'],
$component['configuration'],
$component['additional']
))->setWeight($component['weight']);
}, $section['components'])
);
}
$sections = array_map([Section::class, 'fromArray'], $sections);
}
}
return parent::mapFromStorageRecords($records);
......
......@@ -322,8 +322,7 @@ protected function layoutPluginManager() {
/**
* 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,23 @@ public function toArray() {
];
}
/**
* 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'])
);
}
}
......@@ -292,8 +292,7 @@ protected function eventDispatcher() {
/**
* Returns an array representation of the section component.
*
* @internal
* This is intended for use by a storage mechanism for section components.
* Only use this method if you are implementing custom storage for sections.
*
* @return array
* An array representation of the section component.
......@@ -308,4 +307,24 @@ public function toArray() {
];
}
/**
* Creates an object from an array representation of the section component.
*
* Only use this method if you are implementing custom storage for sections.
*
* @param array $component
* An array of section component data in the format returned by ::toArray().
*
* @return static
* The section component object.
*/
public static function fromArray(array $component) {
return (new static(
$component['uuid'],
$component['region'],
$component['configuration'],
$component['additional']
))->setWeight($component['weight']);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment