Skip to content

Fix post editor layout when content block has no attributes.#5221

Closed
tellthemachines wants to merge 10 commits into
WordPress:trunkfrom
tellthemachines:fix/post-content-layout
Closed

Fix post editor layout when content block has no attributes.#5221
tellthemachines wants to merge 10 commits into
WordPress:trunkfrom
tellthemachines:fix/post-content-layout

Conversation

@tellthemachines

Copy link
Copy Markdown
Contributor

Trac ticket: https://core.trac.wordpress.org/ticket/59358

This PR syncs the changes from WordPress/gutenberg#54485 and adds a test for the Post Content block with empty attributes.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@felixarntz felixarntz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for the PR @tellthemachines. One thing looks off to me here as far as I can tell.

Comment thread src/wp-includes/block-editor.php
switch_theme( 'block-theme-post-content-default' );

$this->assertSame( $attributes_empty, wp_get_post_content_block_attributes() );
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Related to my above feedback, maybe add another test for get_block_editor_settings(), to check that it doesn't include the postContentAttributes field if the post block attributes aren't set.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The original test already checks the return value for classic themes (when Post Content doesn't exist), do you think it would be worth splitting that check out into its own test?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@tellthemachines I meant a test for the get_block_editor_settings() change. As far as I can tell, there isn't one at the moment.

There is https://github.com/WordPress/wordpress-develop/blob/trunk/tests/phpunit/tests/blocks/editor.php#L524 which checks the presence of postContentAttributes, so I think we should add another test where we force wp_get_post_content_block_attributes() to return null, and then assert that get_block_editor_settings() does not include the postContentAttributes key.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh got it! Yeah that's a good idea.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a test in 0e75e53

Comment thread tests/phpunit/tests/blocks/editor.php Outdated
tellthemachines and others added 3 commits September 18, 2023 12:08
remove variable

Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>

@mukeshpanchal27 mukeshpanchal27 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @tellthemachines for the PR. Left some nit-pick document and unit test changes.

Comment thread tests/phpunit/tests/blocks/editor.php Outdated
Comment thread tests/phpunit/tests/blocks/editor.php Outdated
Comment thread src/wp-includes/block-editor.php Outdated
* Retrieves Post Content block attributes from the current post template.
*
* @since 6.3.0
* @since 6.4.0 return null by default and return empty array when Post Content block exists. but has no attributes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
* @since 6.4.0 return null by default and return empty array when Post Content block exists. but has no attributes.
* @since 6.4.0 return null by default or an empty array when the Post Content block exists. but has no attributes.

tellthemachines and others added 3 commits September 18, 2023 15:46
Use assertNull

Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
Update doc.

Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
switch_theme( 'block-theme-post-content-default' );

$this->assertSame( $attributes_empty, wp_get_post_content_block_attributes() );
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@tellthemachines I meant a test for the get_block_editor_settings() change. As far as I can tell, there isn't one at the moment.

There is https://github.com/WordPress/wordpress-develop/blob/trunk/tests/phpunit/tests/blocks/editor.php#L524 which checks the presence of postContentAttributes, so I think we should add another test where we force wp_get_post_content_block_attributes() to return null, and then assert that get_block_editor_settings() does not include the postContentAttributes key.

Comment thread src/wp-includes/block-editor.php Outdated
tellthemachines and others added 2 commits September 19, 2023 12:04
SImplify doc

Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>

@felixarntz felixarntz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for the updates @tellthemachines, LGTM!

@tellthemachines

Copy link
Copy Markdown
Contributor Author

Thanks for the reviews! Committed in r56629.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants