I'm building my own block for use with homebox. It displays a view, but the user can set the argument that is passed into the view in the homebox block settings (ie. the 'cog' icon). The argument in particular is multiple taxonomy terms, selected via a hierarchical select widget.
I've got it mostly working, except that if the user selects 3 terms (say 1,2,3), saves, then comes back and selects 1 term (say 4), 2 of the previous terms will still be in effect.
I can see in the homebox users table that it is storing (4,2,3).
I'm pretty sure the issue is with homebox_block_edit_form_builder_submit(), _homebox_save_user_settings() or homebox_merge_settings().
Working through it now.
Comments
Comment #1
lostkangaroo commentedDid you ever create a patch for this? If not work shall begin in earnest to do so as this is needed for a current project.
I located a problem centering around array_intersect_key() in homebox_block_edit_form_builder_submit(). Which simply appends any new multi values to the current existing settings rather than resetting them. I haven't gone much further debugging beyond this as I was hoping to find a patch by checking in here and locating this issue.
Comment #2
lostkangaroo commentedAfter digging into this a bit more and running a few tests the above problem with array_intersect_key is not the issue causing this. The problem is in the _homebox_save_user_settings() calls to homebox_merge_settings(). In the test case I have created a block and given it two form fields.
The First is a multi select using this form field
The Second is a group of checkboxes using this form field
I noticed fairly early on that the second field "multi_checkboxes" is handled okay with the current system and has no issues. This leaves only the multiselect with issues.
Tracking into this more with no default values associated with the test block the first call to homebox_merge_settings() passes with no issues and only the second homebox_merge_settings() fails in which existing user settings for this block are present. This causes the data from the form to be merged with existing settings rather than allowing the form settings to override and replace the existing settings.
It seems that in the case of saving the configuration we could actually remove any calls to homebox_merge_settings() as the values we really want to keep are those that come from the form itself passed through in the $blocks param.
My question at this point, is there any necessary need to preserve the homebox_merge_settings() calls in _homebox_save_user_settings()?
Comment #3
drummIf there are no side effects, homebox_merge_settings() can certainly be removed. I've wanted to do that before, but was worried it had some purpose I wasn't aware of.
Comment #4
lostkangaroo commentedWe were right to be worried since removal of the homebox_merge_settings() believe it or not actually served some vital purposes with custom colors and duplicate block saving. So to actually fix the original issue at hand we needed to preserve the merges in some way and still allow form input to override any existing settings. Simply switching these calls to array_merge() and passing the save values solved this by its native ability to apply data from the last array passed when any key conflicts are found.
This can be used for D6 also
Comment #5
drummCommitted.