So I'm not sure if this is a bug, or just unintended interaction between Title and Views Bulk Operations.

When using the "Modify Entity Values" operation, the title_field_attach_submit function gets called and it modifies the $form_state. This causes an error in VBO after you submit the form with the modified fields. VBO has $form_state['values'] set to have an array per each entity. title_field_attach_submit strips out this hierarchy when it calls $values = drupal_array_get_nested_value($values, $form['#parents'])

I hope I'm explaining this well enough :)

Comments

jonmcl’s picture

StatusFileSize
new510 bytes

Possible patch attached.

I'm not sure if there are unintended consequences, but the patch removes the $values = &$form_state['values'] variable assignment.

plach’s picture

Status: Active » Needs work

Nope, we need to be able to alter the submitted values in the submit callback, see title_field_term_description_submit(). We need a different solution.

jonmcl’s picture

Yes, sorry.. I don't know what I was thinking. I probably disabled the function completely.

I will try and revisit as soon as I can. I'm still wondering if the array structure that Views Bulk Operations is using in there is valid. I will need to research some other modules.

torrance123’s picture

Status: Needs work » Active

I've just spent several hours trying to debug exactly this bug, and after many backtraces I worked my way to implementing exactly the same 'solution' as in comment 1 here. Nice to know that that 'solution' isn't correct, but I'd be very interested in what will work.

For anyone else like me trying to google this issue, the original VBO error I was getting was:

Recoverable fatal error: Argument 1 passed to drupal_array_get_nested_value() must be an array, null given, called in modules/field/field.default.inc on line 38 and defined in drupal_array_get_nested_value() (line 6490 of includes/common.inc).

..which means that the callback title_field_attach_submit() is deleting array items in the $form_state['values'] which, since this is passed by reference, is affecting everything else afterwards that needs to also operate on this array.

torrance123’s picture

Status: Active » Needs review
StatusFileSize
new906 bytes

Please see attached patch.

I've removed the variable assignment by reference, or else the call to drupal_array_get_nested_value() was stripping most of the values in $form_state['values']. However, to ensure that changes to the $values variable are incorporated into the $form_state array, I've also included a call to drupal_array_set_nested_value() at the end.

This should ensure the functionality of assigning by reference is retained, without its destructiveness though as I'm not entirely sure the purpose of this callback function this definitely needs review.

Status: Needs review » Needs work

The last submitted patch, title-attach_submit-1528590-5.patch, failed testing.

torrance123’s picture

StatusFileSize
new855 bytes

Patch path reformatted for testing.

torrance123’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, title-attach_submit-1528590-7.patch, failed testing.

torrance123’s picture

Status: Needs work » Needs review
StatusFileSize
new810 bytes

Ugh... this should be compatible with SimpleTest.

torrance123’s picture

StatusFileSize
new811 bytes

Please see attached patch with corrected variable name for $values.

I'd really appreciate feedback on this patch, as we'd like to push this across to production soon but I need to know whether this ensures existing functionality is retained.

plach’s picture

Status: Needs review » Needs work

I'd appreciate a comment explaining why #11 actually solves the issue and a brief update to the issue summary with the same information. Aside from this the change does not look harmful to me. The proper way to test it should be changing the input format of a replaced term description and check that everything keeps working. Ideally a test addition would be the perfect way to show this patch does work.

torrance123’s picture

Status: Needs work » Needs review

Please see my comment in #5 which explains why this patch fixes the issue.

To restate though, the code was performing the variable assignment by reference of $values = &$form_state['values'] and then was immediately making a call to drupal_array_get_nested_value($values, $form['#parents']) that accepts $values by reference and makes changes directly to that $values array, whereby it strips most items and leaves just those that are children of $form['#parents']. Therefore, by the time the function title_field_attach_submit() exits, it has potentially deleted elements from the $form_state['values'] array.

In most instances, it just so happens that drupal_array_get_nested_values() returns all the original values unaltered and therefore this code was, by luck, not affecting subsequent functions that also needed to pull values from $form_state['values']. But when VBO is involved, the $form_state['values'] array is very much larger, including data from multiple nodes and the call to drupal_array_get_nested_values() is indeed destructive.

So, by making the assignment $values = $form_state['values'] by value, and then by reinjecting the (potentially) changed values back into this array, we avoid destructively altering other values that are not the concern of title module.

Unfortunately, I am not in a position to write a test for this function (and I don't understand "the proper way to test it should be changing the input format of a replaced term description" — can you elaborate?).

plach’s picture

Status: Needs review » Needs work

Thanks for clarifying but I asked also a comment in code with this explanation.

I don't understand "the proper way to test it should be changing the input format of a replaced term description" — can you elaborate?

Sorry, I got confused with the submit callback (see http://drupalcode.org/project/title.git/blob/628406b0bf0f67eb8a62979eed0...).

I guess we just need to confirm that things don't break for field widgets belonging to field groups (and obviously for widgets in plain forms): submitted values are synchronized back into the legacy properties and taken from there at storage time (they are also stored as fields). We must check that the legacy storage and the field storage have consistent values.

torrance123’s picture

Status: Needs work » Reviewed & tested by the community

I've done no dedicated testing for this, but we've had this patch running on a production system without issue for over a month now. I'd very much appreciate this to be commit, or else we are going to have to maintain this patch against future releases.

Thanks.

plach’s picture

Status: Reviewed & tested by the community » Needs work

Is it that hard to provide a new patch with a comment explaining why we need this fix?

torrance123’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new1.22 KB

Please see attach patch with comments.

plach’s picture

Status: Reviewed & tested by the community » Fixed
StatusFileSize
new1.19 KB

Committed and pushed the attached patch, thanks!

(I made some minor comment cleanup before comitting it)

plach’s picture

Issue tags: +Needs tests

This still needs tests

Automatically closed -- issue fixed for 2 weeks with no activity.

  • Commit a5a02de on 7.x-1.x, workbench authored by torrance123, committed by plach:
    Issue #1528590 by torrance123, JonMcL: Fixed Reference to $form_state['...