Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Archives block alignment and custom class bugs #9696

Merged
merged 1 commit into from
Sep 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not certain declaring this one is necessary here because there's a hook adding this attribute. Though one could think the hook is only declared on JavaScript which means nothing guarantees that it's available in PHP (which hopefully the server-side awareness work should resolve)

'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"}}}}