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

Latest Posts block: use align supports flag + add left/right align support #10707

Closed
wants to merge 2 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
23 changes: 4 additions & 19 deletions packages/block-library/src/archives/edit.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
/**
* WordPress dependencies
*/
import { Fragment } from '@wordpress/element';
import {
Disabled,
PanelBody,
ToggleControl,
Disabled,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import {
InspectorControls,
BlockAlignmentToolbar,
BlockControls,
ServerSideRender,
} from '@wordpress/editor';
import { Fragment } from '@wordpress/element';
import { __ } from '@wordpress/i18n';

export default function ArchivesEdit( { attributes, setAttributes } ) {
const { align, showPostCounts, displayAsDropdown } = attributes;
const { displayAsDropdown, showPostCounts } = attributes;

return (
<Fragment>
Expand All @@ -38,15 +32,6 @@ export default function ArchivesEdit( { attributes, setAttributes } ) {
/>
</PanelBody>
</InspectorControls>
<BlockControls>
<BlockAlignmentToolbar
value={ align }
onChange={ ( nextAlign ) => {
setAttributes( { align: nextAlign } );
} }
controls={ [ 'left', 'center', 'right' ] }
/>
</BlockControls>
<Disabled>
<ServerSideRender block="core/archives" attributes={ attributes } />
</Disabled>
Expand Down
8 changes: 1 addition & 7 deletions packages/block-library/src/archives/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,10 @@ export const settings = {
category: 'widgets',

supports: {
align: true,
html: false,
},

getEditWrapperProps( attributes ) {
const { align } = attributes;
if ( [ 'left', 'center', 'right' ].includes( align ) ) {
return { 'data-align': align };
}
},

edit,

save() {
Expand Down
1 change: 1 addition & 0 deletions packages/block-library/src/archives/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ function register_block_core_archives() {
'attributes' => array(
'align' => array(
'type' => 'string',
'enum' => array( 'left', 'center', 'right', 'wide', 'full' ),
),
'className' => array(
'type' => 'string',
Expand Down
8 changes: 1 addition & 7 deletions packages/block-library/src/latest-posts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,10 @@ export const settings = {
keywords: [ __( 'recent posts' ) ],

supports: {
align: true,
html: false,
},

getEditWrapperProps( attributes ) {
const { align } = attributes;
if ( [ 'left', 'center', 'right', 'wide', 'full' ].includes( align ) ) {
return { 'data-align': align };
}
},

edit,

save() {
Expand Down
33 changes: 17 additions & 16 deletions packages/block-library/src/latest-posts/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,23 @@ function render_block_core_latest_posts( $attributes ) {

$class = 'wp-block-latest-posts';
if ( isset( $attributes['align'] ) ) {
$class .= ' align' . $attributes['align'];
$class .= " align{$attributes['align']}";
}

if ( isset( $attributes['postLayout'] ) && 'grid' === $attributes['postLayout'] ) {
$class .= ' is-grid';
}

if ( isset( $attributes['columns'] ) && 'grid' === $attributes['postLayout'] ) {
$class .= ' columns-' . $attributes['columns'];
$class .= " columns-{$attributes['columns']}";
}

if ( isset( $attributes['displayPostDate'] ) && $attributes['displayPostDate'] ) {
$class .= ' has-dates';
}

if ( isset( $attributes['className'] ) ) {
$class .= ' ' . $attributes['className'];
$class .= " {$attributes['className']}";
}

$block_content = sprintf(
Expand All @@ -90,31 +90,24 @@ function register_block_core_latest_posts() {
'core/latest-posts',
array(
'attributes' => array(
'align' => array(
'type' => 'string',
'enum' => array( 'left', 'center', 'right', 'wide', 'full' ),
),
'categories' => array(
'type' => 'string',
),
'className' => array(
'type' => 'string',
),
'postsToShow' => array(
'columns' => array(
'type' => 'number',
'default' => 5,
'default' => 3,
),
'displayPostDate' => array(
'type' => 'boolean',
'default' => false,
),
'postLayout' => array(
'type' => 'string',
'default' => 'list',
),
'columns' => array(
'type' => 'number',
'default' => 3,
),
'align' => array(
'type' => 'string',
),
'order' => array(
'type' => 'string',
'default' => 'desc',
Expand All @@ -123,6 +116,14 @@ function register_block_core_latest_posts() {
'type' => 'string',
'default' => 'date',
),
'postLayout' => array(
'type' => 'string',
'default' => 'list',
),
'postsToShow' => array(
'type' => 'number',
'default' => 5,
),
),
'render_callback' => 'render_block_core_latest_posts',
)
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":{"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"}}}}
{"core\/block":{"attributes":{"ref":{"type":"number"}}},"core\/archives":{"attributes":{"align":{"type":"string","enum":["left","center","right","wide","full"]},"className":{"type":"string"},"displayAsDropdown":{"type":"boolean","default":false},"showPostCounts":{"type":"boolean","default":false}}},"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\/latest-posts":{"attributes":{"align":{"type":"string","enum":["left","center","right","wide","full"]},"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}}}}