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

Backport PHP parts of sticky position block support #3973

Conversation

andrewserong
Copy link
Contributor

@andrewserong andrewserong commented Feb 3, 2023

This PR backports the PHP parts of the new sticky position block support, and is a follow-on from #3865

Backports the PHP parts of the following PRs:

Notes on this backport:

  • The backport deviates from Gutenberg trunk in one way: fixed position type is excluded from the appearance tools opt-in: this is because fixed positioning isn't being opted-in for the Group block and isn't ready to be used as a default opt-in. The code paths exist for fixed positioning as it will be supported in the future, but for now, sticky is the only one exposed by default. (The overall block support should still support it as a valid value, though)
  • The styling output while logged in depends on the JS packages update, as it will include the CSS changes in #47665, so while testing this PR you might notice an odd styling issue while logged in. This should be resolved once the package update lands.
  • With the above caveat shouldn't really be an issue though, as there is no way for a user to set a group block to sticky without the JS packages landing. This PR is to land the required PHP changes in advance of that.

Screenshots:

While logged in (CSS variable that's included in JS packages update isn't yet output in this PR, once it is the sticky block will sit below the admin bar) While not logged in (correct)
image image

Testing instructions:

  • In the Group block's block.json file add a "position": { "sticky": true } object under "supports" (Note: for this change to propagate in your testing, you might need to rebuild the block JSON cache locally).
  • Create a post and add a bunch of paragraphs.
  • Insert the below markup at the beginning of the post (this is Group block markup with the appropriate position style object to stick to the top of the page when scrolling).
  • Publish the post, and on the site frontend, the group block should stick to the top of the screen once it has been scrolled past the top of the screen (the block sticks to the scrollable area of its container)

Group block markup for testing purposes:

<!-- wp:group {"style":{"spacing":{"padding":{"top":"1em","right":"1em","bottom":"1em","left":"1em"}},"color":{"background":"#f2aeae"},"position":{"type":"sticky","top":"0px"}},"layout":{"type":"default"}} -->
<div class="wp-block-group has-background" style="background-color:#f2aeae;padding-top:1em;padding-right:1em;padding-bottom:1em;padding-left:1em"><!-- wp:paragraph -->
<p>A paragraph in a sticky group</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group -->

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


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.

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

@andrewserong Looks almost good to go, after reviewing this and cross-checking the relevant already approved/merged Gutenberg PRs.

Does this have to wait for the JS package update, or can it be committed to core before already?

src/wp-includes/class-wp-theme-json.php Show resolved Hide resolved
@andrewserong
Copy link
Contributor Author

Thanks for reviewing @felixarntz!

Does this have to wait for the JS package update, or can it be committed to core before already?

This can be committed before the JS package update, since this PR doesn't opt any of the blocks into the new control, so it doesn't expose anything to a user. I think it's preferable to land this PR first, so that when the JS packages update happens, the PHP parts will already be in place.

Copy link
Member

@mukeshpanchal27 mukeshpanchal27 left a comment

Choose a reason for hiding this comment

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

Thanks @andrewserong, Left nit-pick feedback and questions.

*
* @param string $block_content Rendered block content.
* @param array $block Block object.
* @return string Filtered block content.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @return string Filtered block content.
* @return string Filtered block content.

Per PHP Documentation Standards no needs to add spaces for return doc.

Comment on lines +121 to +123
/*
* Add to the style engine store to enqueue and render position styles.
*/
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/*
* Add to the style engine store to enqueue and render position styles.
*/
// Add to the style engine store to enqueue and render position styles.

Use a single-line comment instead of a multiline comment for single-line documents. 

$this->theme_root = realpath( DIR_TESTDATA . '/themedir1' );
$this->orig_theme_dir = $GLOBALS['wp_theme_directories'];

// /themes is necessary as theme.php functions assume /themes is the root if there is only one root.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// /themes is necessary as theme.php functions assume /themes is the root if there is only one root.
// '/themes' is necessary as theme.php functions assume '/themes' is the root if there is only one root.


if (
! $has_position_support ||
empty( $block['attrs']['style']['position'] )
Copy link
Member

Choose a reason for hiding this comment

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

Instead of empty shell we use isset? What do you think?

Comment on lines +59 to +64
if ( true === $theme_has_sticky_support ) {
$allowed_position_types[] = 'sticky';
}
if ( true === $theme_has_fixed_support ) {
$allowed_position_types[] = 'fixed';
}
Copy link
Member

Choose a reason for hiding this comment

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

Do we needs to bail early if the position is not sticky or fixed?

@dream-encode
Copy link
Contributor

Merged into core in https://core.trac.wordpress.org/changeset/55285.

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.

4 participants