Skip to content
Open
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
18 changes: 18 additions & 0 deletions core/Container/Block_Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Block_Container extends Container {
'template_lock' => null,
'allowed_blocks' => null,
),
'align' => false,
'align_default' => false,
'category' => array(
'slug' => 'common',
),
Expand Down Expand Up @@ -304,6 +306,22 @@ public function set_inner_blocks( $inner_blocks = true ) {
return $this;
}

/**
* Set the align options available for this block.
*
* Either pass a boolean or an array of values `left`, `center`, `right`, `wide`, and `full`.
*
* @param array|boolean $inner_blocks
* @param string|boolean $default
* @return Block_Container
*/
public function set_align( $align = false, $default = false ) {
$this->settings[ 'align' ] = $align;
$this->settings[ 'align_default' ] = $default;

return $this;
}

/**
* Set the position of the inner blocks to be rendered
* above or below the fields.
Expand Down
15 changes: 13 additions & 2 deletions packages/blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ get( window.cf, 'preloaded.blocks', [] ).forEach( ( container ) => {
containerDefinitions[ name ] = container;
fieldDefinitions[ name ] = container.fields.map( ( field ) => ( { ...field } ) );

let attributes = {};

let alignDefault = getBlockSetting( 'align_default', false );
if(alignDefault) {
attributes['align'] = {
'type': 'string',
'default': alignDefault
};
}

registerBlockType( `carbon-fields/${ name }`, {
title: container.title,
icon: getBlockSetting( 'icon' ),
Expand All @@ -52,13 +62,14 @@ get( window.cf, 'preloaded.blocks', [] ).forEach( ( container ) => {
data: {
type: 'object',
default: fields
}
},
...attributes
},
supports: {
tabs: isPlainObject( getBlockSetting( 'tabs' ) ),
preview: getBlockSetting( 'preview' ),
innerBlocks: getBlockSetting( 'inner_blocks.enabled' ),
alignWide: false,
align: getBlockSetting( 'align', false ),
anchor: false,
html: false
},
Expand Down