/[drupal]/contributions/modules/addnode/addnode.module
ViewVC logotype

Diff of /contributions/modules/addnode/addnode.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.2 by lionfish, Wed May 2 17:53:47 2007 UTC revision 1.3 by panis, Wed Jul 9 15:43:40 2008 UTC
# Line 3  Line 3 
3    
4  /**  /**
5   * @file   * @file
6   * Allows users to create nodes instead of selecting them from a list   * Extension of nodereference allows user to either select existing nodes
7   *   * or create new nodes via a popup window. Also lets user reorder the attached
8   * @author Obslogic (Mike Smith aka Lionfish)   * nodes as they are attached.
9   */   */
10    
11    
# Line 18  function addnode_help($section='') Line 18  function addnode_help($section='')
18    switch ($section)    switch ($section)
19    {    {
20      case "admin/help#addnode":      case "admin/help#addnode":
21        $output = '<p>'.t("Provides an option to the user to create a new node type.").'</p>';        $output = '<p>' .  t("Extension of nodereference allows user to either select existing nodes or create new nodes via a popup window. Also lets user reorder the attached nodes as they are attached.") . '</p>';
22        break;        break;
23    }    }
24    return $output;    return $output;
# Line 41  function addnode_widget_info() Line 41  function addnode_widget_info()
41  /**  /**
42   * Implementation of hook_widget   * Implementation of hook_widget
43   */   */
44  function addnode_widget($op, &$node, $field, &$node_field)  function addnode_widget($op, &$node, $field, &$items)
45  {  {
46      //need this module for the_nodereference_potential_references function.    //need this module for the_nodereference_potential_references function.
47    include_once(drupal_get_path('module', 'content').'/nodereference.module');    include_once(drupal_get_path('module', 'content').'/nodereference.module');
48    
49    if ($field['widget']['type'] == 'addnode_select')    if ($field['widget']['type'] == 'addnode_select')
50    {    {
51      switch ($op) {      switch ($op) {
52    
53                            //prepare hook load the node order from the database if available
54                            //rearrange the nids in that sequence and return the list.
55        case 'prepare form values':        case 'prepare form values':
56             //puts node_field (original) values into a temporary bit of the array called default nids  
57          $node_field_transposed = content_transpose_array_rows_cols($node_field);          $items_transposed = content_transpose_array_rows_cols($items);
58          $node_field['default nids'] = $node_field_transposed['nid'];          $nids = $items_transposed['nid'];
59                                    $order = db_result(db_query("SELECT weights FROM {addnode_order} WHERE nid=%d AND fieldname='%s'", $node->nid, $field['field_name']));
60    
61                                    //if there is a curent list of nids.
62                                    if (is_array($nids)) {
63    
64                                      //find out the order - order is stored as a string of nids.
65                                            $order = $order? array_keys(explode(',', $order), 0):array();
66    
67                                            //new nids not already ordered are captured in the missing array.
68                              $unordered = array();
69    
70                                            //look at each nid and if it is in the ordered list keep it in the
71                                            //ordered list else collect it in the unordered array to append to the
72                                            //ordered list.
73                                            foreach ($nids as $nid) {
74                                                    if (!array_key_exists($nid, $order)) {
75                                                            $unordered[$nid] = 1;
76                                                    }
77                                                    else {
78                                                            $order[$nid] = 1;
79                                                    }
80                                            }
81    
82                                            //filter will take out all the nids that we have not used.
83                                            $order = array_filter($order);
84    
85                                            //this is the final list of nids - ordered ones preceeding
86                                            //the unordered ones.
87                                            $nids = $order + $unordered;
88                                            //only need the keys.
89                                            $nids = array_keys($nids);
90                                    }
91                                    else {
92                                            $nids = array();
93                                    }
94    
95                                    //here is the new order containing the final set of nids.
96                                    $order = implode(',', $nids);
97    
98                                    //pass this along to the form call
99                                    $items['default nids'] = $nids;
100                                    $items['node_order'] = $order;
101          break;          break;
       case 'form':  
           //adds javascript  
         $path = drupal_get_path('module','addnode');  
         drupal_add_js($path . '/addnode.js');  
102    
103          case 'form':
104          $form = array();          $form = array();
105          $selectedoptions = array();          $fieldname=$field['field_name'];
106            $title=t($field['widget']['label']);
107    
108             //gets the list of all potential nodes that could be referenced          //gets the list of all potential nodes that could be referenced
109          $options = _nodereference_potential_references($field, true);          $options = _nodereference_potential_references($field, true);
   
110          foreach ($options as $key => $value) {          foreach ($options as $key => $value) {
111            $options[$key] = _nodereference_item($field, $value);            $options[$key] = _nodereference_item($field, $value);
112          }          }
113    
114           //string describing what can be added. If there's one type it will be that, otherwise it will be          //string describing what can be added.
          //just 'item'.  
115          $typedesc = "";          $typedesc = "";
116          $type_count=0;  //counts up how many types there are          $type_count=0;  //counts up how many types there are
117          $type_list=array(); //list of the types          $type_list=array(); //list of the types
118    
119            //If referenceable_types is not an array, give up.          //If referenceable_types is not an array, give up.
120          if (!is_array($field['referenceable_types']))          if (!is_array($field['referenceable_types'])) {
         {  
121            return $form;            return $form;
122          }          }
123    
124            //add referenceable types to the $type_list array          //add referenceable types to the $type_list array
125          foreach ($field['referenceable_types'] as $ref_type)          foreach ($field['referenceable_types'] as $ref_type) {
126          {            if ($ref_type) {
           if ($ref_type)  
           {  
127              $typedesc = $ref_type;              $typedesc = $ref_type;
128              $type_count++;              $type_count++;
129              $type_list[] = $ref_type;              $type_list[] = $ref_type;
# Line 93  function addnode_widget($op, &$node, $fi Line 131  function addnode_widget($op, &$node, $fi
131          }          }
132    
133          //if there are no types available, give up.          //if there are no types available, give up.
134          if ($type_count==0)          if ($type_count==0) {
         {  
135            //@todo Need to display something explaining the problem.            //@todo Need to display something explaining the problem.
136                                            $form[$fieldname]['error'] = array(
137                                                    '#type' => 'markup',
138                                                    '#title' => $title,
139                                                    '#value' => '<div class="error">This field does not have any content types configured to be displayed. Please contact your administrator if you think you have reached this in error</div>',
140                                            );
141            return $form;            return $form;
142          }          }
           //converts the type name to a human readable one  
         $typedesc = node_get_types('type', $typedesc)->name;  
143    
144            //If there's more than one type available then we use the term 'item' to describe them          //converts the type name to a human readable one
145          if ($type_count>1)          $typedesc = node_get_types('type', $typedesc);
146          {          $typedesc = $typedesc->name;
147    
148             //If there's more than one type available then we use the term 'item' to describe them
149            if ($type_count>1) {
150            $typedesc = "item";            $typedesc = "item";
151          }          }
152    
153          $fieldname=$field['field_name'];                                  //if this field supports multiple selections then the select list
154          $title=t($field['widget']['label']);                                  //stays in the "to_" list else it is stored in the select identified
155                                    //by the fieldname itself.
156          //$createmsg is a message such as "Create a new _fund_ or _pot_" with links in.                                  if($field['multiple']) {
157          $createmsg=_addnode_create_new_message($type_count, $fieldname, $type_list);                                          $output = theme('addnode_link', $type_list,'updateNewNodes', 'to_' . $fieldname, 'icon');
158                                    } else {
159          $prefix = '';                                          $output = theme('addnode_link', $type_list,'updateNewNodes', $fieldname, 'icon');
160          $suffix = '';                                  }
161          $subsuffix = "";  
162                                    //create the link to create new nodes.
163     //this prefix builds the table headers etc.          $new_link= "<b>$title:</b>";
164          $prefix = "";          $new_link.= t("Select !typedesc already available", array('!typedesc'=>"$typedesc"));
165          $prefix.= "<b>$title:</b>";          $new_link.= ' or click here to add a new one ' . $output .'<br>';
         $prefix.= "<table style='width:60%; position:relative; left:10%;'>";  
         $prefix.= "<tr>";  
         $prefix.= "<th style='width:50%'>";  
         $prefix.= "<a href='javascript:;' id='$fieldname' class='addnode_select_link'>";  
         $prefix.= t("Select</a> !typedesc already available</th>", array('!typedesc'=>"$typedesc"));  
         $prefix.= "<th style='width:50%'>";  
         $prefix.= $createmsg;//msg that says 'Create an item' or whatever  
         $prefix.= "</th>";  
         $prefix.= "</tr>";  
         $prefix.= "<tr>";  
         $prefix.= "<td style='vertical-align:top;'>";  
    //select box goes here  
         $suffix.= "</td>";  
         $suffix.= "<td>";  
    //the subforms go here  
      //the last subform must suffix with:  
         $subsuffix.= "</td>";  
         $subsuffix.= "</tr>";  
         $subsuffix.= "</table>";  
   
 ///This hidden form element has been moved above the subforms to allow it to be processed before their  
 ///#after_build functions run (as they will need the values in this element).  
         //whether we've selected something from the select box, or created a new item  
         //is stored in this hidden field. So the submit functions know what to do.  
         $form["addnode_".$fieldname] = array(  
           '#type' => 'hidden',  
           '#title' => t('selection or creation'),  
           '#default_value' => '',  
           '#attributes' => array (  
             'class' => 'addnode_source',  
           ),  
         );  
   
         $weight = $field['weight'];  
166    
         //select box  
167          $form[$fieldname]['#tree'] = TRUE;          $form[$fieldname]['#tree'] = TRUE;
168          $form[$fieldname]['nids'] = array(                                  $form[$fieldname]['newnode'] = array(
169            '#type' => 'select',                                          '#type' => 'markup',
170            '#title' => '', //no title for this bit                                          '#value' => $new_link,
171            '#default_value' => $node_field['default nids'],                                  );
172            '#multiple' => TRUE,  
173            '#options' => $options,  
174            '#required' => $field['required'],                                  //if multiple select is enabled then allow the user to move the
175            '#description' => $field['widget']['description'],                                  //selected items from one select box to another and reordered the
176            '#prefix' => $prefix,                                  //selected items.
177            '#suffix' => $suffix,          if ($field['multiple']) {
178            '#size' => 15,  
179            '#weight' => $weight,                                          //take the list of all available items and make 2 lists from it
180            '#attributes' => array(                                          //one that is of the selected items (to_list) and the other one
181              'style' => 'width:90%',                                          //the available (from_list) items.
182              'class' => "addnode_select",                                          if( is_array($items['default nids'] ))  {
183              'id' => "$fieldname",                                                  foreach ($items['default nids'] as $nid) {
184            ),                                                          if(in_array($nid, array_keys($options))) {
185          );                                                                  $to_list[$nid] = $options[$nid];
186                                                                    $options[$nid] = 0;
187          //loops through the types this field can be.                                                          }
188          foreach ($type_list as $typename)                                                  }
189          {                                                  $from_list = array_filter($options);
190            $weight = $weight + 0.1;//puts them in an order.                                          }
191                                            else {
192            $subnode = array('uid' => $node->uid, 'type' => $typename);                                                  $from_list = $options;
193              //the name of the array below this field type, needed to divide the subforms.                                                  $to_list = array();
194            $subfieldname = 'node_'.$typename;                                          }
195            $form[$fieldname][$subfieldname] = array(  
196              '#type' => 'subform',                                          //cannot have any of the lists empty so send in a "none"
197              '#id' => $typename.'_node_form',                                          //option if the select list is empty
198              '#arguments' => array($subnode),                                          if(count($to_list) == 0) { $to_list[0] = 'None'; }
199              '#weight' => $weight,                                          if(count($from_list) == 0) { $from_list[0] = 'None'; }
200              '#prefix' => "<span class='addnode_form $fieldname' id='$typename'>",  
201              '#suffix' => "</span>",                                          //markup to wrap the fields in a table.
202              '#after_build' => array('subform_element_build_subform','addnode_fix_subform'),                                          $form[$fieldname]['t1'] = array(
203              '#fieldname' => $fieldname,                                                  '#type' => 'markup',
204              '#extra_form' => array("#fieldname"=>$fieldname),                                                  '#value' => '<table><tr><td valign="top">',
205            );                                          );
206          }  
207          //updates the last suffix to include the subsuffix (which closes the table)                                          //select lists for available references that can be added
208          $form[$fieldname][$subfieldname]['#suffix'] .= $subsuffix;                                          //note the #DANGEROUS_SKIP_CHECK flag below - this is a hidden
209                                            //feature in drupal to skip checking of select lists on a submit to
210                                            //make sure that the list options etc have not changed. Because we
211                                            //will be dynamically manipulating the select lists via javascript
212                                            //drupal will throw errors if this check is enabled.
213                                            $form[$fieldname]['from_nids'] = array(
214                                                    '#type' => 'select',
215                                                    '#title' => t('Available References'),
216                                                    '#multiple' => $field['multiple'],
217                                                    '#options' => $from_list,
218                                                    '#required' => FALSE,
219                                                    '#description' => $field['widget']['description'],
220                                                    '#size' => 15,
221                                                    '#weight' => $field['weight'],
222                                                    '#DANGEROUS_SKIP_CHECK' => true,
223                                                    '#attributes' => array(
224                                                            'id' => "from_$fieldname",
225                                                    ),
226                                            );
227    
228                                            $form[$fieldname]['t2'] = array(
229                                                    '#type' => 'markup',
230                                                    '#value' => '</td><td valign="middle">',
231                                            );
232    
233                                            $form[$fieldname]['add'] = array(
234                                                    '#type' => 'markup',
235                                                    '#value' => '<input type="button" onclick="addnode_add_item(\'' . $fieldname . '\');" value="&rarr;" class="faq_arrow"/><br />',
236                                            );
237                                            $form[$fieldname]['remove'] = array(
238                                                    '#type' => 'markup',
239                                                    '#value' => '<input type="button" onclick="addnode_remove_item(\'' . $fieldname . '\');" value="&larr;" class="faq_arrow"/><br />',
240                                            );
241    
242                                            $form[$fieldname]['t3'] = array(
243                                                    '#type' => 'markup',
244                                                    '#value' => '</td><td valign="top">',
245                                            );
246    
247                                            //select list contains the selected nodes. note comment on
248                                            //DANGEROUS_SKIP_CHECK above in the from_nids
249                                            $form[$fieldname]['to_nids'] = array(
250                                                    '#type' => 'select',
251                                                    '#title' => t('Currently Attached References'),
252                                                    '#options' => $to_list,
253                                                    '#required' => $field['required'],
254                                                    '#description' => $field['widget']['description'],
255                                                    '#size' => 15,
256                                                    '#multiple' => TRUE,
257                                                    '#weight' => $field['weight'],
258                                                    '#DANGEROUS_SKIP_CHECK' => true,
259                                                    '#attributes' => array(
260                                                            'id' => "to_$fieldname",
261                                                            'class'=> 'addnode-select',
262                                                    ),
263                                            );
264    
265                                            //the order of the nodes is stored in a hidden field updated
266                                            //by javascript right before the submit of the form.
267                                            $form[$fieldname]['nids'] = array(
268                                                    '#type' => 'hidden',
269                                                    '#attributes' => array('class' => 'addnode-order'),
270                                                    '#default_value' => $items['node_order'],
271                                            );
272    
273                                            //control buttons - buttons to move items from one list to the
274                                            //other and to rearrange the existing list.
275                                            $form[$fieldname]['move_up'] = array(
276                                                    '#type' => 'markup',
277                                                    '#value' => '<input type="button" onclick="addnode_move_item_up(\'' . $fieldname . '\');" value="&uarr;" class="faq_arrow"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
278                                            );
279                                            $form[$fieldname]['move_down'] = array(
280                                                    '#type' => 'markup',
281                                                    '#value' => '<input type="button" onclick="addnode_move_item_down(\'' . $fieldname . '\');" value="&darr;" class="faq_arrow"/><br />',
282                                            );
283                                            $form[$fieldname]['t4'] = array(
284                                                    '#type' => 'markup',
285                                                    '#value' => '</td></tr></table>',
286                                            );
287                                    }
288                                    else {
289                                            //single select field just display a ordinary select list.
290                                            $form[$fieldname]['nids'] = array(
291                                                    '#type' => 'select',
292                                                    '#title' => '',
293                                                    '#multiple' => $field['multiple'],
294                                                    '#options' => $options,
295                                                    '#default_value' => $items['default nids'],
296                                                    '#required' => $field['required'],
297                                                    '#description' => $field['widget']['description'],
298                                                    '#size' => 15,
299                                                    '#weight' => $field['weight'],
300                                                    '#attributes' => array(
301                                                            'id' => "$fieldname",
302                                                    ),
303                                            );
304                                    }
305    
            //add submit handlers:  
           //Add the nids of the newly created sub-nodes to the node  
         $form['#submit']['addnode_addnids_submit'] = array();  
           //the subform element submit handler  
         $form['#submit']['subform_element_submit'] = array();  
           //the handler for the base node (todo: Is this still necessary, I think subform_element might do this)  
         $form['#submit']['node_form_submit'] = array();  
   
306          return $form;          return $form;
307    
308        case 'process form values':        case 'process form values':
309          $node_field = content_transpose_array_rows_cols(array('nid' => $node_field['nids']));  
310                                    //process the returned results and rearrange the data fields for
311                                    //processing by the CCJ module.
312            if ($field['multiple']) {
313                                            $node_order = $items['nids'];
314                                            $items['nids'] = explode(',', $node_order);
315    
316              if (empty($items['nids'])) {
317                $items['nids'] = array(0 => '0');
318              }
319    
320              $items = array_values(content_transpose_array_rows_cols(array('nid' => $items['nids'])));
321    
322                                            //save the order of the items - delete any existing order and
323                                            //replace with a new one - this dispenses the check for existing order
324                                            //and an update or an insert otherwise..
325                                            db_query("DELETE FROM {addnode_order} WHERE nid=%d AND fieldname='%s'",
326                                                                                    $node->nid, $field['field_name']);
327                                            db_query("INSERT INTO {addnode_order} (nid,fieldname,weights) VALUES (%d,'%s', '%s')", $node->nid, $field['field_name'], $node_order);
328    
329                                            // Remove the widget's data representation so it isn't saved.
330                                            unset($items['nids']);
331                                            unset($items['from_nids']);
332                                            unset($items['to_nids']);
333                                            unset($node_order);
334            }
335            else {
336              $items[0]['nid'] = $items['nids'];
337                                            // Remove the widget's data representation so it isn't saved.
338                                            unset($items['nids']);
339            }
340          break;          break;
341        case 'submit':        case 'submit':
342          break;          break;
# Line 217  function addnode_widget($op, &$node, $fi Line 344  function addnode_widget($op, &$node, $fi
344    }    }
345  }  }
346    
347  /**  function addnode_menu($may_cache) {
348   * This is called as an #after_build function for each subform.  
349   *It 1) Disables the subform's validation etc if it's unused    $items = array();
350   *   2) Removes the subform's buttons.    if ($may_cache) {
351   */      $items[] = array(
352  function addnode_fix_subform($form_element, &$form_values)        'path' => 'addnode/load',
353  {        'title' => t('Node Assist Thumbnails'),
354    //get the subform array (from the subform_element module)        'callback' => 'addnode_load',
355    global $subforms;        'access' => user_access('access content'),
356          'type' => MENU_CALLBACK);
357        $items[] = array(
358          'path' => 'addnode/add',
359          'title' => t('Node Assist Create New'),
360          'callback' => 'addnode_add',
361          'access' => user_access('access content'),
362          'type' => MENU_CALLBACK);
363        $items[] = array(
364          'path' => 'admin/settings/addnode',
365          'title' => t('Node assist'),
366          'description' => t('Change settings for the Node assist module.'),
367          'callback' => 'drupal_get_form',
368          'callback arguments' => 'addnode_admin_settings',
369          'access' => user_access('administer site configuration'),
370          'type' => MENU_NORMAL_ITEM); // optional
371      }
372      else {
373                    //load our javascript functions.
374        $path = drupal_get_path('module','addnode');
375        drupal_add_js($path . '/addnode.js');
376        drupal_add_css($path .'/addnode.css', 'module', 'all', TRUE);
377                    drupal_add_js($path . '/thickbox.js');
378                    drupal_add_css($path . '/thickbox.css');
379      }
380    
381    //the type of node to create    return $items;
382    $nodetype = $form_element['#arguments'][0]['type'];  }
   //the name of the field the addnode widget is for  
   $current_fieldname = $form_element['#fieldname'];  
383    
384    //for each field in the form, look for addnode_[blah]  /**
385    foreach($form_values as $key => $value)   * Theme for adding an image link underneath textareas
386    {   */
387      //if the field key begins 'addnode_' then it's one of the hidden fields, we use these to identify the names of potential subforms  function theme_addnode_link($node_types, $callback_fn, $callback_arg, $link) {
388      if (strpos($key, 'addnode_') === 0)    $instance = $callback_arg;
389      {          $_SESSION['addnode'][$instance] = array();
390        //get the fieldname (the bit after the 'addnode_' in the key).    $_SESSION['addnode'][$instance]['node_types'] = $node_types;
391        $fieldname = substr($key, 8);    $_SESSION['addnode'][$instance]['callback_fn'] = $callback_fn;
392        if ($fieldname == $current_fieldname)    $_SESSION['addnode'][$instance]['callback_arg'] = $callback_arg;
393        {    $_SESSION['addnode'][$instance]['nids'] = array();
394          //find out which subform's the source (it will be the value of this key).  
395          $source = $value;    $output  = '<div class="addnode-button"><a class="thickbox addnode-link" id="addnode-link-'. $id .'" title="'. t('Add New Content') .'" href="'. url('addnode/load/'.$instance, 'TB_iframe=true&height=350&width=600') .'">';
396      //if it's not '' then we're creating a new node. (if it is '' then we must be using the select box).    $output .= ($link == 'icon') ? '<img src="'. base_path() . drupal_get_path('module', 'addnode') .'/newdocument.gif" border="0" alt="'. t('New') .'" />' : t('New');
397      //in other words, we disable subform processing if $source = '' or it's not related to this subform    $output .= '</a></div>';
398          $disable = TRUE;    return $output;
399    }
         if (strlen($source)>0) //if we're not using the select box...  
         {  
           if ($source == $nodetype) //and we've chosen this subform over any other  
           {  
             $disable = FALSE;  
           }  
         }  
400    
401          if ($disable) //disable this subform as it's not being used.  /**
402          {   * Implementation of hook_nodeapi().
403            $form_element['#validate'] = array();   *
404          }   * - Keep track of where nids are used.
405     * - Catch nids of recently created nodes.
406     */
407    function addnode_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
408      switch ($op) {
409        case 'insert':
410        case 'update':
411         // Put nid into a global if this node is created with addnode:
412          if (arg(0) == 'addnode') {
413                                    $instance = arg(2);
414            $_SESSION['addnode'][$instance]['nids'][$node->nid] = $node->title;
415        }        }
416      }        break;
417        case 'delete':
418          break;
419    }    }
420    }
421    
422  //Remove submit and preview buttons from the subform.  
423    $form_element['#form']['submit']['#attributes'] = array(  /**
424      'style' => 'height:0px; visibility:hidden;',   * create an empty addnode form.
425    );   **/
426    $form_element['#form']['preview']['#attributes'] = array(  function addnode_add($instance, $node_type='') {
427      'style' => 'height:0px; visibility:hidden;',    global $user;
428    );  
429            if($node_type == '') {
430    return $form_element;                  $output .= t('System Error: Please notify administrator');
431            }
432      else if (node_access('create',$node_type)) {
433        // Define an empty node and fetch an image node form:
434        $node = array('uid' => $user->uid,
435                      'name' => $user->name,
436                      'type' => $node_type,
437                                                                            'addnode_instance' => $instance);
438        $output .= drupal_get_form($node_type . '_node_form', $node);
439      }
440            else {
441                    $output = t('You do not have access to create a: '). $node_type;
442            }
443      print theme('addnode_page', $output, array('id' => 'addnode_upload', 'class' => 'addnode'));
444  }  }
445    
446  /**  /**
447   * Called as a main form submit handler. It submits the subforms and gets the nids then puts them into   * Implementation of hook_alter().
448   * the main node.   * Add a second submit callback which alters the redirect we do not want
449     * the addnode form to redirect to the newly created node.
450   */   */
451  function addnode_addnids_submit($form_id, &$form_values)  function addnode_form_alter($form_id, &$form) {
452  {          if (arg(0) != 'addnode')  return;
453     //copied from subform_element_submit, allows us to get hold of the redirects and get the nids from them          if(isset($form['type'])) {
454    global $subforms;                  if($form['type']['#value'].'_node_form' == $form_id) {
455    if (isset($subforms)) {                          if (!is_array($form['#submit'])) { $form['#submit'] = array(); }
456      foreach ($subforms as $key => $subform) {                          $form['#submit'] += array('addnode_node_form_submit' => array($form));
457        if (!isset($subform['#submitted'])) {                  }
458          $subforms[$key]['#submitted'] = TRUE;          }
         $redirect = subform_element_call('drupal_submit_form', $subform['#post']['form_id'], $subform);  
         $fieldname = $subform['#fieldname'];  
         $split = explode("/", $redirect);  
         $newnid = $split[1];  
         //unset the current array, and replace it with a new array.  
         //note that as multiselect is currently set, this is an array  
         // @todo allow multi/single select!!  
         unset($form_values[$fieldname]['nids']);  
         $form_values[$fieldname]['nids'] = array ( $newnid => $newnid );  
       }  
     }  
     return $redirect;  
   }  
459  }  }
460    
461  /**  /**
462   * This outputs HTML for the 'create new nodetype' link message.   * A second submit callback for node_form.
463   * @param $type_count   * Change the redirect from node/$nid to addnode/properties/$nid.
464   *   Number of types that could be added   */
465   *  function addnode_node_form_submit($form_id, $form_values) {
466   * @param $fieldname    $instance = arg(2);
467   *   The fieldname of this addnode field    // Get the nid of the newly created node (caught by addnode_nodeapi):
468            $nids = array_keys($_SESSION['addnode'][$instance]['nids']);
469            $nid = end($nids);
470            $title = $_SESSION['addnode'][$instance]['nids'][$nid];
471            drupal_goto("addnode/load/$instance/$nid/$title");
472    }
473    
474    /**
475     * available node types
476     */
477    function addnode_nodereference_types() {
478            return $_SESSION['addnode']['node_types'];
479    }
480    
481    /**
482     * Load the thumbnail display pane
483   *   *
484   * @param $type_list   * Grabs all images from image.module and loads the thumbnails.
  *   List of types  
485   */   */
486  function _addnode_create_new_message($type_count, $fieldname, $type_list)  function addnode_load($instance, $nid='',$title='') {
487  {    global $user;
   $msg="";  
   $spanmsg.= "<span id='$fieldname' class='addnode_links'>";  
488    
489    //if there's only one type then the message is of the form "Create a new blah"    $node_types = $_SESSION['addnode'][$instance]['node_types'];
490    if ($type_count==1)  
491    {          if(count($node_types) > 1) {
492      $atype=$type_list[0];                  /* show list of node types to create. */
493      $typedesc = node_get_types('type', $atype)->name;                  $output = $nid? t('Add Another:'):t('Add Content:');
494                    $output .= '<ul>';
495                    foreach ($node_types as $n) {
496                            if( node_access('create', $n) ) {
497                                            $output .= '<li>' . l($n, "addnode/add/$instance/$n") . '</li>';
498                            }
499                    }
500                    $output .= '</ul>';
501            }
502            else {
503                    $n = $node_types[0];
504                    if($nid) {
505                            $output = t('Add Another') . ' ' . l($n, "addnode/add/$instance/$n");
506                    }
507                    else {
508                            /* go to node add form of only type. */
509                            drupal_goto("addnode/add/$instance/$n");
510                    }
511            }
512    
513            $args[] = $_SESSION['addnode'][$instance]['callback_fn'];
514            $args[] = $_SESSION['addnode'][$instance]['callback_arg'];
515            $args[] = $nid;
516            $args[] = $title;
517    
518        //pretransmsg is message before translation.          array_walk($args,'_quote');
519      $pretransmsg = "or <a href='javascript:;' class='addnode_item !fieldname' id='!atype'>";          $callbackargs = implode(',',$args);
     $pretransmsg.= "!spanmsg";  
     $pretransmsg.= "create a new !typedesc";  
     $pretransmsg.= "</span>";  
     $pretransmsg.= "</a>";  
     $vars = array('!fieldname' => $fieldname, '!atype' => $atype, '!spanmsg' => $spanmsg, '!typedesc' => $typedesc);  
     $msg.= t($pretransmsg, $vars);  
   }  
520    
521    //if there's more than one type then the message is of the form "Create a new blah or blah"    print theme('addnode_page', $output, array('id' => 'addnode_load', 'onload' => 'addnode_callback('.$callbackargs.');', 'class' => 'addnode'));
522    if ($type_count>1)  }
523    {  
524      $vars = array();  function _quote(&$item, $key) {
525      $msg.= t("or create a new ");          $item = "'$item'";
526      $tempcnt=0;  }
527      foreach ($type_list as $atype)  
528      {  // -----------------------------------------------------------------------
529        $typedesc = node_get_types('type', $atype)->name;  // Theme Functions
530        $msg.= "<a href='javascript:;' class='addnode_item $fieldname' id='$atype'>";  // -------------------------------------------------------------------------
531        $msg.= $spanmsg;  function theme_addnode_page($content, $attributes = NULL) {
532        $msg.= "$typedesc";    $output .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n";
533        $msg.= "</span>";    $output .= '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">'."\n";
534        $msg.= "</a>";    //$output  = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'."\n";
535        $tempcnt++;    //$output .= "<html>\n";
536        if ($tempcnt == $type_count-1)    $output .= "<head>\n";
537        {    $output .= " <title>$title</title>\n";
538          $msg.= t(" or ");    $output .= drupal_get_html_head();
539        }    $output .= drupal_get_js();
540        else    $output .= drupal_get_css();
541        {    $path = drupal_get_path('module', 'addnode') .'/addnode.css';
542          $msg.= t(", ");    $output .= "<style type=\"text/css\" media=\"{$media}\">@import \"" . base_path() . $path ."\";</style>\n";
543        }  
544      }    $output .= "</head>\n";
545    }    $output .= "<body" . drupal_attributes($attributes) .">\n";
546    $msg .= "</span>";  
547    return $msg;    $output .= theme_status_messages();
548    
549      $output .= "\n<!-- begin content -->\n";
550      $output .= $content;
551      $output .= "\n<!-- end content -->\n";
552      $output .= '</body>';
553      $output .= '</html>';
554      return $output;
555  }  }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

  ViewVC Help
Powered by ViewVC 1.1.3