Skip to content

Commit

Permalink
Merge pull request silverstripe#313 from creative-commoners/pulls/4.0…
Browse files Browse the repository at this point in the history
…/extensible-block-schema

NEW Block schema is now extensible, getBlockSchema marked as internal
  • Loading branch information
robbieaverill authored Aug 12, 2018
2 parents 665f945 + 0fb157d commit fb9be70
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
30 changes: 26 additions & 4 deletions src/Models/BaseElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Models/ElementContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit fb9be70

Please sign in to comment.