Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / layout_builder / src / Section.php
index 04b1cbb2c60eccecec18650a60d4e0382ab2a25d..30d903a30ab8a8f15eb116389a41c385d833313c 100644 (file)
@@ -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,23 @@ 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'])
+    );
+  }
+
 }