diff --git a/core/Container/Block_Container.php b/core/Container/Block_Container.php index 23762ea5..84b3a871 100644 --- a/core/Container/Block_Container.php +++ b/core/Container/Block_Container.php @@ -22,6 +22,8 @@ class Block_Container extends Container { 'template_lock' => null, 'allowed_blocks' => null, ), + 'align' => false, + 'align_default' => false, 'category' => array( 'slug' => 'common', ), @@ -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. diff --git a/packages/blocks/index.js b/packages/blocks/index.js index 583df01f..298ea24d 100644 --- a/packages/blocks/index.js +++ b/packages/blocks/index.js @@ -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' ), @@ -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 },