-
Notifications
You must be signed in to change notification settings - Fork 225
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
Add extension hooks to update submitted form fields before processing #1060
Add extension hooks to update submitted form fields before processing #1060
Conversation
@@ -246,7 +246,11 @@ public function getValueFromData() | |||
|
|||
public function getSubmittedFormField() |
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.
Looks to me that this function definition can be removed because it's defined in the parent class, no?
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.
They are different classes — FormField vs FileField
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.
Also, the extending class doesn't call the parent method so extending just the parent method would have no effect for the file field.
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.
My point is EditableFileField
extends EditableFormField
, so this duplicate declaration of getSubmittedFormField
is not needed at all and can be completely removed from this class.
The parent can then be adjusted to use late static binding (static::create()
) to replace $field = SubmittedFormField::create()
.
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.
I've renamed the extension point to be unique in each class, more specific in the file class, @dhensby.
I don't think we can use late static binding here. It is true EditableFileField extends EditableFormField, but they each instantiate a different class in their getSubmittedFormField
method (SubmittedFormField
vs SubmittedFileField
) and those classes don't have any connection to the EditableForm/FileField classes using them in terms of inheritance.
So what is the use-case here? I'm a bit unclear as to what kind of tweaks would be needed... |
We needed a custom behaviour for Since we added the extension point for the submitted file field, it made sense to add the same hook into the parent class too to allow for updating of any field type. |
f10cd0c
to
35814ea
Compare
OK - I see, I think I'm getting a better understanding of your usecase here. Wouldn't it be better to add extension hooks to This is the exact purpose of injector (and the So in a rambling kind of way I'm saying, this should be completely possible with injector. |
As mentioned before @dhensby, when replacing a class with Injector, it needs all $db, $has_one etc duplicated in the new class, since the |
Hi @michalkleiner - what you're saying is really concerning to me because it completely defeats the point of app/_config/udf.yml: SilverStripe\Core\Injector\Injector:
SilverStripe\UserForms\Model\Submission\SubmittedFileField:
class: MySubmittedFileField app/src/MySubmittedFileField.php: <?php
namespace {
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\UserForms\Model\Submission\SubmittedFileField;
class MySubmittedFileField extends SubmittedFileField {
/**
* Return the value of this field for inclusion into things such as
* reports.
*
* @return string
*/
public function getFormattedValue()
{
$name = $this->getFileName();
$link = $this->getLink();
$title = 'Extended Download File';
if ($link) {
return DBField::create_field('HTMLText', sprintf(
'%s - <a href="%s" target="_blank">%s</a>',
$name,
$link,
$title
));
}
return false;
}
}
} I then created a UDF and just added a file field: Then received this email: The database doesn't create an extra table, data is stored in the original So that seems to me like using |
Thanks for giving it a shot, @dhensby. With your example above, if you now add a |
Hi @michalkleiner - I've followed your instructions and indeed the table for SubmittedFileField is not created - which is really bad news and this is a more fundamental bug that we can't really just gloss over with a hook like this. I think we need to open a bug report against the framework :( |
Sounds like this PR is not a good solution for the problem. Closing in favor of silverstripe/silverstripe-framework#9952 which fixes the underlying problem. |
@GuySartorelli it wasn't meant to be a solution to the underlying problem, it was an enhancement supporting a workaround. I still see value in adding the extension points as an enhancement, unless there's a strong argument against them. |
I guess my point is that there's no need to workaround it if that PR gets merged - there won't be anything to work around. |
Without this enhancement, there's no way how to easily tweak the existing or provide a custom field that will be used to receive the data when UDF is being processed.