Update form block to use block.json for server-side block registration #41568
+46
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposed changes:
Proposes using the block.json for the contact form block's PHP block registration.
Currently for the contact form block:
jetpack/projects/packages/forms/src/blocks/contact-form/index.js
Lines 37 to 107 in 4967a2f
jetpack/projects/packages/forms/src/blocks/contact-form/block.json
Lines 1 to 26 in 4967a2f
jetpack/projects/packages/forms/src/blocks/contact-form/class-contact-form-block.php
Lines 26 to 32 in 4967a2f
The impact of the third one is that the block doesn't declare any of its block
supports
properties orattribute
definitions (no default values) for the server side implementation of the block. It hasn't caused an issue right now, but for #41428, layout support would have to be triplicated across all three places.Looking at other blocks in the jetpack codebase, it seems the PHP registration (3) can use the values from the block.json by passing an absolute path with the location of the file to
jetpack_register_block
method instead of the block name. This PR uses the__DIR__
constant to do that, just like other blocks do.I'm not sure if there are any unwanted side effects from doing this, but I thought I'd make a PR to propose it ... I still need to test it on WPCOM, but hopefully it works there too.
In the future, it might be nice to be able to import the JSON values into the JS block registration code too so that there's a single source of truth, but perhaps that will require some updates to the jetpack build code.
Other information:
Does this pull request change what data or activity we track or use?
No
Testing instructions: