Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
As entities, Scald Atoms are fieldable, but when a field is added to a scald atom type, no validation of the field's widget takes place when the atom is saved. Per its own documentation, field_attach_form_validate()
should be called for each atom that is being edited or created.
Comment | File | Size | Author |
---|---|---|---|
#13 | atom_add_edit_form-2890463-13.patch | 3.74 KB | nagy.balint |
| |||
#9 | atom_add_edit_form-2890463-9.patch | 3.75 KB | martin_q |
|
Comments
Comment #2
martin_qSee patch attached, which is based on the code in
scald_atom_add_form_options_submit()
as well asnode_form_validate()
.Comment #3
martin_qComment #4
martin_qWhoops, wrong status.
Comment #5
nagy.balint CreditAttribution: nagy.balint commentedThanks for the patch!
It seems we already have similar code in "scald_atom_add_form_options_submit" that constructs a new form state related to the issue #2710927: Wrong $form_state passed to entity_form_submit_build_entity()
Maybe we could make a function or some way to make sure that we don't have the same code at several places.
Comment #6
martin_qThanks for the tip, @nagy.balint. Refactored patch from #2 and abstracted the repeated code into a separate function.
Comment #7
martin_qCorrected syntax for passing of reference to $form_state and $atom_form_state arrays.
Comment #8
nagy.balint CreditAttribution: nagy.balint commentedI guess there is a mistake at
"+function &_scald_get_atom_form_state(&$form_state, $index) {"
Comment #9
martin_qI've never used the syntax in that line before, but it seems to be legit according to PHP documentation when you want to return the reference to an array, which is what I wanted to do, in order to be extremely cautious about maintaining the data in the form state correctly.
But there were errors in the lines immediately following that line. Sorry for not checking it thoroughly enough. It seems from my tests that the attached new patch fixes them.
Comment #10
nagy.balint CreditAttribution: nagy.balint commented--- Removed due next comment.
Comment #11
nagy.balint CreditAttribution: nagy.balint commentedOkay now I see that then it returns with a reference.
Although Im not sure why we need that here, for performance reasons?
Comment #12
nagy.balint CreditAttribution: nagy.balint commentedI suppose as it create a new variable, it would not have any relation with the original form_state, but to be extra careful we can also remove the & before the form state? So then modification on the form state inside the function would not be possible.
Comment #13
nagy.balint CreditAttribution: nagy.balint commentedSo to illustrate #12, would a patch like this work?
Comment #14
nagy.balint CreditAttribution: nagy.balint commentedI guess the form_state was passed by reference because the values_excluding_atoms is now stored in form state for performance reasons.
So the patch in #13 wont use that, but we can readd the reference I guess.
But Im still not sure if the return by reference is needed.
Also I noticed an issue, that in scald_atom_add_form_options_submit, the values is already built, but then not used for anything now.
And so it does not pass the same data now than it passed before.