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

Enable block registration by specifying the path to block.json #32697

Merged
merged 16 commits into from
Sep 6, 2023

Conversation

monsieur-z
Copy link
Contributor

@monsieur-z monsieur-z commented Aug 25, 2023

See #32602

Proposed changes:

Allows the registration of blocks by passing the path to the block.json metadata file to Blocks::jetpack_register_block.

In more details:

  • In PHP
    • Update Blocks::jetpack_register_block and Jetpack_Gutenberg::load_assets_as_required to accept a path as first argument
    • Add helper methods
    • Add unit tests
  • In JS
    • Make sure the beta mention is only rendered once
    • Make registerJetpackBlock accept both prefixed and unprefixed names

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

pedMtX-RS-p2

Does this pull request change what data or activity we track or use?

No.

Testing instructions:

Regression testing:

  • Check that Jetpack blocks are still working as expected

Functional testing:

@github-actions
Copy link
Contributor

github-actions bot commented Aug 25, 2023

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WordPress.com Simple site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta > Jetpack and enable the add/enable-block-registration-by-path branch.

  • To test on Simple, run the following command on your sandbox:

    bin/jetpack-downloader test jetpack add/enable-block-registration-by-path
    

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions github-actions bot added [Package] Blocks [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] In Progress labels Aug 25, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Aug 25, 2023

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ⚠️ All commits were linted before commit.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team Review" label and ask someone from your team review the code. Once reviewed, it can then be merged.
If you need an extra review from someone familiar with the codebase, you can update the labels from "[Status] Needs Team Review" to "[Status] Needs Review", and in that case Jetpack Approvers will do a final review of your PR.


Jetpack plugin:

  • Next scheduled release: September 19, 2023.
  • Scheduled code freeze: September 11, 2023.

@@ -99,7 +115,53 @@ function () use ( $feature_name, $method_name ) {
}
}

return register_block_type( $slug, $args );
return register_block_type( isset( $block_type ) ? $block_type : $slug, $args );
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a small nitpick, maybe we could avoid using the ternary operator inside the function call and instead declare some new variable using it there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing. I'm just curious why: is it a WordPress or A8C best practice?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if it is a formal "best practice", but I can see where it is harder to parse while reading what is being returned with the operator in there.

Copy link
Contributor

@andrii-lysenko andrii-lysenko left a comment

Choose a reason for hiding this comment

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

The changes looks reasonable and good aside of some questions. However, I'm not having as much experience so suggest for an additional pair of eyes on this one. Maybe @jeherve or @kraftbj could take a look?

@kraftbj kraftbj self-requested a review August 28, 2023 19:32
@jeherve jeherve added [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Pri] Normal labels Aug 29, 2023
@monsieur-z monsieur-z force-pushed the add/enable-block-registration-by-path branch 2 times, most recently from bfcfea7 to 100c54d Compare August 31, 2023 17:07
@kraftbj
Copy link
Contributor

kraftbj commented Sep 1, 2023

Unit test failures

Unexpected incorrect usage notice for jetpack_register_block.
Prefix the block with jetpack/ (This message was added in version Jetpack 9.0.0.)
Unexpected incorrect usage notice for WP_Block_Type_Registry::register.
Block type names must contain a namespace prefix. Example: my-plugin/my-custom-block-type (This message was added in version 5.0.0.)
Failed asserting that an array is empty.

@kraftbj kraftbj added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! and removed [Status] Needs Team Review labels Sep 1, 2023
jeherve
jeherve previously approved these changes Sep 6, 2023
Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

This looks good to me now, it should be good to go imo!

@jeherve jeherve added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Team Review labels Sep 6, 2023
Co-authored-by: Jeremy Herve <jeremy@jeremy.hu>
@monsieur-z monsieur-z merged commit 97c70c3 into trunk Sep 6, 2023
52 of 53 checks passed
@monsieur-z monsieur-z deleted the add/enable-block-registration-by-path branch September 6, 2023 14:37
@github-actions github-actions bot added this to the jetpack/12.6 milestone Sep 6, 2023
@github-actions github-actions bot removed the [Status] Ready to Merge Go ahead, you can push that green button! label Sep 6, 2023
SiobhyB pushed a commit that referenced this pull request Oct 31, 2023
Following #32697, 'registerJetpackBlockFromMetadata' is now used to register some Jetpack blocks from metadata. As such, we need to support that functionality on native.

With this commit, the function has been copied/pasted to the native file for use registering Jetpack blocks in the app.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Blocks [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Pri] Normal [Tests] Includes Tests [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants