Repository navigation
Add ability hooks so Pro can place section and repeater fields - #3760
Crabcyborg wants to merge 9 commits into
Conversation
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>
|
Warning Review limit reachedYou'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. View limit details
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. |
There was a problem hiding this comment.
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_FrmSectionStructureandtest_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 intest_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_headis the known harness failure from earlier today (WordPresswp-block-librarynotice). - Builder repro, my own PHPUnit probe (a form with a repeater whose child fields are ordered after the
end_divider, thenapply_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.
- Stored order, which is what the builder gets without the PR:
- Mutations I ran: dropping the parent fields deferred past the
end_dividerinsort_for_builder()is caught (1 failure). A change that makesget_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 theend_dividerand later fields down by one, as intended. The code is right, but no test covers it (see note 1).
Notes (non-blocking)
test_FrmAbilitiesFieldPlacementonly appends to a section that already holds at most one field. Add a case with two or more fields in the section and nofield_order, and assert the new field lands after the last one with theend_dividerpushed down. That is the mutant that survives.- 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-revieworsimplifyskills on this PR. - I read the helper, the inline-fields helper and the controller changes in full. The test files and the
delete-fieldcleanup path I checked by running them, not by reading every case.
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>
|
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). |
There was a problem hiding this comment.
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 failstest_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).
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
There was a problem hiding this comment.
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.phpat 2ffa3e8 → OK, 9 tests, 59 assertions. Alsotest_FrmAbilitiesFieldsController.php17 OK,test_FrmAbilitiesFormsController.php14 OK,test_FrmAbilitiesContract.php22 OK,test_FrmFieldPlacement.php14 OK. CI runs the PHPUnit job on 7.4 to 8.4 and is green. - Mutations: no fallback in
place_new_ability_field()failstest_create_field_keeps_the_earlier_repeater_placement_without_a_placement_hook; putting the$prepared['form_id'] = $form->idoverwrite back failstest_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-fieldreturns theability_callback_exceptionerror, nothing stored. - Update hook returning
null:update-fieldreturnsfrm_field_update_failed, stored field untouched. - Inline hook returning
false:create-formsucceeds 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).
- Placement hook returning a prepared array without
Non-blocking
- 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 inexecute_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. frm_ability_create_inline_fieldsskips the fields on any non-null, non-WP_Error return. The docblock saystrue,WP_Errorornull, but__return_false(or an array) makescreate-formsucceed with no fields at all. InFrmAbilitiesFormsController.phpuseif ( true !== $created ) {for the loop so only an explicittrueskips it.- The inline loop still forces the requested form.
$prepared['form_id'] = $form_id;in the loop runs afterprepare_new_field(), so afrm_ability_new_field_placementhook that changesform_idis 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 (asexecute_create_field()now does) or say so in the filter docblock. - 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 genericfrm_field_update_failedinstead of the original data being used. Same guard inexecute_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).
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>
|
Note 1 (cache-clear lines not covered): not changed in code. |
There was a problem hiding this comment.
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_FrmAbilitiesFieldsController17,test_FrmAbilitiesFormsController14,test_FrmAbilitiesContract22,test_FrmFieldPlacement14, plus the othertest_FrmAbilities*files (entries 17, form actions 9, payments 9, subscriptions 9, styles 7). - Mutations, each reverted afterwards:
true !== $createdback tonull === $createdfailstest_create_form_creates_inline_fields_when_the_hook_returns_false.- The
$prepared['form_id'] = $form_id;overwrite put back in the inline loop failstest_create_form_stores_inline_fields_where_the_placement_hook_puts_them. is_array( $placed ) ? $placed : $field_datareplaced with$placedfailstest_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).
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-fieldexecute_create_field()no longer overwrites the preparedform_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 preparedform_idis always the requested form, so nothing changes.frm_ability_new_field_placementinFrmFieldPlacementHelper::place_new_ability_field(). It runs insideprepare_new_field(), so inlinecreate-formfields go through it too. It may changeform_id,field_orderandfield_options.in_section, or return aWP_Error.maybe_position_in_repeater()placement runs. That method moved unchanged fromFrmAbilitiesFieldsControllertoFrmFieldPlacementHelper, which keeps the controller under the 1000-line phpcs limit.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-fieldfrm_ability_update_field_placement, after stored options are merged. A callback can changeform_idorfield_order, or return aWP_Error. Any other non-array return is ignored and the unfiltered data is saved. The new form's cache is also cleared, thoughFrmField::update()already does this, so no test shows a difference.delete-fieldfrm_ability_before_delete_field(the field still exists) andfrm_ability_after_delete_field(it is gone).create-formfrm_ability_create_inline_fields. Only an explicittruemeans a callback created the fields. AWP_Errorstops the call.nullor any other value keeps the existing one-at-a-time loop.form_idafterprepare_new_field(), so afrm_ability_new_field_placementcallback can move inline fields, as it can forcreate-field. Pro's inline filter always returnstrueor aWP_Error, so with the Pro PR the loop does not run.Mixed versions
Either PR can merge first.
maybe_position_in_repeater()and the plain inline loophas_ability_section_placement()and registers none of its hooks, including the builder sortTesting
create-fieldon a repeater's child form with nofield_order. The field goes right after the repeater's last field, and later fields move down, as before.Local results
test_FrmAbilitiesFieldPlacement(12 tests) covers the fallback, each hook's return value being used,WP_Errorfrom each hook, afalseinline-filter return, anullupdate-filter return, and the placement filter moving inline fields. Mutation check: removing the fallback, restoring eitherform_idoverwrite, removing the update filter or its non-array guard, the delete actions, the inline filter, or going back tonull === $createdeach fails the matching tests. The two cache-clear lines are not covered, becauseFrmField::create()andFrmField::update()clear the same cache.mcpgroup, Pro builder and field tests): all pass. With current Lite, the Pro PR's new tests skip and its earlier-order check passes.test_FrmAppHelper::test_plugin_folder, which fails because the local checkout folder is not namedformidable.🤖 Generated with Claude Code