| 1 |
<?php
|
| 2 |
// $Id:
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Implements three hooks. This allows for form elements provided by the taxonomy
|
| 7 |
* module to be rearranged individually in node add/edit forms.
|
| 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().
|
| 46 |
*/
|
| 47 |
|
| 48 |
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) {
|
| 50 |
$types = variable_get('node_form_rearrange_content_types', array(0));
|
| 51 |
if(isset($types[$form['type']['#value']]) && ($types[$form['type']['#value']] != '0')) {
|
| 52 |
//retrieve all vocabularies for this node's content type
|
| 53 |
$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 |
ORDER BY v.weight, v.name", 'v', 'vid'), $form['type']['#value']);
|
| 55 |
//loop through vocabularies, moving their form element out of the taxonomy fieldset
|
| 56 |
while ($vocabulary = db_fetch_object($vocabularies)) {
|
| 57 |
//check to see if non-tag vocabularies exist
|
| 58 |
if ($form['taxonomy'][$vocabulary->vid]) {
|
| 59 |
$field = $form['taxonomy'][$vocabulary->vid];
|
| 60 |
unset($form['taxonomy'][$vocabulary->vid]);
|
| 61 |
$form["taxonomy_field_$vocabulary->vid"] = $field;
|
| 62 |
}
|
| 63 |
//check to see if tag vocabularies exist
|
| 64 |
if ($form['taxonomy']['tags'][$vocabulary->vid]) {
|
| 65 |
$field = $form['taxonomy']['tags'][$vocabulary->vid];
|
| 66 |
unset($form['taxonomy']['tags'][$vocabulary->vid]);
|
| 67 |
$form["taxonomy_field_tags_$vocabulary->vid"] = $field;
|
| 68 |
}
|
| 69 |
// Direct copy from content.module, for setting the weight of fields based on arrangement in admin/content/node-type/[content type]/fields
|
| 70 |
$type = content_types($form['type']['#value']);
|
| 71 |
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 |
}
|
| 82 |
}
|
| 83 |
}
|
| 84 |
|
| 85 |
/**
|
| 86 |
* Implementation of hook_nodeapi().
|
| 87 |
*/
|
| 88 |
|
| 89 |
function node_form_rearrange_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
|
| 90 |
switch ($op) {
|
| 91 |
case 'presave':
|
| 92 |
$types = variable_get('node_form_rearrange_content_types', array(0));
|
| 93 |
if(isset($types[$node->type]) && ($types[$node->type] != '0')) {
|
| 94 |
$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'
|
| 95 |
ORDER BY v.weight, v.name", 'v', 'vid'), $node->type);
|
| 96 |
//loop through vocabularies, resetting the original data arrangement (fields in taxonomy fieldset) so the taxonomy is saved
|
| 97 |
while ($vocabulary = db_fetch_object($vocabularies)) {
|
| 98 |
$fieldname = 'taxonomy_field_'. $vocabulary->vid;
|
| 99 |
if (isset($node->$fieldname) && $node->$fieldname) {
|
| 100 |
$node->taxonomy[$vocabulary->vid] = $node->$fieldname;
|
| 101 |
unset($node->$fieldname);
|
| 102 |
}
|
| 103 |
$fieldname = 'taxonomy_field_tags_'. $vocabulary->vid;
|
| 104 |
if (isset($node->$fieldname) && $node->$fieldname) {
|
| 105 |
$node->taxonomy['tags'][$vocabulary->vid] = $node->$fieldname;
|
| 106 |
unset($node->$fieldname);
|
| 107 |
}
|
| 108 |
}
|
| 109 |
}
|
| 110 |
break;
|
| 111 |
}
|
| 112 |
}
|
| 113 |
|
| 114 |
/**
|
| 115 |
* Implementation of hook_content_extra_fields().
|
| 116 |
*/
|
| 117 |
|
| 118 |
function node_form_rearrange_content_extra_fields($type_name) {
|
| 119 |
$types = variable_get('node_form_rearrange_content_types', array(0));
|
| 120 |
if(isset($types[$type_name]) && ($types[$type_name] != '0')) {
|
| 121 |
$extra = array();
|
| 122 |
$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'
|
| 123 |
ORDER BY v.weight, v.name", 'v', 'vid'), $type_name);
|
| 124 |
//add rows for each vocabulary
|
| 125 |
while ($vocabulary = db_fetch_object($vocabularies)) {
|
| 126 |
if ($vocabulary->tags) {
|
| 127 |
$extra["taxonomy_field_tags_$vocabulary->vid"] = array(
|
| 128 |
'label' => $vocabulary->name,
|
| 129 |
'description' => t('Individual field for %vocabularyname vocabulary, disables Taxonomy group ', array('%vocabularyname' => $vocabulary->name)),
|
| 130 |
'weight' => 0);
|
| 131 |
}
|
| 132 |
else {
|
| 133 |
$extra["taxonomy_field_$vocabulary->vid"] = array(
|
| 134 |
'label' => $vocabulary->name,
|
| 135 |
'description' => t('Individual field for %vocabularyname vocabulary, disables Taxonomy group', array('%vocabularyname' => $vocabulary->name)),
|
| 136 |
'weight' => 0);
|
| 137 |
}
|
| 138 |
}
|
| 139 |
$extra['author'] = array(
|
| 140 |
'label' => 'Authoring information',
|
| 141 |
'description' => t('Node module form'),
|
| 142 |
'weight' => 20);
|
| 143 |
$extra['options'] = array(
|
| 144 |
'label' => 'Publishing options',
|
| 145 |
'description' => t('Node module form'),
|
| 146 |
'weight' => 25);
|
| 147 |
}
|
| 148 |
return $extra;
|
| 149 |
}
|
| 150 |
|