From 059f4fdacd25e2adcccca42a93de816ab1545a2c Mon Sep 17 00:00:00 2001 From: Zebulan Stanphill Date: Fri, 7 Sep 2018 12:58:06 -0500 Subject: [PATCH] Archives block: fix alignment and custom class issues --- packages/block-library/src/archives/index.js | 2 +- packages/block-library/src/archives/index.php | 25 +++++++++++++------ .../full-content/fixtures/core__archives.html | 2 +- .../full-content/fixtures/core__archives.json | 3 +-- .../fixtures/core__archives.parsed.json | 4 +-- .../core__archives__showPostCounts.html | 2 +- .../core__archives__showPostCounts.json | 3 +-- ...core__archives__showPostCounts.parsed.json | 4 +-- .../full-content/server-registered.json | 2 +- 9 files changed, 28 insertions(+), 19 deletions(-) diff --git a/packages/block-library/src/archives/index.js b/packages/block-library/src/archives/index.js index c2917ebfa873e..9d0f780d46440 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' ].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 5386a4fea15a4..adcc61c233b7a 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'] ) ) { @@ -111,17 +120,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/test/integration/full-content/fixtures/core__archives.html b/test/integration/full-content/fixtures/core__archives.html index 68bda3aaef3fd..dbed6fec172dc 100644 --- a/test/integration/full-content/fixtures/core__archives.html +++ b/test/integration/full-content/fixtures/core__archives.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/test/integration/full-content/fixtures/core__archives.json b/test/integration/full-content/fixtures/core__archives.json index 0caf2ec732a3d..ad43f4051a739 100644 --- a/test/integration/full-content/fixtures/core__archives.json +++ b/test/integration/full-content/fixtures/core__archives.json @@ -4,9 +4,8 @@ "name": "core/archives", "isValid": true, "attributes": { - "showPostCounts": false, "displayAsDropdown": false, - "align": "none" + "showPostCounts": false }, "innerBlocks": [], "originalContent": "" diff --git a/test/integration/full-content/fixtures/core__archives.parsed.json b/test/integration/full-content/fixtures/core__archives.parsed.json index f883870399030..fab690ff93afd 100644 --- a/test/integration/full-content/fixtures/core__archives.parsed.json +++ b/test/integration/full-content/fixtures/core__archives.parsed.json @@ -2,8 +2,8 @@ { "blockName": "core/archives", "attrs": { - "showPostCounts": false, - "displayAsDropdown": false + "displayAsDropdown": false, + "showPostCounts": false }, "innerBlocks": [], "innerHTML": "" diff --git a/test/integration/full-content/fixtures/core__archives__showPostCounts.html b/test/integration/full-content/fixtures/core__archives__showPostCounts.html index bd1c93d1e1d33..cce02a6a1a784 100644 --- a/test/integration/full-content/fixtures/core__archives__showPostCounts.html +++ b/test/integration/full-content/fixtures/core__archives__showPostCounts.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/test/integration/full-content/fixtures/core__archives__showPostCounts.json b/test/integration/full-content/fixtures/core__archives__showPostCounts.json index 76d086c472d07..0c1514e413a61 100644 --- a/test/integration/full-content/fixtures/core__archives__showPostCounts.json +++ b/test/integration/full-content/fixtures/core__archives__showPostCounts.json @@ -4,9 +4,8 @@ "name": "core/archives", "isValid": true, "attributes": { - "showPostCounts": true, "displayAsDropdown": false, - "align": "none" + "showPostCounts": true }, "innerBlocks": [], "originalContent": "" diff --git a/test/integration/full-content/fixtures/core__archives__showPostCounts.parsed.json b/test/integration/full-content/fixtures/core__archives__showPostCounts.parsed.json index b016ecf02288d..cd58cbf96924d 100644 --- a/test/integration/full-content/fixtures/core__archives__showPostCounts.parsed.json +++ b/test/integration/full-content/fixtures/core__archives__showPostCounts.parsed.json @@ -2,8 +2,8 @@ { "blockName": "core/archives", "attrs": { - "showPostCounts": true, - "displayAsDropdown": false + "displayAsDropdown": false, + "showPostCounts": true }, "innerBlocks": [], "innerHTML": "" diff --git a/test/integration/full-content/server-registered.json b/test/integration/full-content/server-registered.json index ae3a565090857..0434a63b6634b 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":{"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"}}}}