Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEW Block schema is now extensible, getBlockSchema marked as internal #313

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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