Closed (fixed)
Project:
Field Inherit
Version:
6.x-1.0
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
8 Jul 2010 at 12:04 UTC
Updated:
23 Jul 2010 at 07:30 UTC
It would be awesome if this module allowed inheritance by node reference.
I made myself a Computed field that does this, but it is only on a proof-of-concept basis. (My skills in module development are far to modest to implement it as a CCK setting, unfortunately.)
I'm attaching the code if it could be of any interest.
Cheers!
// This code can be inserted into a CCK Computed Field to allow the field to inherit values from specified references
// Set parameters
$field_name = "field_name_here";
$reference_name = "field_nodereference_inheritance";
$default_value = "default";
// Start searching on the current node
$tmpnode = $node;
$value = $tmpnode->{$field_name}[0]['value'];
// Parameter for failsafe
$i = 0;
$i_max = 15;
// Keep searching until a value is found or there is no reference to load
// Note that node_load is carried out as a part of loop evaluation
while ($value == '' && ($tmpnode = node_load($tmpnode->{$reference_name}[0]['nid']))) {
$value = $tmpnode->{$field_name}[0]['value'];
// Break if number of recursions is suspiciously high
$i++;
if($i == $i_max) {
dsm("Reached maximum recursion limit when trying to find $field_name inheritance, falling back to defaul value ($default_value).");
break;
}
}
// Set default value, if reasonable
if ($value == '') {$value = $default_value;}
// Set field value
$node_field[0]['value'] = $value;
Comments
Comment #1
joelstein commentedI agree; that's a great idea. I implemented Node Reference support in the 6.x-2.0 release. Please give it a test run and let me know if it works for you.
Comment #2
finex commentedHi, why not write about the new feature in the module description?
Comment #3
joelstein commentedThanks, FiNeX. Forgot to do that. Also forgot to close this ticket. Eek!
Comment #4
joelstein commentedOkay, the description has been updated on the module page. Also, I updated the screenshot.
Comment #5
finex commentedgreat! I've not yet tried this module, but I'll do soon. It looks very interesting.