Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / layout_builder / src / Plugin / DataType / SectionData.php
diff --git a/web/core/modules/layout_builder/src/Plugin/DataType/SectionData.php b/web/core/modules/layout_builder/src/Plugin/DataType/SectionData.php
new file mode 100644 (file)
index 0000000..353c53f
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+
+namespace Drupal\layout_builder\Plugin\DataType;
+
+use Drupal\Core\TypedData\TypedData;
+use Drupal\layout_builder\Section;
+
+/**
+ * Provides a data type wrapping \Drupal\layout_builder\Section.
+ *
+ * @DataType(
+ *   id = "layout_section",
+ *   label = @Translation("Layout Section"),
+ *   description = @Translation("A layout section"),
+ * )
+ */
+class SectionData extends TypedData {
+
+  /**
+   * The section object.
+   *
+   * @var \Drupal\layout_builder\Section
+   */
+  protected $value;
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setValue($value, $notify = TRUE) {
+    if ($value && !$value instanceof Section) {
+      throw new \InvalidArgumentException(sprintf('Value assigned to "%s" is not a valid section', $this->getName()));
+    }
+    parent::setValue($value, $notify);
+  }
+
+}