-
-
Notifications
You must be signed in to change notification settings - Fork 227
Provide the current Form instance to partials #902
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
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
|
Why does it need to? |
|
@LukeTowers I spoke with @AIC-BV on Discord and the issue is that |
bennothommo
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.
All good to be merged in with v1.2.3
|
It looks fine, but it is not working 😅 |
|
@AIC-BV are you using |
Yes 🤦♂️ |
|
Can we merge this one with 1.2.2 as well @LukeTowers it's definitely not going to break anything, it just add a variable for the partial. |
|
Not yet @mjauvin, I'm still not convinced of it and it adds to the API surface. Why is previewMode necessary and not just looking at the disabled state of the current field? |
That information is NOT available elsewhere when within a repeater/nestedform @LukeTowers |
|
@LukeTowers the only information sent to the partial is this: <?= $this->controller->makePartial($field->path ?: $field->fieldName, [
'formModel' => $formModel,
'formField' => $field,
'formValue' => $field->value,
'model' => $formModel,
'field' => $field,
'value' => $field->value
]) ?>
Now it would be possible to set the previewMode in the field as well (from backend/widgets/Form.php) but I find it more intrusive. |
|
@LukeTowers I can also do the following if you prefer: diff --git a/modules/backend/widgets/form/partials/_field_partial.php b/modules/backend/widgets/form/partials/_field_partial.php
index ae545876a..5b6f54277 100644
--- a/modules/backend/widgets/form/partials/_field_partial.php
+++ b/modules/backend/widgets/form/partials/_field_partial.php
@@ -1,3 +1,5 @@
+<?php $field->previewMode = $this->previewMode ?>
+
<?= $this->controller->makePartial($field->path ?: $field->fieldName, [
'formModel' => $formModel,
'formField' => $field,
@@ -5,5 +7,4 @@
'model' => $formModel,
'field' => $field,
'value' => $field->value,
- 'previewMode' => $this->previewMode,
]) ?> |
|
That works too, but how is it different about the API surface ? |
|
Because it's more purposeful. Adding the variable |

There is currently no way for a partial to know the form's previewMode, especially when in a repeater or nestedform firmwidget.