Project:Flexifield
Version:6.x-1.x-dev
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:needs review

Issue Summary

On #259837: Nodereferrer Drupal 6 patches + zip + Views integration there is a NodeReferrer patch to allow the use of nodereferrer function on Drupal 6.x. It aims to "provides a counter part to CCK's nodereference fields"

Now, this function doesn't work within Flexi-field, maybe a control statement should be added on nodereferrer_referrers:

<?php
  $values
= array();
  foreach(
$fieldnames as $fieldname) {
  
/* if ($fields[$fieldname]['type'] == 'flexifield') {
           # LOOK FOR TYPE nodereference within flexifield
    }*/
   
elseif ($fields[$fieldname]['type'] == 'nodereference') {
     
$db_info = content_database_info($fields[$fieldname]);   

     
$query = "SELECT       n.nid, n.vid, n.title
                FROM         {"
. $db_info['table'] . "} nr
                INNER JOIN   {node} n ON n.vid = nr.vid AND n.status = 1 "
. $filter_nodetypes ."
                WHERE        nr."
. $db_info['columns']['nid']['column'] . " = %d
                ORDER BY     "
. $order;
     
     
$query = db_rewrite_sql($query);
     
$result = db_query($query, $nid);

      while (
$value = db_fetch_array($result)) {
       
// avoid duplicate referrers by using nid as key
       
$values[$value['nid']] = $value;
      }
    }
  }
  return
$values;
?>

Any idea to make it works?

Comments

#1

Status:active» needs review

Here's an ugly but working patch. Put it after foreach($fieldnames as $fieldname) {

<?php
   
/**
      * nodereferrer_referrers($node->nid, array('field_work', array('flexifield'=>'field_voice_actors', 'nodereference'=>'field_work')), Array('char'));
    1) get referrers to $nid from field_work for content type 'char'
    2) get referrers to $nid from field_work on field_voice_actors flexifield for content type 'char'
     **/
    # if $fieldname is an array with both indexes flexifield and nodereference,
    #  get nodereferrers from nodereference fields stored in specified flexifield
   
if ($fields[$fieldname['flexifield']]['type'] == 'flexifield' && is_array($fieldname) && array_key_exists('flexifield', $fieldname) && array_key_exists('nodereference', $fieldname)) {
   
$db_info = content_database_info($fields[$fieldname['flexifield']]);
       
$query = "SELECT       n.nid, n.vid, n.title, nr." . $fieldname['flexifield'] . "_value
                FROM         {"
. $db_info['table'] . "} nr
                INNER JOIN   {node} n ON n.vid = nr.vid AND n.status = 1 "
. $filter_nodetypes ."
                WHERE        1
                ORDER BY     "
. $order;
       
$query = db_rewrite_sql($query);
       
$result = db_query($query, $nid);


      while (
$array = db_fetch_array($result)) {
   
$myarray = unserialize($array[$fieldname['flexifield'].'_value']);
   
# display only fields referring the right node:
    #    supports multiple values, where available
   
for($i=0; $i<count($myarray[$fieldname['nodereference']]); $i++) {
     if(
$myarray[$fieldname['nodereference']][$i]['nid']==$nid){
        
// avoid duplicate referrers by using nid as key
           
$values[$array['nid']] = $array['nid'];
     }
        }
      }
    }
?>

To specify both flexifield and nodereference field contained in, $fieldname can be an array with 'flexifield' and 'nodereference' keys.

Question: this patch should be attached to this project (as nodereference and userreference ones) or directly to NodeReferrer project? Thanks.

#2

Has anyone submitted chirale's code or something similar as a .patch file to get Node Referrer to recognize a node reference field that is part of a flexifield?

I posted a feature request (with a link back to this issue) for flexifield support in the Node Referrer issues queue yesterday #430876: NodeReferrer and Flexifield, and the developer of that module did reply. However, I'm not a programmer and don't really understand what the developer suggests, and wouldn't be able to code it if I did understand.

Considering how amazingly useful Flexifield and Node Referrer both are, I'm sure others are going to need this feature. My extremely inelegant workaround now is to require the noderef field to be entered twice when creating/editing a node that has the flexifield - once as part of the flexifield, and once as its own noderef field. Obviously, I want to eliminate that redundancy.

Apologies for posting about the same matter under both projects.

#3

I've found that the multigroup module #119102: Combo field - group different fields into one (see comment no. 512) plays nice with Node Referrer and does what I need, so I'm now using that instead of Flexifield for the site I'm working on. Multigroup apparently has other limitations, though, so it may not be a solution for everyone.

nobody click here