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

Categories block: fix alignment #9829

Merged
merged 1 commit into from
Oct 15, 2018
Merged

Categories block: fix alignment #9829

merged 1 commit into from
Oct 15, 2018

Conversation

ZebulanStanphill
Copy link
Member

Description

This PR fixes an issue where the Categories block would always use the aligncenter class regardless of what alignment you set. It also cleans up some of the code to make it more readable and consistent.

Fixes #7910.

@ZebulanStanphill ZebulanStanphill changed the title Fix Categories block alignment Categories block: fix alignment Sep 12, 2018
@chrisvanpatten chrisvanpatten added the [Type] Enhancement A suggestion for improvement. label Sep 14, 2018
@ZebulanStanphill
Copy link
Member Author

Could this be milestoned for 4.1? It's been ready-to-merge (aside from having no reviews) for a month now. Also, the enhancement label is not really correct. This is a bug fix.

@Soean Soean added this to the 4.1 milestone Oct 14, 2018
Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

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

Confirmed this fixes the observed bug. 👍

Noted some potential ideas for future enhancements to consider.

@@ -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 ) ) {
Copy link
Member

Choose a reason for hiding this comment

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

I agree we shouldn't want to recreate validation in the render callback. Ideally this is validated at the attribute definition, i.e. via enum.

I expect this is encompassed in part by #2751.

Separately, we can plan to support enum validation in the client implementation. Maybe a near-term compromise is adding expected alignments as an enum in the attribute definition to be ready when this is "turned on". Though, ideally this would be handled automatically when opting into align supports, not the responsibility of each block implementer to define.

Copy link
Member Author

Choose a reason for hiding this comment

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

@aduth I'm guessing this is probably affected by #2751, but what exactly is the correct way to define attributes for blocks with server-side rendering? I've seen core blocks define them in JS, PHP, and even both.

Copy link
Member

Choose a reason for hiding this comment

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

The register_block_type PHP function can accept the same options as what exists in the client today. They are passed down and shallowly† merged with client registration. With #2751, the idea is that the server would be the primary location where blocks be registered.

† All of attributes must be defined in the server or in the client, not fragments amongst both.

Copy link
Member Author

Choose a reason for hiding this comment

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

@aduth In that case, I guess registering attributes in PHP is the right move for blocks that already have an index.php. I think there are currently still some blocks that use server-side rendering but define their attributes in JS. I plan on making some PRs to fix that.

One more question, though. These blocks also use getEditWrapperProps in JS, so if you use enum to define the valid values in PHP, then you end up defining the valid alignments in 2 different places. So would it be a good idea to move getEditWrapperProps to index.php so that you can use and reference a constant defining the valid alignments in a single place, or is there a good reason for it to stay in index.js?

Copy link
Member

Choose a reason for hiding this comment

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

My hope is to actually kill off getEditWrapperProps (example).

I don't think we want to be validating there either. As-is, I think it'd be sufficient to just pass through any non-undefined as data-align, not too much unlike how we've done with the frontend class rendering here?

Copy link
Member Author

Choose a reason for hiding this comment

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

@aduth Alright then, I have created a new PR to do just that and move the attributes from JS to PHP for the Categories block: #10635.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Alignment: categories block forces aligncenter regardless of what is selected in the toolbar
4 participants