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

Standardize alignment options for blocks based off of WP widgets #9557

Closed
wants to merge 5 commits into from
Closed
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
1 change: 0 additions & 1 deletion packages/block-library/src/archives/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export default function ArchivesEdit( { attributes, setAttributes } ) {
onChange={ ( nextAlign ) => {
setAttributes( { align: nextAlign } );
} }
controls={ [ 'left', 'center', 'right' ] }
/>
</BlockControls>
<Disabled>
Expand Down
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', 'wide', 'full' ].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 @@ -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',
Expand Down
1 change: 0 additions & 1 deletion packages/block-library/src/categories/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ class CategoriesEdit extends Component {
onChange={ ( nextAlign ) => {
setAttributes( { align: nextAlign } );
} }
controls={ [ 'left', 'center', 'right', 'full' ] }
/>
</BlockControls>
<div className={ this.props.className }>
Expand Down
12 changes: 6 additions & 6 deletions packages/block-library/src/categories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ export const settings = {
category: 'widgets',

attributes: {
showPostCounts: {
type: 'boolean',
default: false,
align: {
type: 'string',
},
displayAsDropdown: {
type: 'boolean',
Expand All @@ -32,8 +31,9 @@ export const settings = {
type: 'boolean',
default: false,
},
align: {
type: 'string',
showPostCounts: {
type: 'boolean',
default: false,
},
},

Expand All @@ -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 };
}
},
Expand Down
13 changes: 6 additions & 7 deletions packages/block-library/src/categories/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ),
Expand All @@ -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(
Expand Down
7 changes: 3 additions & 4 deletions packages/block-library/src/latest-comments/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
),
Expand All @@ -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',
)
Expand Down
1 change: 0 additions & 1 deletion packages/block-library/src/latest-posts/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ class LatestPostsEdit extends Component {
onChange={ ( nextAlign ) => {
setAttributes( { align: nextAlign } );
} }
controls={ [ 'center', 'wide', 'full' ] }
/>
<Toolbar controls={ layoutControls } />
</BlockControls>
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/latest-posts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
},
Expand Down
6 changes: 3 additions & 3 deletions packages/block-library/src/latest-posts/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ function register_block_core_latest_posts() {
'core/latest-posts',
array(
'attributes' => array(
'align' => array(
'type' => 'string',
),
'categories' => array(
'type' => 'string',
),
Expand All @@ -105,9 +108,6 @@ function register_block_core_latest_posts() {
'type' => 'number',
'default' => 3,
),
'align' => array(
'type' => 'string',
),
'order' => array(
'type' => 'string',
'default' => 'desc',
Expand Down
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 @@ -5,8 +5,7 @@
"isValid": true,
"attributes": {
"showPostCounts": false,
"displayAsDropdown": false,
"align": "none"
"displayAsDropdown": false
},
"innerBlocks": [],
"originalContent": ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"isValid": true,
"attributes": {
"showPostCounts": true,
"displayAsDropdown": false,
"align": "none"
"displayAsDropdown": false
},
"innerBlocks": [],
"originalContent": ""
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":{"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}}}}