Skip to content

Add ability hooks so Pro can place section and repeater fields - #3760

Open
Crabcyborg wants to merge 9 commits into
masterfrom
fix/section-placement-frontend-rules
Open

Crabcyborg wants to merge 9 commits into
masterfrom
fix/section-placement-frontend-rules

Conversation

@Crabcyborg

@Crabcyborg Crabcyborg commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Fields often showed inside a repeater in the form builder but outside it on the frontend, or the other way round. Sections and repeaters are Pro fields, so the rules that fix this now live in Pro: https://github.com/Strategy11/formidable-pro/pull/7048. This PR keeps only what Lite needs: hooks for Pro to attach to, and the earlier placement when no Pro version attaches.

The first version of this PR added about 800 lines of section handling to Lite. All of it has moved to the Pro PR.

Changes

create-field

  • execute_create_field() no longer overwrites the prepared form_id, so a field that Pro moved into a repeater's child form is stored there. The cache it clears afterwards is now that form's. FrmField::create() already clears it, so this is a safety net that no test can isolate. With no Pro hook, the prepared form_id is always the requested form, so nothing changes.
  • New filter frm_ability_new_field_placement in FrmFieldPlacementHelper::place_new_ability_field(). It runs inside prepare_new_field(), so inline create-form fields go through it too. It may change form_id, field_order and field_options.in_section, or return a WP_Error.
  • With no callback on that filter, the existing maybe_position_in_repeater() placement runs. That method moved unchanged from FrmAbilitiesFieldsController to FrmFieldPlacementHelper, which keeps the controller under the 1000-line phpcs limit.
  • New FrmFieldPlacementHelper::has_ability_section_placement(). Lite uses it to pick the fallback. Pro checks that it exists before turning on any of its new behavior, so a newer Pro with an older Lite also keeps the earlier behavior.

update-field

  • New filter frm_ability_update_field_placement, after stored options are merged. A callback can change form_id or field_order, or return a WP_Error. Any other non-array return is ignored and the unfiltered data is saved. The new form's cache is also cleared, though FrmField::update() already does this, so no test shows a difference.

delete-field

  • New actions frm_ability_before_delete_field (the field still exists) and frm_ability_after_delete_field (it is gone).

create-form

  • New short-circuit filter frm_ability_create_inline_fields. Only an explicit true means a callback created the fields. A WP_Error stops the call. null or any other value keeps the existing one-at-a-time loop.
  • That loop no longer forces the requested form_id after prepare_new_field(), so a frm_ability_new_field_placement callback can move inline fields, as it can for create-field. Pro's inline filter always returns true or a WP_Error, so with the Pro PR the loop does not run.

Mixed versions

Either PR can merge first.

Lite Pro Result
this PR Pro PR New behavior: builder and abilities follow the frontend's rules
this PR current Pro Earlier behavior: no hook is attached, so Lite uses maybe_position_in_repeater() and the plain inline loop
current Lite Pro PR Earlier behavior: Pro sees no has_ability_section_placement() and registers none of its hooks, including the builder sort
current Lite current Pro Unchanged

Testing

  1. Without Pro, or with current Pro, call create-field on a repeater's child form with no field_order. The field goes right after the repeater's last field, and later fields move down, as before.
  2. With the Pro PR active, follow the Pro PR's testing steps.

Local results

  • test_FrmAbilitiesFieldPlacement (12 tests) covers the fallback, each hook's return value being used, WP_Error from each hook, a false inline-filter return, a null update-filter return, and the placement filter moving inline fields. Mutation check: removing the fallback, restoring either form_id overwrite, removing the update filter or its non-array guard, the delete actions, the inline filter, or going back to null === $created each fails the matching tests. The two cache-clear lines are not covered, because FrmField::create() and FrmField::update() clear the same cache.
  • All four version combinations in the table above were run locally (Lite placement test, Pro mcp group, Pro builder and field tests): all pass. With current Lite, the Pro PR's new tests skip and its earlier-order check passes.
  • Full Lite suite (no Pro): 1442 tests. The only failure is test_FrmAppHelper::test_plugin_folder, which fails because the local checkout folder is not named formidable.
  • phpcs, php-cs-fixer, rector, mago lint, phpstan, psalm and typos pass on every changed file.
  • Not exercised: the builder UI in a browser, and live MCP calls against a running site.

🤖 Generated with Claude Code

The frontend repeats the fields of a repeater's child form whatever
their field_order, and groups other fields into sections by order.
The builder grouped everything by order, and the field abilities let
form_id, in_section and field_order disagree, so fields showed inside
a repeater in one place and outside it in the other.

Sort builder fields by the frontend rules, and make create-field,
update-field, delete-field and create-form inline fields keep the
three in agreement, rejecting sections that cannot hold the field.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 41 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 32b46de and 352c165.

Files selected for processing: 4

  • classes/controllers/FrmAbilitiesFieldsController.php
  • classes/controllers/FrmAbilitiesFormsController.php
  • classes/helpers/FrmFieldPlacementHelper.php
  • tests/phpunit/fields/test_FrmAbilitiesFieldPlacement.php
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@franky-the-going-merry franky-the-going-merry Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approve, with two non-blocking notes. The new tests pass, the builder reordering reproduces before and after, and nothing else in the Lite suite changed.

Tests run (wordpress-develop harness, PHP 8.5, PHPUnit 9.6, the 8 PR files copied in at 27f7ab1, harness restored afterwards)

  • test_FrmSectionStructure and test_FrmAbilitiesFieldPlacement: 24 tests, 195 assertions, OK. CI runs these files too and is green on PHP 7.4 to 8.4.
  • Full Lite suite: 1444 tests with 5 errors and 2 failures: test_FrmStylesController::test_front_head, test_FrmFieldCombo, test_FrmFormTemplatesController, and 4 in test_FrmSpamCompatibility. The Field Combo, Form Templates and Spam Compatibility classes give the same 5 errors and 1 failure on a clean checkout, so none of this comes from the PR. test_front_head is the known harness failure from earlier today (WordPress wp-block-library notice).
  • Builder repro, my own PHPUnit probe (a form with a repeater whose child fields are ordered after the end_divider, then apply_filters( 'frm_fields_in_form_builder', ... )).
    • Stored order, which is what the builder gets without the PR: divider#2 end_divider#3 text#4(child) text#5(child) email#6, so the child fields land below the repeater.
    • At this head: divider#2 text#1(child) text#4(child) text#5(child) end_divider#3 email#6, so they sit inside it.
  • Mutations I ran: dropping the parent fields deferred past the end_divider in sort_for_builder() is caught (1 failure). A change that makes get_order_at_section_end() stop at the first field of the section survives (24 pass).
  • Calling prepare_new_placement() directly for a section with three fields gives order 5 and shifts the end_divider and later fields down by one, as intended. The code is right, but no test covers it (see note 1).

Notes (non-blocking)

  1. test_FrmAbilitiesFieldPlacement only appends to a section that already holds at most one field. Add a case with two or more fields in the section and no field_order, and assert the new field lands after the last one with the end_divider pushed down. That is the mutant that survives.
  2. The frontend side of the claim ("the frontend repeats a child form's fields whatever their field_order") rests on the author's Pro scratch run. Pro is not loaded in this harness, so I confirmed the builder list only.

Not exercised:

  • No browser: the builder UI, live MCP calls and a frontend render were not run.
  • The FrmProBuilderContainersHelper::get_containers() path (tabs and accordions) was not run, since Pro was not loaded.
  • PHPCS, PHPStan, Psalm, Mago and Rector: CI and the author's run cover them, and I did not repeat them.
  • I did not run the code-review, security-review or simplify skills on this PR.
  • I read the helper, the inline-fields helper and the controller changes in full. The test files and the delete-field cleanup path I checked by running them, not by reading every case.

@franky-the-going-merry franky-the-going-merry Bot removed franky-review franky-working Franky is actively reviewing this labels Nov 27, 2026
Crabcyborg and others added 4 commits November 27, 2026 13:46
Sections and repeaters are Pro fields, so the placement rules, the
builder sort and the inline section handling move to Pro. Lite keeps
hooks for Pro to attach to, and falls back to the earlier repeater
placement when no Pro version hooks in.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Crabcyborg

Copy link
Copy Markdown
Contributor Author

Note 1 (no test appends to a section holding two or more fields): fixed in 14a6e0e. New test_create_field_in_a_section_with_several_fields_is_added_after_the_last_one puts three fields in a section, creates one with no field_order, and asserts it gets order 5 with the end_divider and the field after it pushed down. It fails under the surviving mutant (get_order_at_section_end() stopping at the first field: 3 instead of 5), and the class plus test_FrmSectionStructure pass at this head (25 tests, 210 assertions).
Note 2 (frontend claim rests on the Pro scratch run): not changed, it is a note on review coverage, not a code issue.
Also merged the latest master into the branch (clean).

@franky-the-going-merry franky-the-going-merry Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approve at 14a6e0e (my Approve was at 27f7ab1). The one code-side note is closed: the new test covers appending to a section that holds several fields.

Tests run (wordpress-develop harness, PHP 8.4, PHPUnit 9.6; the PR's 8 files copied in at 14a6e0e, harness restored after)

  • test_FrmAbilitiesFieldPlacement.php: OK, 13 tests, 151 assertions. test_FrmSectionStructure.php: OK, 12 tests, 59 assertions. That matches the author's 25 tests / 210 assertions. CI runs both files and is green on PHP 7.4 to 8.4.
  • Mutation: making get_order_at_section_end() stop at the first field of the section (the mutant that survived last round) now fails test_create_field_in_a_section_with_several_fields_is_added_after_the_last_one (Failed asserting that 3 is identical to 5). Restored, all 13 pass.

The PR delta since my approval is that test only (32 lines) plus a clean merge of master; no production code changed, so my earlier read of the helper, inline-fields helper and controllers stands.

Still true from last round, and a limit on my coverage rather than a change request: the frontend half of the claim rests on the author's Pro scratch run (Pro is not loaded in this harness).

Not exercised: a browser (builder UI, live MCP calls, frontend render), the Pro FrmProBuilderContainersHelper::get_containers() path, PHPCS/PHPStan/Psalm (CI is green for them), and the code-review/security-review/simplify skills (test-only delta).

@franky-the-going-merry franky-the-going-merry Bot removed franky-review franky-working Franky is actively reviewing this labels Nov 27, 2026
Crabcyborg and others added 2 commits November 27, 2026 14:12
Moves the placement hook and the earlier repeater fallback into
FrmFieldPlacementHelper so the controller stays under the phpcs
file length limit, and narrows the filter result to its documented
type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ules' into HEAD

# Conflicts:
#	tests/phpunit/fields/test_FrmAbilitiesFieldPlacement.php
@Crabcyborg Crabcyborg changed the title Group section and repeater fields the way the frontend renders them Add ability hooks so Pro can place section and repeater fields Nov 27, 2026
@franky-the-going-merry franky-the-going-merry Bot added the franky-working Franky is actively reviewing this label Nov 27, 2026

@franky-the-going-merry franky-the-going-merry Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approve with non-blocking notes, re-reviewed at 2ffa3e8 (my Approve was at 14a6e0e).

This is a different PR from the one I approved: the ~800 lines of section handling moved to Pro (formidable-pro#7048) and Lite keeps only hooks plus the earlier repeater placement as the fallback. I re-read the whole current diff against master (4 files: FrmFieldPlacementHelper, the fields and forms ability controllers, one test file). maybe_position_in_repeater() moved unchanged from the controller to the helper. My earlier approvals and test notes were about the code that is now in Pro, so they no longer apply here.

What I ran (php@8.4, wordpress-develop harness with this head copied in as the only plugin, no Pro, throwaway DB):

  • Tests run: test_FrmAbilitiesFieldPlacement.php at 2ffa3e8 → OK, 9 tests, 59 assertions. Also test_FrmAbilitiesFieldsController.php 17 OK, test_FrmAbilitiesFormsController.php 14 OK, test_FrmAbilitiesContract.php 22 OK, test_FrmFieldPlacement.php 14 OK. CI runs the PHPUnit job on 7.4 to 8.4 and is green.
  • Mutations: no fallback in place_new_ability_field() fails test_create_field_keeps_the_earlier_repeater_placement_without_a_placement_hook; putting the $prepared['form_id'] = $form->id overwrite back fails test_create_field_stores_the_field_where_the_placement_hook_puts_it.
  • Hook edge probes (throwaway tests, removed), each via the real abilities:
    • Placement hook returning a prepared array without form_id: create-field returns the ability_callback_exception error, nothing stored.
    • Update hook returning null: update-field returns frm_field_update_failed, stored field untouched.
    • Inline hook returning false: create-form succeeds with 0 fields (note 2).
    • Placement hook that moves form_id, with no inline hook: the inline loop puts both fields back on the new form (note 3).

Non-blocking

  1. The two cache-clear lines are not covered. Replacing FrmField::delete_form_transient( $prepared['form_id'] ) with the requested form, or dropping the $field_data['form_id'] clear in execute_update_field(), leaves all 9 tests green. In a probe the moved field's destination form list was already fresh without them (FrmField::create() / update() invalidate it), so I could not make their absence visible. Keep them, but the description's wording about clearing the destination cache is not something a test shows.
  2. frm_ability_create_inline_fields skips the fields on any non-null, non-WP_Error return. The docblock says true, WP_Error or null, but __return_false (or an array) makes create-form succeed with no fields at all. In FrmAbilitiesFormsController.php use if ( true !== $created ) { for the loop so only an explicit true skips it.
  3. The inline loop still forces the requested form. $prepared['form_id'] = $form_id; in the loop runs after prepare_new_field(), so a frm_ability_new_field_placement hook that changes form_id is ignored for inline fields unless the inline filter handles them. The description says inline fields go through the placement filter "too". With Pro #7048 both filters are registered, so it does not show up there, but another plugin using only the placement filter would be surprised. Either drop that line (as execute_create_field() now does) or say so in the filter docblock.
  4. The update filter does not guard a non-array return the way place_new_ability_field() does (is_array( $placed ) || is_wp_error( $placed ) ? $placed : $prepared). A callback that returns nothing gets the generic frm_field_update_failed instead of the original data being used. Same guard in execute_update_field() would match.

Was not exercised: Pro, so none of the four Lite/Pro combinations in the PR's table except this Lite with no hooks (Pro #7048 is a separate PR); a browser (builder UI, live MCP calls); PHPCS (the repo ruleset needs the FormidableQuality sniff, not installed here; CI's PHPCS, PHPStan, Mago and Rector jobs show as skipped on this head, so nothing static ran that I could see beyond Psalm and the syntax check); the code-review/security-review/simplify skills (read by hand, 4 files).

@franky-the-going-merry franky-the-going-merry Bot removed franky-review franky-working Franky is actively reviewing this labels Nov 27, 2026
Crabcyborg and others added 2 commits November 27, 2026 15:53
Only skip the inline field loop on an explicit true from
frm_ability_create_inline_fields, keep the form_id the placement
filter picks for inline fields, and ignore a non-array return from
frm_ability_update_field_placement instead of failing the update.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Crabcyborg

Copy link
Copy Markdown
Contributor Author

Note 1 (cache-clear lines not covered): not changed in code. FrmField::create() and FrmField::update() already clear the destination form's cache, so no test can fail without them. The description now says they are a safety net no test isolates.
Note 2 (inline filter skips on any non-null): fixed in 352c165, true !== $created. test_create_form_creates_inline_fields_when_the_hook_returns_false fails with null === $created.
Note 3 (inline loop forces the requested form): fixed in 352c165, the overwrite is dropped. test_create_form_stores_inline_fields_where_the_placement_hook_puts_them fails with it restored. Pro #7048's inline filter always returns true or WP_Error, so the loop does not run there.
Note 4 (update filter non-array return): fixed in 352c165, a non-array return is ignored. test_update_field_ignores_a_non_array_from_the_update_hook fails without the guard.
Also merged the latest master (clean).

@franky-the-going-merry franky-the-going-merry Bot added the franky-working Franky is actively reviewing this label Nov 27, 2026

@franky-the-going-merry franky-the-going-merry Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approve, re-reviewed at 352c165 (my Approve was at 2ffa3e8). Nothing left open.

The delta is 7 files, 88 lines: the four changes from my last notes plus a clean master merge. All four are in, and each one has a test that fails without it.

Tests run: phpunit at 352c165 (php@8.4, wordpress-develop harness, this head as the only plugin, no Pro, throwaway DB)

  • test_FrmAbilitiesFieldPlacement.php → 12 tests, 74 assertions, OK (was 9 at my last review).
  • Neighbours, each OK: test_FrmAbilitiesFieldsController 17, test_FrmAbilitiesFormsController 14, test_FrmAbilitiesContract 22, test_FrmFieldPlacement 14, plus the other test_FrmAbilities* files (entries 17, form actions 9, payments 9, subscriptions 9, styles 7).
  • Mutations, each reverted afterwards:
    • true !== $created back to null === $created fails test_create_form_creates_inline_fields_when_the_hook_returns_false.
    • The $prepared['form_id'] = $form_id; overwrite put back in the inline loop fails test_create_form_stores_inline_fields_where_the_placement_hook_puts_them.
    • is_array( $placed ) ? $placed : $field_data replaced with $placed fails test_update_field_ignores_a_non_array_from_the_update_hook.
  • PHP CS Fixer (repo config, --allow-risky=yes) on the 4 PR files: 0 to fix. CI is green on PHPUnit 7.4 to 8.4, Psalm and the syntax checks.

The inline loop no longer overwrites form_id, and prepare_new_field() already sets it from the new form before the placement hook runs, so a plain create-form still lands its fields on the new form (the 14 forms-controller tests and the 12 placement tests cover that). The cache-clear lines are still not isolated by any test; the author says so in the description, which is the honest place for it.

Not exercised: Pro (so the Lite/Pro combinations in the PR's table other than this Lite with no hooks), a browser (builder UI, live MCP calls), PHPCS (the repo ruleset needs PHPCompatibilityWP and FormidableQuality, not installed here; CI shows PHPCS, PHPStan, Mago and Rector as skipped on this head), and the code-review/security-review/simplify skills (the delta is small and was read by hand).

@franky-the-going-merry franky-the-going-merry Bot removed franky-review franky-working Franky is actively reviewing this labels Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant