From 0fb157d77a684675db2f787ba6b9ead88eec8679 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Mon, 13 Aug 2018 10:40:01 +1200 Subject: [PATCH] NEW Block schema is now extensible, getBlockSchema marked as internal --- src/Models/BaseElement.php | 30 ++++++++++++++++++++++++++---- src/Models/ElementContent.php | 4 ++-- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/Models/BaseElement.php b/src/Models/BaseElement.php index 7b054336..0da926da 100644 --- a/src/Models/BaseElement.php +++ b/src/Models/BaseElement.php @@ -709,19 +709,41 @@ public function getSummary() /** + * The block schema defines a set of data that will be serialised and sent via GraphQL + * to the React editor client. + * + * To modify the schema, either use the extension point or overload the `provideBlockSchema` + * method. + * + * @internal This API may change in future. Treat this as a `final` method. * @return array */ public function getBlockSchema() { - $blockSchema = [ + $blockSchema = $this->provideBlockSchema(); + + $this->extend('updateBlockSchema', $blockSchema); + + return $blockSchema; + } + + /** + * Provide block schema data, which will be serialised and sent via GraphQL to the editor client. + * + * Overload this method in child element classes to augment, or use the extension point on `getBlockSchema` + * to update it from an `Extension`. + * + * @return array + */ + protected function provideBlockSchema() + { + return [ 'iconClass' => $this->config()->get('icon'), 'type' => $this->getType(), 'actions' => [ 'edit' => $this->getEditLink(), - ] + ], ]; - - return $blockSchema; } /** diff --git a/src/Models/ElementContent.php b/src/Models/ElementContent.php index cc876b0f..e597f536 100644 --- a/src/Models/ElementContent.php +++ b/src/Models/ElementContent.php @@ -41,9 +41,9 @@ public function getSummary() return DBField::create_field('HTMLText', $this->HTML)->Summary(20); } - public function getBlockSchema() + protected function provideBlockSchema() { - $blockSchema = parent::getBlockSchema(); + $blockSchema = parent::provideBlockSchema(); $blockSchema['content'] = $this->getSummary(); return $blockSchema; }