Skip to content
Snippets Groups Projects
Commit b0f063e8 authored by catch's avatar catch
Browse files

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
No related branches found
No related tags found
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
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
use Drupal\Core\Config\Entity\ConfigEntityStorage; use Drupal\Core\Config\Entity\ConfigEntityStorage;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\layout_builder\Section; use Drupal\layout_builder\Section;
use Drupal\layout_builder\SectionComponent;
/** /**
* Provides storage for entity view display entities that have layouts. * Provides storage for entity view display entities that have layouts.
...@@ -38,20 +37,7 @@ protected function mapFromStorageRecords(array $records) { ...@@ -38,20 +37,7 @@ protected function mapFromStorageRecords(array $records) {
foreach ($records as $id => &$record) { foreach ($records as $id => &$record) {
if (!empty($record['third_party_settings']['layout_builder']['sections'])) { if (!empty($record['third_party_settings']['layout_builder']['sections'])) {
$sections = &$record['third_party_settings']['layout_builder']['sections']; $sections = &$record['third_party_settings']['layout_builder']['sections'];
foreach ($sections as $section_delta => $section) { $sections = array_map([Section::class, 'fromArray'], $sections);
$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'])
);
}
} }
} }
return parent::mapFromStorageRecords($records); return parent::mapFromStorageRecords($records);
......
...@@ -322,8 +322,7 @@ protected function layoutPluginManager() { ...@@ -322,8 +322,7 @@ protected function layoutPluginManager() {
/** /**
* Returns an array representation of the section. * Returns an array representation of the section.
* *
* @internal * Only use this method if you are implementing custom storage for sections.
* This is intended for use by a storage mechanism for sections.
* *
* @return array * @return array
* An array representation of the section component. * An array representation of the section component.
...@@ -338,4 +337,23 @@ public function toArray() { ...@@ -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() { ...@@ -292,8 +292,7 @@ protected function eventDispatcher() {
/** /**
* Returns an array representation of the section component. * Returns an array representation of the section component.
* *
* @internal * Only use this method if you are implementing custom storage for sections.
* This is intended for use by a storage mechanism for section components.
* *
* @return array * @return array
* An array representation of the section component. * An array representation of the section component.
...@@ -308,4 +307,24 @@ public function toArray() { ...@@ -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']);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment