Skip to content
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
13 changes: 12 additions & 1 deletion packages/block-library/src/post-tags/block.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
{
"name": "core/post-tags",
"category": "design",
"attributes": {
"textAlign": {
"type": "string"
}
},
"usesContext": [ "postId", "postType" ],
"supports": {
"html": false,
"lightBlockWrapper": true
"lightBlockWrapper": true,
"__experimentalFontSize": true,
"__experimentalColor": {
"gradients": true,
"linkColor": true
},
"__experimentalLineHeight": true
}
}
36 changes: 33 additions & 3 deletions packages/block-library/src/post-tags/edit.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
import { useEntityProp } from '@wordpress/core-data';
import { Warning, __experimentalBlock as Block } from '@wordpress/block-editor';
import {
BlockControls,
Warning,
__experimentalBlock as Block,
AlignmentToolbar,
} from '@wordpress/block-editor';
import { useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';

export default function PostTagsEdit( { context } ) {
export default function PostTagsEdit( { context, attributes, setAttributes } ) {
const { textAlign } = attributes;

const [ tags ] = useEntityProp(
'postType',
context.postType,
Expand Down Expand Up @@ -65,5 +77,23 @@ export default function PostTagsEdit( { context } ) {
);
}

return <Block.div>{ display }</Block.div>;
return (
<>
<BlockControls>
<AlignmentToolbar
value={ textAlign }
onChange={ ( nextAlign ) => {
setAttributes( { textAlign: nextAlign } );
} }
/>
</BlockControls>
<Block.div
className={ classnames( {
[ `has-text-align-${ textAlign }` ]: textAlign,
} ) }
>
{ display }
</Block.div>
</>
);
}
6 changes: 5 additions & 1 deletion packages/block-library/src/post-tags/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ function render_block_core_post_tags( $attributes, $content, $block ) {
$post_tags = get_the_tags( $block->context['postId'] );
if ( ! empty( $post_tags ) ) {
$classes = 'wp-block-post-tags';
$output = sprintf( '<div class="%1$s">', esc_attr( $classes ) );
if ( isset( $attributes['textAlign'] ) ) {
$classes .= ' has-text-align-' . $attributes['textAlign'];
}

$output = sprintf( '<div class="%1$s">', esc_attr( $classes ) );

foreach ( $post_tags as $tag ) {
$output .= '<a href="' . get_tag_link( $tag->term_id ) . '">' . $tag->name . '</a>' . ' | ';
Expand Down