I love using the Node Reference URL Widget, I've used to for a number of sites. One of the common places I use it is for registration forms for an event. This involves two content types: Event & Registration. One of the challenges I constantly seem to have is that there are different types of events that require different types of information to be collected at Registration time.

I'm wondering if anyone has any good ideas about the easiest way to specify in the Event CCK type the fields that are in the registration CCK type that should be hidden because they are irrelevant for the given event. I can (and have been) doing this in the custom module, but it seems to me that there might be an easy way to create a new module, or an enhancement to this one, which would allow for a new content type that would hold the field names that should be hidden when creating a new node from the Node Reference URL Widget.

Ideas?

Comments

quicksketch’s picture

I'm not really sure what's being requested here. Could you describe exactly what you're hoping Node Reference URL Widget would do? Or is this a request asking for another module to do what you're wanting?

darrellduane’s picture

Hi Quicksketch,
I'm thinking this will probably be in another module, although the functionality request is tied closely to NodeReferenceURL, and if it could be included in NodeReferenceURLwidget that'd be great.

More, I'm looking for ideas and tips from others who may have been in a similar situation, I imagine this is functionality that many others would like to have.

I'm asking for an easy way to specify fields to be hidden from display in a piece of content (A) that is referencing another piece of content (B) via Node Reference. There would be a new field that appears in the field listing of B when editing the node that could be configured (by those with the right permissions) that would allow for hiding/disabling any of the fields that appear in Content A. This would allow for different pieces of content (say Events (B)) to specify which fields are needed to be collected for registering for that event in the Event Registration content type (A).

I may write this myself but wanted to make sure I'm not duplicating effort.

darrellduane’s picture

Category: support » feature
Status: Closed (fixed) » Active

OK, I found an easy way to do this, and I wanted to share it with others who might be wanting to do this.

Here is an example based on a CCK type 'event' and another type called 'event_registration'.
event_registration has the field field_reg_event which is a Node Reference to CCK types of 'event', and it uses Node Reference URL. The 'event_registration' CCK type has many fields in it, some of which are not relevant to a given event. To easily configure the fields to be hidden for a given event's event registration form:

1a. Add the field 'field_event_fields_to_hide' to the 'event' CCK type as a text field using the [Check boxes/radio buttons] Form element to edit the data.

1b. Make the Number of Values for this field set to 'Unlimited', and then
enter the names of the fields that you want to be able to hide
as they appear in the Name column of the [Manage Fields] tab of the CCK type.
You can come back and add other fields to this list as needed.

1c. Save this field. Optional: Set default value for this fields;
typically you'll want to default all fields to be hidden (checked)
and then uncheck the fields to make appear for the given event.

2. Add the following code to a custom module for the site. If there
is already a hook_form_alter() function, just add the code inside. Alter
the CCK names event and event_registration to your own specific CCK type
names, and set MODULE_NAME equal to the name of your module

/*
 * Implements hook_form_alter().
 */
function MODULE_NAME_form_alter(&$form, $form_state, $form_id){
 
  if($form_id == 'event_registration_node_form'){
 
      // hide fields based on configuration in the node that is referred to
      // first get values from the event node
      $action = explode('/',$form['#action']); 

      if($action[2] == 'add'){
        // get the referred nid from the form
        if(!isset($action[4]))
          return;
        $event_nid = $action[4];
      }else{
        // get the referred nid from data  
        $form_object = $form['#parameters'][2];
        $event_nid = $form_object->field_reg_event[0]['nid'];
      }

      if(strlen($event_nid)){
        $event = node_load($event_nid);
        foreach ($event->field_event_fields_to_hide AS $idx => $field_name_arr) {
          $fieldname = $field_name_arr['value'];
          unset($form[$fieldname]);
        }
      }else{
        drupal_set_message('referred node nid not found');
      }

   }

}

I don't think there is a way to include this functionality into this module, but if there was I think it'd be a nice addition. Perhaps the answer is to create another module to do this sort of thing so that no PHP coding would be needed.

quicksketch’s picture

Category: feature » support
Status: Active » Fixed

You're right, I don't think this is an appropriate feature for this module.

Status: Fixed » Closed (fixed)

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

pauljb’s picture

Took me hours to find out why it didn't work:

"if(form_id == 'event_registration_node_form')"

should be

"if($form_id == 'event_registration_node_form')"

and node_reference return path: The new node (no redirect)

darrellduane’s picture

Category: feature » support
Status: Active » Closed (fixed)

I updated the code in the comment above to make this fix, thanks for posting your update, pauljp

darrellduane’s picture

Here is the PHP code to use to set the default values in the "fields_to_hide" field of the referenced node.

  $content_types = _content_type_info();
  $fields = $content_types['content types']['your_content_type_name_with_fields_to_hide']['fields'];
  $field_names=array();
  foreach ($fields AS $field_name=>$field) {
    $field_names[$field_name]=$field_name;
 }
 return $field_names;