Skip to content

Commit

Permalink
Archives block: fix alignment and custom class issues (#9696)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZebulanStanphill authored and youknowriad committed Sep 12, 2018
1 parent a0dfb14 commit 77ff8e6
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/block-library/src/archives/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
},
Expand Down
25 changes: 18 additions & 7 deletions packages/block-library/src/archives/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ) ) {

Expand Down Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion test/integration/full-content/fixtures/core__archives.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!-- wp:archives {"showPostCounts":false,"displayAsDropdown":false} /-->
<!-- wp:archives {"displayAsDropdown":false,"showPostCounts":false} /-->
3 changes: 1 addition & 2 deletions test/integration/full-content/fixtures/core__archives.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
"name": "core/archives",
"isValid": true,
"attributes": {
"showPostCounts": false,
"displayAsDropdown": false,
"align": "none"
"showPostCounts": false
},
"innerBlocks": [],
"originalContent": ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
{
"blockName": "core/archives",
"attrs": {
"showPostCounts": false,
"displayAsDropdown": false
"displayAsDropdown": false,
"showPostCounts": false
},
"innerBlocks": [],
"innerHTML": ""
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!-- wp:archives {"showPostCounts":true,"displayAsDropdown":false} /-->
<!-- wp:archives {"displayAsDropdown":false,"showPostCounts":true} /-->
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
"name": "core/archives",
"isValid": true,
"attributes": {
"showPostCounts": true,
"displayAsDropdown": false,
"align": "none"
"showPostCounts": true
},
"innerBlocks": [],
"originalContent": ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
{
"blockName": "core/archives",
"attrs": {
"showPostCounts": true,
"displayAsDropdown": false
"displayAsDropdown": false,
"showPostCounts": true
},
"innerBlocks": [],
"innerHTML": ""
Expand Down
2 changes: 1 addition & 1 deletion test/integration/full-content/server-registered.json
Original file line number Diff line number Diff line change
@@ -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"}}}}
{"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"}}}}

0 comments on commit 77ff8e6

Please sign in to comment.