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

Gutenblocks: add new utility to get all classes for a given block #13302

Merged
merged 5 commits into from
Aug 26, 2019

Conversation

jeherve
Copy link
Member

@jeherve jeherve commented Aug 22, 2019

Fixes #13257

Changes proposed in this Pull Request:

  • We previously fetched different classes in each block rendering function, from multiple places (the block's name, the block's alignment settings, the block's extra CSS classes that can be defined in the sidebar, and sometimes our own extra classes). This PR centralizes things into a common function that can be used by other blocks in the future.
  • This PR also changes the default alignment for the Mailchimp and the GIF block. Until now we defaulted to a center alignment, which may not be the expected default. Thus this fixes Mailchimp block: Hardcoded alignment setting #13257.

Testing instructions:

  • You can test this PR by inserting a GIF, Recurring Payments, Mailchimp, and / or Repeat Visitor block in the block editor.
  • After inserting the block, you can preview your post.
  • You can check the block's markup and make sure the overall div container displays at least the main block class, wp-block-jetpack-blockname.
  • You should not see an aligncenter class name by default.
  • Back in the block editor, try making some changes to your block:
    • Add a custom class using the CSS class input field at the bottom of the editor sidebar when the block is selected.
    • Define an alignment for your block when it's offered.
  • You will want to make sure those extra fields appear in the block markup in the preview.

Proposed changelog entry for your changes:

  • Blocks: add new utility to get all classes for a given block.

@jeherve jeherve added [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. [Pri] Normal [Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack [Block] Payment Button aka Recurring Payments [Block] GIF [Block] Mailchimp [Block] Repeat Visitor labels Aug 22, 2019
@jeherve jeherve added this to the 7.7 milestone Aug 22, 2019
@jeherve jeherve requested review from a team August 22, 2019 15:35
@jeherve jeherve self-assigned this Aug 22, 2019
@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello jeherve! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer, review, and approve D31844-code before merging this PR. Thank you!

@jetpackbot
Copy link

jetpackbot commented Aug 22, 2019

Thank you for the great PR description!

When this PR is ready for review, please apply the [Status] Needs Review label. If you are an a11n, please have someone from your team review the code if possible. The Jetpack team will also review this PR and merge it to be included in the next Jetpack release.

Scheduled Jetpack release: September 3, 2019.
Scheduled code freeze: August 27, 2019

Generated by 🚫 dangerJS against 6694fae

@simison
Copy link
Member

simison commented Aug 23, 2019

@jeffersonrabb I added you as a reviewer here because I remember you were particularly interested to see this happen unless I remember wrong. but no pressure/feel free to ignore. ;-)

class.jetpack-gutenberg.php Outdated Show resolved Hide resolved
class.jetpack-gutenberg.php Outdated Show resolved Hide resolved
&& in_array( $attr['align'], array( 'left', 'center', 'right', 'wide', 'full' ), true )
) {
array_push( $classes, 'align' . $attr['align'] );
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we even have to take care of alignment? I thought we could pretty much rely on Gutenberg's supports feature for alignment... 🤔 I'll try to dig up a PR I vaguely recall where I was doing something like that...

Copy link
Member

Choose a reason for hiding this comment

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

I think some of our blocks are little old in that we handled it manually. Gutenberg's support might be purely frontend side and backend side has to be handled manually like this?

Copy link
Contributor

Choose a reason for hiding this comment

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

For reference, this is the commit I was thinking of: Automattic/wp-calypso@d675ab0

I'll see if that kind of change can be applied here...

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, nevermind, that doesn't really apply to dynamic blocks/the server side/PHP.

@matticbot
Copy link
Contributor

jeherve, Your synced wpcom patch D31844-code has been updated.

It's already specified earlier anyway.

See https://github.com/Automattic/jetpack/pull/13302/files#r316986528

Co-Authored-By: Bernie Reiter <ockham@raz.or.at>
@matticbot
Copy link
Contributor

jeherve, Your synced wpcom patch D31844-code has been updated.

simison
simison previously approved these changes Aug 23, 2019
Copy link
Member

@simison simison left a comment

Choose a reason for hiding this comment

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

Tested gif, recurring payments, repeat visitor, and Mailchimp blocks. Tested with gif's align options and with custom CSS classes for each.

Super happy to see maintenance like this. Well done!

empty does check if it is set anyway.

See #13302 (comment)
@matticbot
Copy link
Contributor

jeherve, Your synced wpcom patch D31844-code has been updated.

'wp-block-button__link',
'components-button',
'is-primary',
'is-button',
Copy link
Contributor

Choose a reason for hiding this comment

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

Not entirely sure classes like this belong into a top-level block element, that's pre-existing. (It might raise the question if the new util is really needed, or more of a symptom of suboptimal architectural choices, but oh well.)

Copy link
Contributor

@ockham ockham left a comment

Choose a reason for hiding this comment

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

LGTM 👍

It's almost curious that core doesn't provide a helper like this for dynamic blocks (and might be a worthwhile addition).


// Basic block name class.
$classes = array(
'wp-block-jetpack-' . $slug,
Copy link
Member

Choose a reason for hiding this comment

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

Just noting that (I think) setting className:false in block's supports attributes would normally disable the primary class name as well but this always enforces it.

I don't think we'll ever have any such blocks in Jetpack so it doesn't really matter, but wanted to note in case anyone looks up this PR later on for inspiration to implement this also in core Gutenberg.

@jeherve jeherve added the [Status] Needs Design Review Design has been added. Needs a review! label Aug 23, 2019
@jeherve
Copy link
Member Author

jeherve commented Aug 23, 2019

Bringing Design for a second opinion here about the default alignment for blocks.

See #13257 for a point of view on this, and p1566567543002100-slack-jetpack-plugin for another.

@jeffersonrabb
Copy link
Contributor

For reference here's how we're doing the same in Newspack, although this PR has a bit of sophistication we'll want to add to Newspack's:

https://github.com/Automattic/newspack-blocks/blob/master/newspack-blocks.php#L147-L164

@simison
Copy link
Member

simison commented Aug 26, 2019

Bringing Design for a second opinion here about the default alignment for blocks.

I think it's ok to address separate since this PR doesn't really change that behavior, right?

@jeherve
Copy link
Member Author

jeherve commented Aug 26, 2019

this PR doesn't really change that behavior, right?

It does, for the Mailchimp and the Gif blocks. See #13257 for the previous behaviour.

Copy link
Contributor

@jeffersonrabb jeffersonrabb left a comment

Choose a reason for hiding this comment

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

LGTM. The center alignment in GIF and Mailchimp was just a reasonable default, I don't think we'll miss it.

@oskosk oskosk added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Aug 26, 2019
@jeherve jeherve merged commit ef39055 into master Aug 26, 2019
@jeherve jeherve deleted the add/block-class-utility branch August 26, 2019 11:29
@matticbot matticbot added [Status] Needs Changelog and removed [Status] Ready to Merge Go ahead, you can push that green button! labels Aug 26, 2019
jeherve added a commit that referenced this pull request Aug 26, 2019
jeherve added a commit that referenced this pull request Aug 27, 2019
* 7.7 changelog: initial set of changes

* Changelog: add #13154

* Changelog: add #13134

* Changelog: add #12699 and many others

* Changelog: add #13127

* Changelog: add #13167

* Changelog: add #13225

* Changelog: add #13179

* Changelog: add #13173

* Changelog: add #13232

* Changelog: add #13137

* Changelog: add #13172

* Changelog: add #13182

* Changelog: add #13200

* Changelog: add #13244

* Changelog: add #13267

* Changelog: add #13204

* changelog: add #13205

* Changelog: add #13183

* Changelog: add #13278

* Changelog: add #13162

* Changelog: add #13268

* Changelog: add #13286

* Changelog: add #13273

* Changelog: add #12474

* Changelog: add #13085

* Changelog: add #13266

* Changelog: add #13306

* Changelog: add #13311

* Changelog: add #13302

* Changelog: add #13196

* Changelog: add #12733

* Changelog: add #13261

* Changelog: add #13322

* Changelog: add #13333

* Changelog: add #13335
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] GIF [Block] Mailchimp [Block] Payment Button aka Recurring Payments [Block] Repeat Visitor [Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack [Pri] Normal [Status] Needs Design Review Design has been added. Needs a review! Touches WP.com Files [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mailchimp block: Hardcoded alignment setting
7 participants