From 51c15c4dff358b4a4673db91e362f22f56d5701d Mon Sep 17 00:00:00 2001 From: Zebulan Stanphill Date: Sat, 1 Sep 2018 14:08:23 -0500 Subject: [PATCH 1/5] Standardize alignment options for blocks based off of WP widgets --- packages/block-library/src/archives/edit.js | 1 - packages/block-library/src/archives/index.js | 2 +- packages/block-library/src/archives/index.php | 25 +++++++++++++------ packages/block-library/src/categories/edit.js | 1 - .../block-library/src/categories/index.js | 2 +- .../block-library/src/categories/index.php | 13 +++++----- .../src/latest-comments/index.php | 7 +++--- .../block-library/src/latest-posts/edit.js | 1 - .../block-library/src/latest-posts/index.js | 2 +- .../block-library/src/latest-posts/index.php | 6 ++--- 10 files changed, 33 insertions(+), 27 deletions(-) diff --git a/packages/block-library/src/archives/edit.js b/packages/block-library/src/archives/edit.js index 83b79b536eb87..0ec7ceb543d11 100644 --- a/packages/block-library/src/archives/edit.js +++ b/packages/block-library/src/archives/edit.js @@ -44,7 +44,6 @@ export default function ArchivesEdit( { attributes, setAttributes } ) { onChange={ ( nextAlign ) => { 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 2774569ab6531..eec1f316c8565 100644 --- a/packages/block-library/src/archives/index.js +++ b/packages/block-library/src/archives/index.js @@ -25,7 +25,7 @@ export const settings = { getEditWrapperProps( attributes ) { const { align } = attributes; - if ( 'left' === align || 'right' === align || 'center' === align ) { + if ( [ 'left', 'center', 'right', 'wide', 'full' ].includes( align ) ) { return { 'data-align': align }; } }, diff --git a/packages/block-library/src/archives/index.php b/packages/block-library/src/archives/index.php index 9784284361922..004a11a120fb7 100644 --- a/packages/block-library/src/archives/index.php +++ b/packages/block-library/src/archives/index.php @@ -16,7 +16,16 @@ */ function render_block_core_archives( $attributes ) { $show_post_count = ! empty( $attributes['showPostCounts'] ); - $class = "wp-block-archives align{$attributes['align']}"; + + $class = "wp-block-archives"; + + if ( isset( $attributes['align'] ) ) { + $class .= " align{$attributes['align']}"; + } + + if ( isset( $attributes['className'] ) ) { + $class .= " {$attributes['className']}"; + } if ( ! empty( $attributes['displayAsDropdown'] ) ) { @@ -99,17 +108,19 @@ function register_block_core_archives() { 'core/archives', array( 'attributes' => array( - 'showPostCounts' => array( - 'type' => 'boolean', - 'default' => false, + 'align' => array( + 'type' => 'string', + ), + 'className' => array( + 'type' => 'string', ), 'displayAsDropdown' => array( 'type' => 'boolean', 'default' => false, ), - 'align' => array( - 'type' => 'string', - 'default' => 'none', + 'showPostCounts' => array( + 'type' => 'boolean', + 'default' => false, ), ), 'render_callback' => 'render_block_core_archives', diff --git a/packages/block-library/src/categories/edit.js b/packages/block-library/src/categories/edit.js index 49097d18b888d..0bd2b18f3d3e5 100644 --- a/packages/block-library/src/categories/edit.js +++ b/packages/block-library/src/categories/edit.js @@ -187,7 +187,6 @@ class CategoriesEdit extends Component { onChange={ ( nextAlign ) => { setAttributes( { align: nextAlign } ); } } - controls={ [ 'left', 'center', 'right', 'full' ] } />
diff --git a/packages/block-library/src/categories/index.js b/packages/block-library/src/categories/index.js index 399e5d95d7b2c..b5536567c52ab 100644 --- a/packages/block-library/src/categories/index.js +++ b/packages/block-library/src/categories/index.js @@ -43,7 +43,7 @@ export const settings = { getEditWrapperProps( attributes ) { const { align } = attributes; - if ( 'left' === align || 'right' === align || 'full' === align ) { + if ( [ 'left', 'center', 'right', 'wide', 'full' ].includes( align ) ) { return { 'data-align': align }; } }, diff --git a/packages/block-library/src/categories/index.php b/packages/block-library/src/categories/index.php index cf121ced0b769..05aba5fccf2ac 100644 --- a/packages/block-library/src/categories/index.php +++ b/packages/block-library/src/categories/index.php @@ -16,11 +16,6 @@ function render_block_core_categories( $attributes ) { static $block_id = 0; $block_id++; - $align = 'center'; - if ( isset( $attributes['align'] ) && in_array( $attributes['align'], array( 'left', 'right', 'full' ), true ) ) { - $align = $attributes['align']; - } - $args = array( 'echo' => false, 'hierarchical' => ! empty( $attributes['showHierarchy'] ), @@ -46,10 +41,14 @@ function render_block_core_categories( $attributes ) { $type = 'list'; } - $class = "wp-block-categories wp-block-categories-{$type} align{$align}"; + $class = "wp-block-categories wp-block-categories-{$type}"; + + if ( isset( $attributes['align'] ) ) { + $class .= " align{$attributes['align']}"; + } if ( isset( $attributes['className'] ) ) { - $class .= ' ' . $attributes['className']; + $class .= " {$attributes['className']}"; } $block_content = sprintf( diff --git a/packages/block-library/src/latest-comments/index.php b/packages/block-library/src/latest-comments/index.php index dd310028ce145..b40fa5e45eb85 100644 --- a/packages/block-library/src/latest-comments/index.php +++ b/packages/block-library/src/latest-comments/index.php @@ -151,6 +151,9 @@ function gutenberg_render_block_core_latest_comments( $attributes = array() ) { 'core/latest-comments', array( 'attributes' => array( + 'align' => array( + 'type' => 'string', + ), 'className' => array( 'type' => 'string', ), @@ -172,10 +175,6 @@ function gutenberg_render_block_core_latest_comments( $attributes = array() ) { 'type' => 'boolean', 'default' => true, ), - 'align' => array( - 'type' => 'string', - 'enum' => array( 'center', 'left', 'right', 'wide', 'full', '' ), - ), ), 'render_callback' => 'gutenberg_render_block_core_latest_comments', ) diff --git a/packages/block-library/src/latest-posts/edit.js b/packages/block-library/src/latest-posts/edit.js index 580792b3e0d64..8c489af5ed7e2 100644 --- a/packages/block-library/src/latest-posts/edit.js +++ b/packages/block-library/src/latest-posts/edit.js @@ -125,7 +125,6 @@ class LatestPostsEdit extends Component { onChange={ ( nextAlign ) => { setAttributes( { align: nextAlign } ); } } - controls={ [ 'center', 'wide', 'full' ] } /> diff --git a/packages/block-library/src/latest-posts/index.js b/packages/block-library/src/latest-posts/index.js index 6fe9e16104041..10f1f4bb3cb40 100644 --- a/packages/block-library/src/latest-posts/index.js +++ b/packages/block-library/src/latest-posts/index.js @@ -27,7 +27,7 @@ export const settings = { getEditWrapperProps( attributes ) { const { align } = attributes; - if ( 'left' === align || 'right' === align || 'wide' === align || 'full' === align ) { + if ( [ 'left', 'center', 'right', 'wide', 'full' ].includes( align ) ) { return { 'data-align': align }; } }, diff --git a/packages/block-library/src/latest-posts/index.php b/packages/block-library/src/latest-posts/index.php index 070abafeb4c75..128df9685268c 100644 --- a/packages/block-library/src/latest-posts/index.php +++ b/packages/block-library/src/latest-posts/index.php @@ -83,6 +83,9 @@ function register_block_core_latest_posts() { 'core/latest-posts', array( 'attributes' => array( + 'align' => array( + 'type' => 'string', + ), 'categories' => array( 'type' => 'string', ), @@ -105,9 +108,6 @@ function register_block_core_latest_posts() { 'type' => 'number', 'default' => 3, ), - 'align' => array( - 'type' => 'string', - ), 'order' => array( 'type' => 'string', 'default' => 'desc', From c045f75042cd6e55820c8bb57a7d3c76cd914619 Mon Sep 17 00:00:00 2001 From: Zebulan Stanphill Date: Mon, 3 Sep 2018 22:30:34 -0500 Subject: [PATCH 2/5] Fix test failures --- test/integration/full-content/server-registered.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/full-content/server-registered.json b/test/integration/full-content/server-registered.json index ae3a565090857..8cdd5fd81e182 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":{"showPostCounts":{"type":"boolean","default":false},"displayAsDropdown":{"type":"boolean","default":false},"align":{"type":"string","default":"none"}}},"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\/latest-comments":{"attributes":{"align":{"type":"string"},"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}}},"core\/archives":{"attributes":{"align":{"type":"string"},"displayAsDropdown":{"type":"boolean","default":false},"showPostCounts":{"type":"boolean","default":false}}},"core\/latest-posts":{"attributes":{"align":{"type":"string"},"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}}}} From 1073e51f03572df432f6a85585fec9f4e08c4246 Mon Sep 17 00:00:00 2001 From: Zebulan Stanphill Date: Mon, 3 Sep 2018 22:49:27 -0500 Subject: [PATCH 3/5] Fix more tests --- test/integration/full-content/fixtures/core__archives.json | 3 +-- .../full-content/fixtures/core__archives__showPostCounts.json | 3 +-- test/integration/full-content/server-registered.json | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/test/integration/full-content/fixtures/core__archives.json b/test/integration/full-content/fixtures/core__archives.json index 0caf2ec732a3d..7162be0dcddd3 100644 --- a/test/integration/full-content/fixtures/core__archives.json +++ b/test/integration/full-content/fixtures/core__archives.json @@ -5,8 +5,7 @@ "isValid": true, "attributes": { "showPostCounts": false, - "displayAsDropdown": false, - "align": "none" + "displayAsDropdown": false }, "innerBlocks": [], "originalContent": "" diff --git a/test/integration/full-content/fixtures/core__archives__showPostCounts.json b/test/integration/full-content/fixtures/core__archives__showPostCounts.json index 76d086c472d07..adf3c5324709d 100644 --- a/test/integration/full-content/fixtures/core__archives__showPostCounts.json +++ b/test/integration/full-content/fixtures/core__archives__showPostCounts.json @@ -5,8 +5,7 @@ "isValid": true, "attributes": { "showPostCounts": true, - "displayAsDropdown": false, - "align": "none" + "displayAsDropdown": false }, "innerBlocks": [], "originalContent": "" diff --git a/test/integration/full-content/server-registered.json b/test/integration/full-content/server-registered.json index 8cdd5fd81e182..ce49d6a38a132 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":{"align":{"type":"string"},"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}}},"core\/archives":{"attributes":{"align":{"type":"string"},"displayAsDropdown":{"type":"boolean","default":false},"showPostCounts":{"type":"boolean","default":false}}},"core\/latest-posts":{"attributes":{"align":{"type":"string"},"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}}}} +{"core\/block":{"attributes":{"ref":{"type":"number"}}},"core\/latest-comments":{"attributes":{"align":{"type":"string"},"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}}},"core\/archives":{"attributes":{"align":{"type":"string"},"className":{"type":"string"},"displayAsDropdown":{"type":"boolean","default":false},"showPostCounts":{"type":"boolean","default":false}}},"core\/latest-posts":{"attributes":{"align":{"type":"string"},"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}}}} From b40c422ff16fffa5157f829c09cb00210f190711 Mon Sep 17 00:00:00 2001 From: Zebulan Stanphill Date: Mon, 3 Sep 2018 23:03:37 -0500 Subject: [PATCH 4/5] Fix code style issue caught by linter --- packages/block-library/src/archives/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/archives/index.php b/packages/block-library/src/archives/index.php index 004a11a120fb7..234037a2994ab 100644 --- a/packages/block-library/src/archives/index.php +++ b/packages/block-library/src/archives/index.php @@ -17,7 +17,7 @@ function render_block_core_archives( $attributes ) { $show_post_count = ! empty( $attributes['showPostCounts'] ); - $class = "wp-block-archives"; + $class = 'wp-block-archives'; if ( isset( $attributes['align'] ) ) { $class .= " align{$attributes['align']}"; From faddf50850bcce28ec71d84987902457bd7a96bb Mon Sep 17 00:00:00 2001 From: Zebulan Stanphill Date: Tue, 4 Sep 2018 11:42:40 -0500 Subject: [PATCH 5/5] Reorganize Categories block attributes in index.js alphabetically --- packages/block-library/src/categories/index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/block-library/src/categories/index.js b/packages/block-library/src/categories/index.js index b5536567c52ab..fce7509a6be51 100644 --- a/packages/block-library/src/categories/index.js +++ b/packages/block-library/src/categories/index.js @@ -20,9 +20,8 @@ export const settings = { category: 'widgets', attributes: { - showPostCounts: { - type: 'boolean', - default: false, + align: { + type: 'string', }, displayAsDropdown: { type: 'boolean', @@ -32,8 +31,9 @@ export const settings = { type: 'boolean', default: false, }, - align: { - type: 'string', + showPostCounts: { + type: 'boolean', + default: false, }, },