Per default, the Gutenberg groups block has only two alignment options: wide
and full width
.
I now want to add a custom alignment center
to the block. Other blocks like images have this option.
Is there any way to extend a core block like this?
I know that there is an option for custom styles with registerBlockStyle
(See docs).
But is there also something like this for basic controls/settings? I couldn't find anything in the docs.
I found an answer here.
It works, if I change the code like this:
wp.hooks.addFilter( 'blocks.registerBlockType',
'my/change_alignment', ( settings, name ) => {
switch( name ) {
case 'core/group':
case 'core/cover':
return lodash.assign( {}, settings, {
supports: lodash.assign( {}, settings.supports, {
align: [ 'center', 'wide', 'full']
} ),
} );
}
return settings;
});