Hi,

This is one of the complicated and complexed Drupal bugs I've ever messed with. Here goes:
I have a custom content type with "assigned_person" field (this is a user reference field type). I have a report showing all of content of that specific content type, with the option to edit the field (the "assigned_person" field). This content type, also contain other field of various types.

When I use the resulted view(=action view form) to change "assigned_person" field, editing the desired field works great but strangely, one field of the custom content type loses its data (only in edited nodes selected in the form).

I've tracked the problem for hours. It appears that (I'm not detailing full stack trace below but parts of it):
- actionview_form_submit() launches hook views_operations_validate
- that hook in turn calls content_views_operations_validate() into action. This function removes from the edited node all the fields that are not edited currently (like other text fields. Remember that we are editing user reference field here).
- later on, content_validate() is being called, and it calls _content_widget_invoke(), which calls
- optionwidgets_widget() . This function alters its given parameter $items which is handled to it as a reference (and is actually the $node_field from the calling function). This function, when run on the relevant field (that's being emptied), which is a simple text field, since it got an empty field (remember it was dropped by content_views_operations_validate() above), sets the value of $items to an empty value, and here the problem lies... . It practically "accepts" and put a "VALIDATED" stamp on the empty field, setting it to empty de-facto in the node itself.

So, at the end of it, we get to the problem that some fields (one in my case) is being emptied when used with action view.

I've tried a quick fix which is to change the name of content_views_operations_validate() and I thought it would eliminate the problem. For some reason it wont. So, I cannot submit a patch. I haven't got full introspective on this problem.

I hope someone could take it from this point, investigate, and resolve it.
Thanks,
Boaz.

Comments

Chris Bray’s picture

I'm having this same problem and I've got a customer that needs this feature quite urgently, I'll have a look at it myself but may also be able to offer some money as a bounty if anyone else wants to have a try?

akahn’s picture

Title: when using on custom content types some data is lost from nodes » Action Views destroys data on CCK nodes

This is a critical issue that I'm experiencing as well. In my case, I'm using an action view to assign taxonomy terms to video nodes en masse. Upon clicking the update button, the data in an embedded video field (supplied by the Embedded Media Field module) is totally erased for the updated nodes.

What's going on here? Any comment from a maintainer?

Chris Bray’s picture

I ended up adding some checking code in actionview_save_nodes between the calls to node_validate and node_save, my code made sure that if the relevant fields were set to '' that they were unset, so node_save treated them as "don't change this field" rather than "set this field to nothing"

My hack is just to call:

if($node->field_title[0]['value'] == "")
  unset($node->field_title);

I know it's not a great solution, and I'd prefer not to have to use it!

bneel’s picture

Assigned: mdekkers » Unassigned
Status: Needs review » Active

Hi,
Your code doesn't work, the data are still deleted.
Are you sure about your code ?
Ben

mdekkers’s picture

Assigned: Unassigned » mdekkers

sorry, I have been busy, will get one of our developers to have a look at this.

giovans’s picture

Hi,
I think I have a (ugly) workaround for this issue. If you like you can try this:

In file actionview.module, at line 453,

replace

node_validate($node);
node_save($node);

whith:

node_validate($node);
module_invoke_all('views_operations_clean_node_fields', &$form_values, &$node);
node_save($node);

In file actionview_content.inc, add the following function:

function content_views_operations_clean_node_fields(&$form_values, &$node)
{
  $content_types = content_types($node->type);
  foreach ($content_types['fields'] as $f)
    {
      $field_name = $f[field_name];
      if (!isset($form_values[$field_name]))
	{
	  $node->$field_name = array();
	}
    }
}

Enjoy,
Giovans

Chris Bray’s picture

Status: Active » Needs review

Giovans solution in #6 seems to work for me, is it worth porting this back to the main module?

akahn’s picture

Seems like Views Bulk Operations may be a better bet.

Dimm’s picture

To: Giovans

Many thanks!
I did change your code and it works!

function content_views_operations_clean_node_fields(&$form_values, &$node)
{
  $content_types = content_types($node->type);
  foreach ($content_types['fields'] as $f)
    {
      $field_name = $f[field_name];
      if (!isset($form_values[$field_name]))
        {
//  $node->$field_name = array();
  unset($node->$field_name);
         }

    }
}

mdekkers’s picture

Assigned: Unassigned » mdekkers
Status: Active » Closed (won't fix)

This Module will no longer be maintained (shocker) as this functionality is mainly present in VBO and thats what we started using internally.