From c746b673b28dc927eabe6d7d8445e29ee095ce5d Mon Sep 17 00:00:00 2001 From: Zebulan Stanphill Date: Wed, 17 Oct 2018 15:54:41 -0500 Subject: [PATCH 1/2] Archives block: use align supports flag + wide/full align support --- packages/block-library/src/archives/edit.js | 23 ++++--------------- packages/block-library/src/archives/index.js | 8 +------ packages/block-library/src/archives/index.php | 1 + .../full-content/server-registered.json | 2 +- 4 files changed, 7 insertions(+), 27 deletions(-) diff --git a/packages/block-library/src/archives/edit.js b/packages/block-library/src/archives/edit.js index b59f4dd04d930..a529b00151c30 100644 --- a/packages/block-library/src/archives/edit.js +++ b/packages/block-library/src/archives/edit.js @@ -1,26 +1,20 @@ /** * WordPress dependencies */ -import { Fragment } from '@wordpress/element'; import { + Disabled, PanelBody, ToggleControl, - Disabled, } from '@wordpress/components'; -import { __ } from '@wordpress/i18n'; - -/** - * Internal dependencies - */ import { InspectorControls, - BlockAlignmentToolbar, - BlockControls, ServerSideRender, } from '@wordpress/editor'; +import { Fragment } from '@wordpress/element'; +import { __ } from '@wordpress/i18n'; export default function ArchivesEdit( { attributes, setAttributes } ) { - const { align, showPostCounts, displayAsDropdown } = attributes; + const { displayAsDropdown, showPostCounts } = attributes; return ( @@ -38,15 +32,6 @@ export default function ArchivesEdit( { attributes, setAttributes } ) { /> - - { - setAttributes( { align: nextAlign } ); - } } - controls={ [ 'left', 'center', 'right' ] } - /> - diff --git a/packages/block-library/src/archives/index.js b/packages/block-library/src/archives/index.js index 8dfca64a8823c..8b34f786c4c48 100644 --- a/packages/block-library/src/archives/index.js +++ b/packages/block-library/src/archives/index.js @@ -21,16 +21,10 @@ export const settings = { category: 'widgets', supports: { + align: true, html: false, }, - getEditWrapperProps( attributes ) { - const { align } = attributes; - if ( [ 'left', 'center', 'right' ].includes( align ) ) { - return { 'data-align': align }; - } - }, - edit, save() { diff --git a/packages/block-library/src/archives/index.php b/packages/block-library/src/archives/index.php index 3d7b5b42f4ae4..7e557fec126c7 100644 --- a/packages/block-library/src/archives/index.php +++ b/packages/block-library/src/archives/index.php @@ -126,6 +126,7 @@ function register_block_core_archives() { 'attributes' => array( 'align' => array( 'type' => 'string', + 'enum' => array( 'left', 'center', 'right', 'wide', 'full' ), ), 'className' => array( 'type' => 'string', diff --git a/test/integration/full-content/server-registered.json b/test/integration/full-content/server-registered.json index 65eb48d6d53f2..a87bd4ef5cecb 100644 --- a/test/integration/full-content/server-registered.json +++ b/test/integration/full-content/server-registered.json @@ -1 +1 @@ -{"core\/block":{"attributes":{"ref":{"type":"number"}}},"core\/latest-comments":{"attributes":{"className":{"type":"string"},"commentsToShow":{"type":"number","default":5,"minimum":1,"maximum":100},"displayAvatar":{"type":"boolean","default":true},"displayDate":{"type":"boolean","default":true},"displayExcerpt":{"type":"boolean","default":true},"align":{"type":"string","enum":["center","left","right","wide","full",""]}}},"core\/archives":{"attributes":{"align":{"type":"string"},"className":{"type":"string"},"displayAsDropdown":{"type":"boolean","default":false},"showPostCounts":{"type":"boolean","default":false}}},"core\/latest-posts":{"attributes":{"categories":{"type":"string"},"className":{"type":"string"},"postsToShow":{"type":"number","default":5},"displayPostDate":{"type":"boolean","default":false},"postLayout":{"type":"string","default":"list"},"columns":{"type":"number","default":3},"align":{"type":"string"},"order":{"type":"string","default":"desc"},"orderBy":{"type":"string","default":"date"}}}} \ No newline at end of file +{"core\/block":{"attributes":{"ref":{"type":"number"}}},"core\/archives":{"attributes":{"align":{"type":"string","enum":["left","center","right","wide","full"]},"className":{"type":"string"},"displayAsDropdown":{"type":"boolean","default":false},"showPostCounts":{"type":"boolean","default":false}}},"core\/latest-comments":{"attributes":{"className":{"type":"string"},"commentsToShow":{"type":"number","default":5,"minimum":1,"maximum":100},"displayAvatar":{"type":"boolean","default":true},"displayDate":{"type":"boolean","default":true},"displayExcerpt":{"type":"boolean","default":true},"align":{"type":"string","enum":["center","left","right","wide","full",""]}}},"core\/latest-posts":{"attributes":{"categories":{"type":"string"},"className":{"type":"string"},"postsToShow":{"type":"number","default":5},"displayPostDate":{"type":"boolean","default":false},"postLayout":{"type":"string","default":"list"},"columns":{"type":"number","default":3},"align":{"type":"string"},"order":{"type":"string","default":"desc"},"orderBy":{"type":"string","default":"date"}}}} \ No newline at end of file From 05bbf171e7321477053012e889b1510ca3aa47c7 Mon Sep 17 00:00:00 2001 From: Zebulan Stanphill Date: Wed, 17 Oct 2018 16:18:35 -0500 Subject: [PATCH 2/2] Latest Posts: use align supports flag + left/right align support --- .../block-library/src/latest-posts/index.js | 8 +---- .../block-library/src/latest-posts/index.php | 33 ++++++++++--------- .../full-content/server-registered.json | 2 +- 3 files changed, 19 insertions(+), 24 deletions(-) diff --git a/packages/block-library/src/latest-posts/index.js b/packages/block-library/src/latest-posts/index.js index e1dd91ea70af8..5d5d860aced52 100644 --- a/packages/block-library/src/latest-posts/index.js +++ b/packages/block-library/src/latest-posts/index.js @@ -23,16 +23,10 @@ export const settings = { keywords: [ __( 'recent posts' ) ], supports: { + align: true, html: false, }, - getEditWrapperProps( attributes ) { - const { align } = attributes; - if ( [ 'left', 'center', 'right', 'wide', 'full' ].includes( align ) ) { - return { 'data-align': align }; - } - }, - edit, save() { diff --git a/packages/block-library/src/latest-posts/index.php b/packages/block-library/src/latest-posts/index.php index 18a43e51828e5..f96f707e53575 100644 --- a/packages/block-library/src/latest-posts/index.php +++ b/packages/block-library/src/latest-posts/index.php @@ -54,7 +54,7 @@ function render_block_core_latest_posts( $attributes ) { $class = 'wp-block-latest-posts'; if ( isset( $attributes['align'] ) ) { - $class .= ' align' . $attributes['align']; + $class .= " align{$attributes['align']}"; } if ( isset( $attributes['postLayout'] ) && 'grid' === $attributes['postLayout'] ) { @@ -62,7 +62,7 @@ function render_block_core_latest_posts( $attributes ) { } if ( isset( $attributes['columns'] ) && 'grid' === $attributes['postLayout'] ) { - $class .= ' columns-' . $attributes['columns']; + $class .= " columns-{$attributes['columns']}"; } if ( isset( $attributes['displayPostDate'] ) && $attributes['displayPostDate'] ) { @@ -70,7 +70,7 @@ function render_block_core_latest_posts( $attributes ) { } if ( isset( $attributes['className'] ) ) { - $class .= ' ' . $attributes['className']; + $class .= " {$attributes['className']}"; } $block_content = sprintf( @@ -90,31 +90,24 @@ function register_block_core_latest_posts() { 'core/latest-posts', array( 'attributes' => array( + 'align' => array( + 'type' => 'string', + 'enum' => array( 'left', 'center', 'right', 'wide', 'full' ), + ), 'categories' => array( 'type' => 'string', ), 'className' => array( 'type' => 'string', ), - 'postsToShow' => array( + 'columns' => array( 'type' => 'number', - 'default' => 5, + 'default' => 3, ), 'displayPostDate' => array( 'type' => 'boolean', 'default' => false, ), - 'postLayout' => array( - 'type' => 'string', - 'default' => 'list', - ), - 'columns' => array( - 'type' => 'number', - 'default' => 3, - ), - 'align' => array( - 'type' => 'string', - ), 'order' => array( 'type' => 'string', 'default' => 'desc', @@ -123,6 +116,14 @@ function register_block_core_latest_posts() { 'type' => 'string', 'default' => 'date', ), + 'postLayout' => array( + 'type' => 'string', + 'default' => 'list', + ), + 'postsToShow' => array( + 'type' => 'number', + 'default' => 5, + ), ), 'render_callback' => 'render_block_core_latest_posts', ) diff --git a/test/integration/full-content/server-registered.json b/test/integration/full-content/server-registered.json index a87bd4ef5cecb..b6587d70f1862 100644 --- a/test/integration/full-content/server-registered.json +++ b/test/integration/full-content/server-registered.json @@ -1 +1 @@ -{"core\/block":{"attributes":{"ref":{"type":"number"}}},"core\/archives":{"attributes":{"align":{"type":"string","enum":["left","center","right","wide","full"]},"className":{"type":"string"},"displayAsDropdown":{"type":"boolean","default":false},"showPostCounts":{"type":"boolean","default":false}}},"core\/latest-comments":{"attributes":{"className":{"type":"string"},"commentsToShow":{"type":"number","default":5,"minimum":1,"maximum":100},"displayAvatar":{"type":"boolean","default":true},"displayDate":{"type":"boolean","default":true},"displayExcerpt":{"type":"boolean","default":true},"align":{"type":"string","enum":["center","left","right","wide","full",""]}}},"core\/latest-posts":{"attributes":{"categories":{"type":"string"},"className":{"type":"string"},"postsToShow":{"type":"number","default":5},"displayPostDate":{"type":"boolean","default":false},"postLayout":{"type":"string","default":"list"},"columns":{"type":"number","default":3},"align":{"type":"string"},"order":{"type":"string","default":"desc"},"orderBy":{"type":"string","default":"date"}}}} \ No newline at end of file +{"core\/block":{"attributes":{"ref":{"type":"number"}}},"core\/archives":{"attributes":{"align":{"type":"string","enum":["left","center","right","wide","full"]},"className":{"type":"string"},"displayAsDropdown":{"type":"boolean","default":false},"showPostCounts":{"type":"boolean","default":false}}},"core\/latest-comments":{"attributes":{"className":{"type":"string"},"commentsToShow":{"type":"number","default":5,"minimum":1,"maximum":100},"displayAvatar":{"type":"boolean","default":true},"displayDate":{"type":"boolean","default":true},"displayExcerpt":{"type":"boolean","default":true},"align":{"type":"string","enum":["center","left","right","wide","full",""]}}},"core\/latest-posts":{"attributes":{"align":{"type":"string","enum":["left","center","right","wide","full"]},"categories":{"type":"string"},"className":{"type":"string"},"columns":{"type":"number","default":3},"displayPostDate":{"type":"boolean","default":false},"order":{"type":"string","default":"desc"},"orderBy":{"type":"string","default":"date"},"postLayout":{"type":"string","default":"list"},"postsToShow":{"type":"number","default":5}}}} \ No newline at end of file