Add additional settings tab to node_type_form

Public

Good example can be taken from page_title module:

Get raw version
php
  1. /**
  2.  * Implement hook_form_FORM_ID_alter().
  3.  */
  4. function page_title_form_node_type_form_alter(&$form, $form_state) {
  5. // If we dont have permission to administer the title then we need to abort this alter now!
  6. if (!user_access('administer page title')) return;
  7.  
  8. // Add the node-type specific page title settings to the additional settings section
  9. $form['page_title'] = array(
  10. '#type' => 'fieldset',
  11. '#title' => t('Page Title Settings'),
  12. '#collapsible' => TRUE,
  13. '#collapsed' => TRUE,
  14. '#tree' => TRUE,
  15. '#group' => 'additional_settings',
  16. );
  17.  
  18. $form['page_title']['show_field'] = array(
  19. '#type' => 'checkboxes',
  20. '#title' => t('Page Title Field'),
  21. '#description' => t('If checked, the <em>Page Title</em> field will appear on the node edit form for those who have permission to set the title.'),
  22. '#options' => array(
  23. 'show_field' => t('Show field'),
  24. ),
  25. '#default_value' => variable_get('page_title_type_' . $form['#node_type']->type . '_showfield', 0) ? array('show_field') : array(),
  26. );
  27.  
  28. $form['page_title']['pattern'] = array(
  29. '#type' => 'textfield',
  30. '#title' => t('Page Title Pattern'),
  31. '#default_value' => variable_get('page_title_type_' . $form['#node_type']->type, ''),
  32. '#description' => t('Enter the <em>Page Title</em> pattern you want to use for this node type. For more information, please use the !link settings page', array('!link' => l('Page Title', 'admin/config/search/page-title'))),
  33. '#maxlength' => 255,
  34. );
  35.  
  36. $form['#submit'][] = 'page_title_node_type_form_submit';
  37. }
  38.  
  39.  
  40. /**
  41.  * Submit handler for the node_type_form element added in the hook_form_FORM_ID_alter() above.
  42.  */
  43. function page_title_node_type_form_submit($form, &$form_state) {
  44. $show_field = $form_state['values']['page_title']['show_field']['show_field'] ? 1 : 0;
  45. variable_set('page_title_type_' . $form_state['values']['type'] . '_showfield', $show_field);
  46. variable_set('page_title_type_' . $form_state['values']['type'], $form_state['values']['page_title']['pattern']);
  47.  
  48. // For some reason the node module adds the fieldset as a separate entry in the variables table... we dont want this!
  49. variable_del('page_title_' . $form_state['values']['type']);
  50.  
  51. // Flush the settings on update/insert.
  52. page_title_get_settings(TRUE);
  53. }