Skip to content

Alignment update tweaks#3127

Merged
Crabcyborg merged 1 commit into
masterfrom
alignment_update_tweaks
Jun 8, 2026
Merged

Alignment update tweaks#3127
Crabcyborg merged 1 commit into
masterfrom
alignment_update_tweaks

Conversation

@Crabcyborg
Copy link
Copy Markdown
Contributor

@Crabcyborg Crabcyborg commented Jun 8, 2026

Too much of the alignment update was in Pro.

Related PR https://github.com/Strategy11/formidable-pro/pull/6493

Summary by CodeRabbit

  • Refactor
    • Enhanced form style caching mechanism to improve performance and optimize field alignment handling based on product tier configuration.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 8, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This PR introduces style-based alignment configuration for form fields. FrmStylesController now caches active style objects per form and exposes alignment setting keys. FrmFieldType::get_container_class() falls back to these cached style settings for field alignment when Pro is not installed.

Changes

Style-based alignment fallback

Layer / File(s) Summary
Style cache infrastructure
classes/controllers/FrmStylesController.php
Static $active_style cache indexed by form ID. get_active_style() returns a memoized style object, and get_align_key_for_style_settings() returns the alignment key (check_align for checkboxes, radio_align otherwise).
FrmFieldType alignment fallback
classes/models/fields/FrmFieldType.php
get_container_class() conditionally reads field align (Pro-only), falling back to get_align_class_from_style_settings() when absent. The new protected helper retrieves alignment values from the cached active style's post_content.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A cached style aligns the field,
No Pro required, fallback revealed,
Controllers whisper, types attend,
Alignment flows from theme, not trend. 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Alignment update tweaks' is vague and generic. While it references alignment, it doesn't clearly convey what specific changes were made or why. Consider a more descriptive title that explains the specific change, such as 'Move alignment logic from Pro to core for style settings' or similar.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch alignment_update_tweaks

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@deepsource-io
Copy link
Copy Markdown

deepsource-io Bot commented Jun 8, 2026

DeepSource Code Review

We reviewed changes in e994136...6e0b7b4 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
PHP Jun 8, 2026 1:24p.m. Review ↗
JavaScript Jun 8, 2026 1:24p.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a 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

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@classes/controllers/FrmStylesController.php`:
- Around line 1307-1309: When get_form_style() returns null we currently replace
it with new stdClass(), but downstream
FrmFieldType::get_align_class_from_style_settings() expects
$active_style->post_content to be an array and accesses
$active_style->post_content[$key], causing an undefined property notice; update
the fallback in FrmStylesController around the $active_style assignment so that
when creating the stdClass you also initialize $active_style->post_content = []
(an empty array) before caching/returning it, ensuring the property exists and
behaves as expected by get_align_class_from_style_settings().
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 26191a85-ddcd-4ced-bdaf-729cdf2f3626

📥 Commits

Reviewing files that changed from the base of the PR and between e994136 and 6e0b7b4.

📒 Files selected for processing (2)
  • classes/controllers/FrmStylesController.php
  • classes/models/fields/FrmFieldType.php

Comment on lines +1307 to +1309
if ( ! is_object( $active_style ) ) {
$active_style = new stdClass();
}
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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Potential undefined property access in downstream code.

When get_form_style returns null, this code converts it to an empty stdClass and caches it. Later, FrmFieldType::get_align_class_from_style_settings() (line 1109) accesses $active_style->post_content[$key] on this object. Since the empty stdClass has no post_content property, this will trigger a PHP notice: "Undefined property: stdClass::$post_content" before the null coalescing operator can suppress it.

🛡️ Recommended fix to ensure post_content exists

Option 1 (fix here in FrmStylesController):

 		if ( ! is_object( $active_style ) ) {
-			$active_style = new stdClass();
+			$active_style              = new stdClass();
+			$active_style->post_content = array();
 		}

Option 2 (fix in FrmFieldType at line 1109):

-		return $active_style->post_content[ $key ] ?? '';
+		return ( $active_style->post_content ?? array() )[ $key ] ?? '';

Either approach prevents the undefined property notice.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if ( ! is_object( $active_style ) ) {
$active_style = new stdClass();
}
if ( ! is_object( $active_style ) ) {
$active_style = new stdClass();
$active_style->post_content = array();
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@classes/controllers/FrmStylesController.php` around lines 1307 - 1309, When
get_form_style() returns null we currently replace it with new stdClass(), but
downstream FrmFieldType::get_align_class_from_style_settings() expects
$active_style->post_content to be an array and accesses
$active_style->post_content[$key], causing an undefined property notice; update
the fallback in FrmStylesController around the $active_style assignment so that
when creating the stdClass you also initialize $active_style->post_content = []
(an empty array) before caching/returning it, ensuring the property exists and
behaves as expected by get_align_class_from_style_settings().

@Crabcyborg Crabcyborg merged commit ad59373 into master Jun 8, 2026
42 of 48 checks passed
@Crabcyborg Crabcyborg deleted the alignment_update_tweaks branch June 8, 2026 13:38
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