Skip to content

Commit

Permalink
Docs: Add example for registerBlockType hook (#8091)
Browse files Browse the repository at this point in the history
* Docs: Add example for registerBlockType hook

* Rewrite example using ES5 syntax and wp.* globals
  • Loading branch information
mcsf authored Jul 23, 2018
1 parent b129f0e commit 1533c33
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions docs/extensibility/extending-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,30 @@ To modify the behavior of existing blocks, Gutenberg exposes the following Filte

Used to filter the block settings. It receives the block settings and the name of the block the registered block as arguments.

_Example:_

Ensure that List blocks are saved with the canonical generated class name (`wp-block-list`):

```js
function addListBlockClassName( settings, name ) {
if ( name !== 'core/list' ) {
return settings;
}

return Object.assign( {}, settings, {
supports: Object.assign( {}, settings.supports, {
className: true
} ),
} );
}

wp.hooks.addFilter(
'blocks.registerBlockType',
'my-plugin/class-names/list-block',
addListBlockClassName
);
```

#### `blocks.getSaveElement`

A filter that applies to the result of a block's `save` function. This filter is used to replace or extend the element, for example using `wp.element.cloneElement` to modify the element's props or replace its children, or returning an entirely new element.
Expand Down

0 comments on commit 1533c33

Please sign in to comment.