I have a couple box implementations that include custom Media form elements (image and video fields) inside custom Boxes.
In the process of upgrading Media to the latest 7.x-2.x-dev (7.x-2.0-beta1+9-dev) and Boxes to 7.x-1.2 (as well as a whole lot of other modules...) the boxes were no longer saving my chosen media items.
I tracked the problem down to the fact that the $form
was losing boxes' submit handler, 'boxes_box_form_submit'
, when I would use (change the value in) the media form element.
It looks like when the media element does its ajax stuff, the arg() path is no longer set to 'admin/structure/block/manage/boxes'
(which boxes_form_alter()
checks for) but is instead 'media/ajax/settings/options/FORM_ELEMENT'
(where FORM_ELEMENT is the ID of my media form element).
So, when the form is saved, the boxes submit handler is not called (and therefore neither is my custom my_box_box->options_submit()
).
I was able to fix this by, in boxes_form_alter()
, testing $form['#action']
instead of the path:
- if (($form_id != 'block_admin_configure' || $path != 'admin/structure/block/manage/boxes') &&
+ if (($form_id != 'block_admin_configure' || strpos($form['#action'], '/admin/structure/block/manage/boxes') != 0) &&
While this is working for me now, I don't actually know:
- Where/when this change in operation originated.
- Whether Media is doing things properly and it's ok that the arg() path is being changed.
- Whether it's always safe and effective for Boxes to rely on $form['action'].
Patch forthcoming.
Comment | File | Size | Author |
---|---|---|---|
#4 | boxes-form-alter-path-check-2636660-4-D7.patch | 620 bytes | oliverpolden |
#2 | boxes-2636660-form_alter_path_check.patch | 640 bytes | jeffschuler |
Comments
Comment #2
jeffschulerComment #4
oliverpolden CreditAttribution: oliverpolden commentedThe reason the save is now failing is due to the code within boxes_block_save() being removed. This code is redundant because the box should be saved using the form submit function 'boxes_box_form_submit'.
I've attached a patch that may be a better way of checking if we're submitting an ajax form.
Comment #5
jeffschulerThanks! I like your way better; checking $form['#action'] was definitely not a solid idea on my part.
I likely won't have a chance to test this until I come back to the project where it was an issue...