Would be a great action to use along with Views Bulk Operations module. Might as well do user reference as well.

Comments

deekayen’s picture

Status: Active » Postponed (maintainer needs more info)

You have my attention. Care to elaborate?

moshe weitzman’s picture

The action's configuration would ask the admin to set which node ref he wants to set, and what the value of the node ref would be. Then when the action fires, it sets the node ref field to the specified nid. Hope that makes sense.

deekayen’s picture

Status: Postponed (maintainer needs more info) » Active

It does, though I can't get to writing the patch right now, I'd accept one to do that.

deekayen’s picture

Version: 5.x-1.0 » 6.x-1.x-dev
Status: Active » Fixed

Added in cvs revision 1.6.2.2 (DRUPAL-6--1).

Status: Fixed » Closed (fixed)

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

jon nunan’s picture

Status: Closed (fixed) » Active

Any chance to get the reverse as well?

That way we can use VBO to select all the 'child nodes' in a relationship and then apply them in bulk to the one parent node.

I hacked this in for myself by putting the following code into 'field_assign_value_to_nodereference_action':

  if ($context['nr_flip_value'] == true){
    $parent_node = node_load($context['nr_field_value']);
    if (isset($parent_node)){
      if (isset($parent_node->{$context['nr_field_name']}[0])) {
        $parent_node->{$context['nr_field_name']}[]['nid'] = $node->nid;
        $parent_node->revision ='0';
        if (!$context['defer']) {
          node_save($parent_node);
        }
        watchdog('fieldactions', 'Changed value of node reference field %field in node %id to reference %nid.', array('%field' => $context['nr_field_name'], '%nid' => intval($node->nid), '%id' => intval($context['nr_field_value'])), WATCHDOG_INFO);
      }else{
        watchdog('fieldactions', 'Could not reset the value of node reference %field in node %id to %nid because it did not contain the specified node reference field.', array('%field' => $context['nr_field_name'], '%nid' => intval($node->nid), '%id' => intval($context['nr_field_value'])), WATCHDOG_NOTICE);
      }
    }else{
      watchdog('fieldactions', 'Could not change node reference field %field in node %id to reference %nid because node doesn\'t exist.', array('%field' => $context['nr_field_name'], '%nid' => intval($node->nid), '%id' => intval($context['nr_field_value'])), WATCHDOG_INFO);
    }
  }else{
  //existing code here

'nr_flip_value' is just a checkbox I added to the form to enable the new functionality when required.

hunmonk’s picture

here's a post that completely lays out how to accomplish this in a custom module -- i'm sure it would be trivial to incorporate this into field actions:

http://drupal.org/node/628544

hunmonk’s picture

Status: Active » Needs review
StatusFileSize
new95.27 KB
new4.77 KB

and, here's a patch that adds the requested functionality from #6. tested pretty thoroughly, and works perfectly for me.

i attached a screenshot of the configurable action form -- i'm not crazy about the usability of it, but there are complications with making it more elegant: namely, nodereference fields have to know the field in order for the fancy autocomplete to work properly. the best alternate approach i could think of was to start by displaying just the select of the nodereference fields, then on another form display the autocomplete for that field -- but i have no idea if multi-step even works w/ action forms, and/or if that would screw up how views bulk operations would work. therefore, i've decided that the current UI is fine as is... ;)

i also cleaned up the function that pulls all the nodereference fields, to also add the human-readable node type the field is attached to, and to sort on the descriptions.

deekayen’s picture

Issue summary: View changes
Status: Needs review » Patch (to be ported)

Committed to 6.x-1.x. 7.x-1.x is pending.