-
Notifications
You must be signed in to change notification settings - Fork 39
Fix single row style setting not working as expected #2544
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
base: master
Are you sure you want to change the base?
Conversation
WalkthroughMapping of 'block' alignment to the 'vertical_radio' class in FrmFieldType::prepare_align_class is now conditional based on the form-level style value 'check_align' retrieved via FrmStylesController::get_style_val; behavior unchanged when 'check_align' equals 'inline'. No public API changes. Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant FR as Form Renderer
participant FT as FrmFieldType.prepare_align_class
participant SC as FrmStylesController
U->>FR: Render form
FR->>FT: Request field align class
FT->>SC: get_style_val('check_align', field.form_id)
SC-->>FT: check_align value
alt check_align != "inline"
note right of FT #DFF2DF: style permits block override
FT-->>FR: return "vertical_radio"
else
note right of FT #FFF4D6: preserve existing mapping
FT-->>FR: return existing alignment class
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
classes/models/fields/FrmFieldType.php(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
classes/models/fields/FrmFieldType.php (1)
classes/controllers/FrmStylesController.php (2)
FrmStylesController(6-1362)get_style_val(1178-1183)
🔇 Additional comments (1)
classes/models/fields/FrmFieldType.php (1)
985-989: Good fix addressing the single row style issue.The conditional check correctly gates the 'vertical_radio' mapping based on the form-level style value. This ensures that the single row style setting takes effect as intended. The logic properly handles the case where
get_style_valreturnsnull(when the style value is not set), as the strict comparison will evaluate tofalse.
| $check_align = FrmStylesController::get_style_val( 'check_align', $this->field['form_id'] ); | ||
| // Check needed to fix issue #6035 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Verify that form_id exists before using it.
$this->field['form_id'] is accessed without checking if it exists. If the field array doesn't have a form_id key, this will trigger an undefined index notice.
Run the following script to check if there are safeguards elsewhere or if this can occur:
🏁 Script executed:
#!/bin/bash
# Description: Check how prepare_align_class is called and if form_id is always set
# Search for calls to prepare_align_class to understand the context
rg -nP --type=php -C5 '\bprepare_align_class\b'
# Search for where $this->field is populated to see if form_id is always set
ast-grep --pattern $'function __construct($field = $_, $type = $_) {
$$$
}'
# Check if there are other places where $this->field['form_id'] is accessed
rg -nP --type=php "\\\$this->field\['form_id'\]"Length of output: 1862
🏁 Script executed:
#!/bin/bash
# Check FrmFieldType class and its constructor to ensure form_id is initialized
rg -nP --type=php 'class\s+FrmFieldType\b' -C5 classes/models/fields/FrmFieldType.php
rg -nP --type=php 'function __construct' -C10 classes/models/fields/FrmFieldType.phpLength of output: 562
🏁 Script executed:
#!/bin/bash
# List all field-type subclass files
fd --type f 'FrmField*.php' classes/models/fields
# Find where field-type objects are instantiated
rg -nP 'new\s+FrmField\w+\s*\(' -n classesLength of output: 776
🏁 Script executed:
#!/bin/bash
# Show context for FrmFieldDefault instantiation
rg -nP -C5 'new\s+FrmFieldDefault' -n classes/factories/FrmFieldFactory.php
# Find assignment to $field in the factory
rg -nP -C5 '\$field\s*=' -n classes/factories/FrmFieldFactory.phpLength of output: 1300
🏁 Script executed:
rg -nP --type=php 'function\s+getOne' -C10 classes/models/FrmField.phpLength of output: 741
Handle both object and array when retrieving form_id.
In prepare_align_class, replace
$check_align = FrmStylesController::get_style_val( 'check_align', $this->field['form_id'] );with something like:
$form_id = is_object( $this->field ) ? $this->field->form_id : ( $this->field['form_id'] ?? null );
$check_align = FrmStylesController::get_style_val( 'check_align', $form_id );[this prevents fatal errors for object‐typed fields and undefined index notices]
🤖 Prompt for AI Agents
In classes/models/fields/FrmFieldType.php around lines 985 to 986, the code
assumes $this->field is an array and accesses $this->field['form_id'], which can
cause fatal errors for object-typed fields or undefined index notices; update
the code to normalize $form_id first by checking is_object($this->field) and
using $this->field->form_id if so, otherwise use $this->field['form_id'] if set
(or null), then pass that normalized $form_id into
FrmStylesController::get_style_val('check_align', $form_id).
|
@AbdiTolesa I tested this and noticed the following issues:
|
@lauramekaj1 This one should be fixed now. |
@lauramekaj1 I couldn't reproduce this one but I already have another PR that is needed to make the alignment work properly in the builder. https://github.com/Strategy11/formidable-pro/pull/6057 Could you check out this branch and the Pro part and test if this issue is gone? |
@lauramekaj1 This fix just focuses on fixing the Single vs Multiple rows layout for field choices and I can reproduce that issue on the master branch too. Can we create another issue to track that? |
lauramekaj1
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AbdiTolesa I tested this and verified that the issue is fixed. Thank you!
|
@Crabcyborg If I set to "Single Row" in the Styles then set to "One Column" in the field setting, it prefers the Styles setting. Is that the right behavior? |
I think we might not add additional option to resolve conflict that might happen between the two settings (Style & Option Layout) since users could adjust update either of those two settings to make it display as they wish in my opinion. |
|
@AbdiTolesa Currently if I set the field setting to any value except "One Column", it always uses the field setting. |
@truongwp The more I think about those two settings, the more I feel uncertain about their purpose since their purpose seem to overlap. Both of them can be used to make the options in single row vs multiple rows but can also be conflicting with each other easily. |
|
@Crabcyborg Can you give your opinion? |
|
Thanks @AbdiTolesa and @truongwp. These two settings seem to directly conflict. I'm bringing this up with Steve, Dalton and Nat, to see what they think. I think we might want to overhaul these settings a bit. |
|
We're going to add some new options to both the style and field settings. I have some related PRs where I started working on this. https://github.com/Strategy11/formidable-pro/pull/6102 and #2593. Most of the details to get started are in https://github.com/Strategy11/formidable-pro/pull/6102, and below. This still needs a lot of work. @AbdiTolesa, if you can take these over again, that would be great. What we need to make sure works
Thank you! |
@Crabcyborg Sure, working on it. |
Fix https://github.com/Strategy11/formidable-pro/issues/6035
Related PR: https://github.com/Strategy11/formidable-pro/pull/6057
Test steps