| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Implementation of hook_form_alter().
|
| 6 |
*/
|
| 7 |
function nodeform_form_alter(&$form, $form_state, $form_id) {
|
| 8 |
// Let users select between node form layouts on the Post settings page.
|
| 9 |
if ($form_id == 'node_configure') {
|
| 10 |
$form['nodeform_layout'] = array(
|
| 11 |
'#type' => 'radios',
|
| 12 |
'#title' => t('Layout of node form'),
|
| 13 |
'#default_value' => variable_get('nodeform_layout', 'default'),
|
| 14 |
'#options' => array(
|
| 15 |
'default' => t('Default'),
|
| 16 |
'accordion' => t('Accordion'),
|
| 17 |
'vertical' => t('Vertical tabs'),
|
| 18 |
),
|
| 19 |
'#description' => t('Select which layout to use on the node form.'),
|
| 20 |
);
|
| 21 |
|
| 22 |
$form['#submit'][] = 'nodeform_settings_form_submit';
|
| 23 |
$form['buttons']['#weight'] = 10;
|
| 24 |
}
|
| 25 |
|
| 26 |
// Add JS and CSS files of the selected layout to the node form.
|
| 27 |
elseif ($form['#id'] == 'node-form') {
|
| 28 |
$module_path = drupal_get_path('module', 'nodeform');
|
| 29 |
|
| 30 |
$form['buttons']['#prefix'] .= '<div id="nodeform-buttons">';
|
| 31 |
$form['buttons']['#suffix'] .= '</div>';
|
| 32 |
|
| 33 |
switch (variable_get('nodeform_layout', 'default')) {
|
| 34 |
// Accordion:
|
| 35 |
case 'accordion':
|
| 36 |
drupal_add_js($module_path .'/accordion/jquery.accordion.js', 'module');
|
| 37 |
drupal_add_js($module_path .'/accordion/accordion.js', 'module');
|
| 38 |
drupal_add_css($module_path .'/accordion/accordion.css', 'module');
|
| 39 |
break;
|
| 40 |
// Vertical tabs:
|
| 41 |
case 'vertical':
|
| 42 |
drupal_add_js($module_path .'/vertical_tabs/ui.tabs.min.js', 'module');
|
| 43 |
drupal_add_js($module_path .'/vertical_tabs/vertical_tabs.js', 'module');
|
| 44 |
drupal_add_css($module_path .'/vertical_tabs/vertical_tabs.css', 'module');
|
| 45 |
break;
|
| 46 |
}
|
| 47 |
}
|
| 48 |
}
|
| 49 |
|
| 50 |
/**
|
| 51 |
* Custom submit handler for admin/content/node-settings.
|
| 52 |
*/
|
| 53 |
function nodeform_settings_form_submit($form, &$form_state) {
|
| 54 |
if ($form['#post']['op'] == t('Reset to defaults')) {
|
| 55 |
variable_set('nodeform_layout', 'default');
|
| 56 |
}
|
| 57 |
else {
|
| 58 |
variable_set('nodeform_layout', $form_state['values']['nodeform_layout']);
|
| 59 |
}
|
| 60 |
}
|