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

Diff of /contributions/modules/node_form_rearrange/node_form_rearrange.module

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

revision 1.2, Mon Nov 17 22:55:04 2008 UTC revision 1.3, Thu Sep 3 20:52:16 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: node_form_rearrange.module,v 1.1 2008/11/17 21:08:10 chiddicks Exp $  // $Id:
3    
4  /**  /**
5   * @file   * @file
# Line 8  Line 8 
8   */   */
9    
10  /**  /**
11     * Implementation of hook_menu().
12     */
13    function node_form_rearrange_menu() {
14      $items = array();
15      $items['admin/settings/node-form-rearrange'] = array(
16        'title' => 'Node Form Rearrange Settings',
17        'page callback' => 'drupal_get_form',
18        'page arguments' => array('node_form_rearrange_settings'),
19        'access arguments' => array('administer nodes'),
20        'type' => MENU_NORMAL_ITEM,
21      );
22      return $items;
23    }
24    
25    /**
26     * Form builder
27     * Implementation of hook_settings().
28     */
29    function node_form_rearrange_settings() {
30      $form = array();
31      $types = node_get_types('names');
32      $form['node_form_rearrange_content_types'] = array(
33        '#type' => 'checkboxes',
34        '#description' => 'Check the content types for which you want to use the Form Rearrange Functions',
35        '#title' => t('Rearrange Content Types'),
36        '#options' => $types,
37        '#default_value' => variable_get('node_form_rearrange_content_types', array(0)),
38        '#required' => TRUE,
39      );
40      return system_settings_form($form);
41    }
42    
43    
44    /**
45   * Implementation of hook_form_alter().   * Implementation of hook_form_alter().
46   */   */
47    
48  function node_form_rearrange_form_alter(&$form, $form_state, $form_id) {  function node_form_rearrange_form_alter(&$form, $form_state, $form_id) {
49    if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) {    if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] .'_node_form' == $form_id) {
50      //retrieve all vocabularies for this node's content type          $types = variable_get('node_form_rearrange_content_types', array(0));
51      $vocabularies = db_query(db_rewrite_sql("SELECT v.* FROM {vocabulary} v INNER JOIN {vocabulary_node_types} n ON v.vid = n.vid WHERE n.type = '%s'          if(isset($types[$form['type']['#value']]) && ($types[$form['type']['#value']] != '0')) {
52  ORDER BY v.weight, v.name", 'v', 'vid'), $form['type']['#value']);        //retrieve all vocabularies for this node's content type
53      //loop through vocabularies, moving their form element out of the taxonomy fieldset        $vocabularies = db_query(db_rewrite_sql("SELECT v.* FROM {vocabulary} v INNER JOIN {vocabulary_node_types} n ON v.vid = n.vid WHERE n.type = '%s'
54      while ($vocabulary = db_fetch_object($vocabularies)) {    ORDER BY v.weight, v.name", 'v', 'vid'), $form['type']['#value']);
55      //check to see if non-tag vocabularies exist        //loop through vocabularies, moving their form element out of the taxonomy fieldset
56      if ($form['taxonomy'][$vocabulary->vid]) {        while ($vocabulary = db_fetch_object($vocabularies)) {
57          $field = $form['taxonomy'][$vocabulary->vid];        //check to see if non-tag vocabularies exist
58          unset($form['taxonomy'][$vocabulary->vid]);        if ($form['taxonomy'][$vocabulary->vid]) {
59          $form["taxonomy_field_$vocabulary->vid"] = $field;            $field = $form['taxonomy'][$vocabulary->vid];
60        }            unset($form['taxonomy'][$vocabulary->vid]);
61        //check to see if tag vocabularies exist            $form["taxonomy_field_$vocabulary->vid"] = $field;
62        if ($form['taxonomy']['tags'][$vocabulary->vid]) {          }
63          $field = $form['taxonomy']['tags'][$vocabulary->vid];          //check to see if tag vocabularies exist
64          unset($form['taxonomy']['tags'][$vocabulary->vid]);          if ($form['taxonomy']['tags'][$vocabulary->vid]) {
65          $form["taxonomy_field_tags_$vocabulary->vid"] = $field;            $field = $form['taxonomy']['tags'][$vocabulary->vid];
66        }            unset($form['taxonomy']['tags'][$vocabulary->vid]);
67        // Direct copy from content.module, for setting the weight of fields based on arrangement in admin/content/node-type/[content type]/fields            $form["taxonomy_field_tags_$vocabulary->vid"] = $field;
68        $type = content_types($form['type']['#value']);          }
69        foreach ($type['extra'] as $key => $value) {          // Direct copy from content.module, for setting the weight of fields based on arrangement in admin/content/node-type/[content type]/fields
70          if (isset($form[$key])) {          $type = content_types($form['type']['#value']);
71            $form[$key]['#weight'] = $value['weight'];          foreach ($type['extra'] as $key => $value) {
72              if (isset($form[$key])) {
73                $form[$key]['#weight'] = $value['weight'];
74              }
75          }          }
76        }        }
77          //Removing now empty taxonomy fieldset
78          if (isset($form['taxonomy'])) {
79            unset($form['taxonomy']);
80          }
81      }      }
     //Removing now empty taxonomy fieldset  
     if (isset($form['taxonomy'])) {  
       unset($form['taxonomy']);  
     }  
   
82    }    }
83  }  }
84    

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

  ViewVC Help
Powered by ViewVC 1.1.2