Fieldset formwidget fields should be translatable - #1528
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
💤 Files with no reviewable changes (1)
Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review. WalkthroughThe nested form widget setup no longer assigns Estimated code review effort: 1 (Trivial) | ~2 minutes Merge Risk: ⚪ Minimal · up to This is a narrowly scoped change to make fieldset formwidget fields translatable, with no actionable merge-blocking risk remaining beyond normal checks and review. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
LukeTowers
left a comment
There was a problem hiding this comment.
@mjauvin this is going to cause issues with code that extends form widgets that checks for isNested to avoid injecting fields on the wrong Form widget instance.
|
Sorry for the AI dump @LukeTowers you're right — EasyAudit, Winter.Pages and Winter.TailwindUI all guard on The root issue is that
For Conflating them breaks two things:
SuggestionKeep --- a/modules/backend/widgets/Form.php
+++ b/modules/backend/widgets/Form.php
@@ -74,6 +74,15 @@ class Form extends WidgetBase
*/
public $isNested = false;
+ /**
+ * @var bool Used to flag that this nested form shares the data scope of its parent
+ * form; ie. its fields resolve against the same model attributes and array name as
+ * if they had been defined on the parent form directly. Only relevant when
+ * $isNested is true. Used by the fieldset form widget, which nests fields visually
+ * without introducing a new data scope.
+ */
+ public $sharesParentScope = false;
+
//
// Object properties
//
@@ -138,6 +147,7 @@ class Form extends WidgetBase
'context',
'arrayName',
'isNested',
+ 'sharesParentScope',
]);
@@ -881,8 +891,9 @@ class Form extends WidgetBase
if ($field->required === null && $this->model && method_exists($this->model, 'isAttributeRequired')) {
- // Check nested fields
- if ($this->isNested) {
+ // Check nested fields, unless the nested form shares its parent's data
+ // scope, in which case the attribute name needs no prefixing
+ if ($this->isNested && !$this->sharesParentScope) {
// Get the current attribute level
$nameArray = HtmlHelper::nameToArray($this->arrayName);
unset($nameArray[0]);
--- a/modules/backend/formwidgets/FieldSet.php
+++ b/modules/backend/formwidgets/FieldSet.php
@@ -54,6 +54,10 @@ class FieldSet extends FormWidgetBase
// set arrayName from parent form to save fields to the model
$config->arrayName = $this->getParentForm()->arrayName;
+ // the fields are nested visually only; they resolve against the parent
+ // form's model and array name, exactly as if defined on the parent form
+ $config->isNested = true;
+ $config->sharesParentScope = true;Winter.Translate's guard then becomes: // EventRegistry::registerModelTranslation()
$sharesParentScope = property_exists($widget, 'sharesParentScope') && $widget->sharesParentScope;
if (!$model->hasTranslatableAttributes() || ($widget->isNested && !$sharesParentScope)) {
return;
}
VerifiedOn a settings model with 22 translatable attributes, all of them inside
Happy to open the Winter.Translate PR (and a docs note) alongside if you like the direction. Naming is of course open — AlternativeIf you'd rather not add core surface at all: have Winter.Translate recurse into |
|
@AIC-BV seems reasonable enough, feel free to submit a PR. |
Summary by CodeRabbit