Posted by moshe weitzman on December 23, 2008 at 2:46pm
4 followers
| Project: | Field Actions |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Issue Summary
Would be a great action to use along with Views Bulk Operations module. Might as well do user reference as well.
Comments
#1
You have my attention. Care to elaborate?
#2
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.
#3
It does, though I can't get to writing the patch right now, I'd accept one to do that.
#4
Added in cvs revision 1.6.2.2 (DRUPAL-6--1).
#5
Automatically closed -- issue fixed for 2 weeks with no activity.
#6
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.
#7
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
#8
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.