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

Forms: update form field and button blocks to support content only mode #41411

Merged
merged 4 commits into from
Feb 4, 2025

Conversation

talldan
Copy link
Contributor

@talldan talldan commented Jan 30, 2025

Closes #40955, see also #40040

Proposed changes:

Makes the field and button blocks editable when using contentOnly editing.

To achieve this, certain block attributes (ones that are considered 'content') now have the role: content property added to them. This allows contentOnly mode to identify which blocks contain content, and make them editable (but with a pared back interface).

This is useful for a couple of different editing modes:

  • If a form is within a group that has templateLock: 'contentOnly' set on it.
  • If the experimental Write Mode feature is enabled and active, form fields are now editable.

At the moment, this is about all that can be achieved with the APIs currently available in Gutenberg and WordPress core.

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)?

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

No

Testing instructions:

The main thing to check is that every field block type works as expected.

templateLock: contentOnly

  1. For this test you need a group block inserted with the "templateLock": "contentOnly" attribute. That group should contain a form, and that form should have pretty much every field type added. I've included the block markup for you so that you can copy/paste it into the 'Code Editor' within the block editor. Expand below to view and copy it:
Expand here to view/copy block markup
<!-- wp:group {"layout":{"type":"constrained"},"templateLock":"contentOnly"} -->
<div class="wp-block-group">
<!-- wp:jetpack/contact-form {"style":{"spacing":{"padding":{"top":"16px","right":"16px","bottom":"16px","left":"16px"}}}} -->
<div class="wp-block-jetpack-contact-form" style="padding-top:16px;padding-right:16px;padding-bottom:16px;padding-left:16px">
<!-- wp:jetpack/field-text /-->
<!-- wp:jetpack/field-name /-->
<!-- wp:jetpack/field-email /-->
<!-- wp:jetpack/field-url /-->
<!-- wp:jetpack/field-date /-->
<!-- wp:jetpack/field-telephone /-->
<!-- wp:jetpack/field-textarea {"label":""} /-->
<!-- wp:jetpack/field-checkbox /-->
<!-- wp:jetpack/field-consent /-->
<!-- wp:jetpack/field-radio -->
<div class="wp-block-jetpack-field-radio">
<!-- wp:jetpack/field-option-radio /-->
</div>
<!-- /wp:jetpack/field-radio -->
<!-- wp:jetpack/field-checkbox-multiple -->
<div class="wp-block-jetpack-field-checkbox-multiple">
<!-- wp:jetpack/field-option-checkbox /-->
</div>
<!-- /wp:jetpack/field-checkbox-multiple -->
<!-- wp:jetpack/field-select {"label":"","toggleLabel":"Select one option"} /-->
<!-- wp:jetpack/button {"element":"button","text":"Contact Us","lock":{"remove":true}} /--></div>
<!-- /wp:jetpack/contact-form -->
</div>
<!-- /wp:group -->
  1. Click the fields and try to edit each one. Pretty much every field should be updatable, with a few minor exceptions:
  • The block inspector for each field can't be reached (which is currently by design).
  • New single-choice radio or multi-choice checkboxes can't be added/removed. This is a limitation in core that's also present with blocks like List as well.
  • The form block itself is not selectable (another limitation). We can technically also add role: content to the form block, but the UI ends up a bit buggy, as contentOnly doesn't properly support parent blocks that have this role.

Write Mode

  1. For this you need to enable a Gutenberg experiment, so a local dev environment that has the Gutenberg plugin installed is probably the best place to test. From wp-admin, navigate to Gutenberg > Experiments and toggle on the 'Simplified site editing' experiment.
  2. Open the Site Editor and edit a template like the Homepage/Blog Home.
  3. On the top bar, between the + button and the 'Undo' button, you should see a 'Tools' dropdown. Open this and ensure 'Design' is selected.
  4. Open List View. If you're in a template, in most themes you'll have a Header, Group, and Footer as the top level blocks. Insert a Form into the Group, and add every type of field and a button to the form.
  5. Open the tools dropdown again and switch to 'Design'
  6. Now try editing the form, you should see it works similarly to the 'contentOnly' template lock test above. For this test, the Form block should be selectable if it was inserted in the write place (this is because it's considered a 'section', and it's a little hard to explain!).

@talldan talldan added [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] Needs Team Review [Block] Contact Form Form block (also see Contact Form label) [Package] Forms labels Jan 30, 2025
@talldan talldan self-assigned this Jan 30, 2025
Copy link
Contributor

github-actions bot commented Jan 30, 2025

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, select your plugin, and enable the update/form-blocks-for-content-only-mode branch.

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

    bin/jetpack-downloader test jetpack update/form-blocks-for-content-only-mode
    

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 [Block] Button [Feature] Contact Form [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ labels Jan 30, 2025
Copy link
Contributor

github-actions bot commented Jan 30, 2025

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.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ 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.


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Choose a review path based on your changes:
    • A. Team Review: add the "[Status] Needs Team Review" label
      • For most changes, including minor cross-team impacts.
      • Example: Updating a team-specific component or a small change to a shared library.
    • B. Crew Review: add the "[Status] Needs Review" label
      • For significant changes to core functionality.
      • Example: Major updates to a shared library or complex features.
    • C. Both: Start with Team, then request Crew
      • For complex changes or when you need extra confidence.
      • Example: Refactor affecting multiple systems.
  3. Get at least one approval before merging.

Still unsure? Reach out in #jetpack-developers for guidance!


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen semi-continuously (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly. The next release is scheduled for February 4, 2025 (scheduled code freeze on February 4, 2025).

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

Copy link
Contributor

github-actions bot commented Jan 30, 2025

Code Coverage Summary

This PR did not change code coverage!

That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷

Full summary · PHP report · JS report

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.

Looks good and works well! Thanks!

image

@talldan talldan force-pushed the update/form-blocks-for-content-only-mode branch from a407cee to 3946192 Compare February 3, 2025 08:04
@talldan talldan merged commit 6c3d061 into trunk Feb 4, 2025
64 checks passed
@talldan talldan deleted the update/form-blocks-for-content-only-mode branch February 4, 2025 02:22
@github-actions github-actions bot added this to the jetpack/14.2.2 milestone Feb 4, 2025
@tbradsha tbradsha modified the milestones: jetpack/14.2.2, jetpack/14.4 Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Button [Block] Contact Form Form block (also see Contact Form label) [Feature] Contact Form [Package] Forms [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [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.

Forms block: cannot edit the field text in contentOnly mode
3 participants