vertical_tabs_example.module

Tracking 6.x-1.x branch
  1. drupal
    1. 6 contributions/examples/vertical_tabs_example/vertical_tabs_example.module
    2. 7 contributions/examples/vertical_tabs_example/vertical_tabs_example.module
    3. 8 contributions/examples/vertical_tabs_example/vertical_tabs_example.module

Shows how to integrate your custom node options with vertical tabs module in Drupal 6. This example does not cover how to save / load custom setting, and only deals with elements visibility.

Functions & methods

NameDescription
vertical_tabs_example_form_alterImplement hook_form_alter().
vertical_tabs_example_menuImplements hook_menu for a simple explanation page.
_vertical_tabs_example_explanationSimple explanation page.

File

View source
  1. <?php
  2. /**
  3. * @file
  4. * Shows how to integrate your custom node options with vertical tabs module in
  5. * Drupal 6. This example does not cover how to save / load custom setting, and
  6. * only deals with elements visibility.
  7. */
  8. /**
  9. * @defgroup vertical_tabs_example Example: Vertical Tabs
  10. * @ingroup examples
  11. * @{
  12. * Using vertical_tabs module. (drupal 6)
  13. *
  14. * Shows how to integrate your custom node options with vertical tabs module in
  15. * Drupal 6. This example does not cover how to save / load custom setting, and
  16. * only deals with elements visibility.
  17. *
  18. * This example is part of the Examples for Developers Project which you can download
  19. * and experiment with here: http://drupal.org/project/examples
  20. */
  21. /**
  22. * Implements hook_menu for a simple explanation page.
  23. */
  24. function vertical_tabs_example_menu() {
  25. $items['examples/vertical_tabs'] = array(
  26. 'title' => 'Vertical tabs example',
  27. 'description' => 'Shows how vertical tabs can best be supported by a custom module',
  28. 'page callback' => '_vertical_tabs_example_explanation',
  29. 'access callback' => TRUE,
  30. );
  31. return $items;
  32. }
  33. /**
  34. * Implement hook_form_alter().
  35. *
  36. * Adds custom fieldset to the node form, and attach ajax behaviour for vertical
  37. * panels to update the settings description.
  38. */
  39. function vertical_tabs_example_form_alter(&$form, $form_state, $form_id) {
  40. // Only include on node add/edit forms.
  41. if (isset($form['#node']) && $form['#node']->type .'_node_form' == $form_id) {
  42. // Define a fieldset for our settings in the node edit form.
  43. $form['vertical_tabs_example'] = array(
  44. '#type' => 'fieldset',
  45. '#title' => t('Example vertical tab'),
  46. '#collapsible' => TRUE,
  47. '#collapsed' => FALSE,
  48. // The #group value must be defined to be included in the vertical tabs
  49. // element by default.
  50. '#group' => 'additional_settings',
  51. // Attach the javascript for vertical tabs. Normally we would use
  52. // drupal_add_js(), but the vertical tabs module supports this special
  53. // Drupal 7 #attached property.
  54. '#attached' => array(
  55. 'js' => array(drupal_get_path('module', 'vertical_tabs_example') . '/vertical_tabs_example.js'),
  56. ),
  57. '#tree' => TRUE,
  58. '#weight' => -2,
  59. );
  60. // This checkbox is used to show or hide the custom settings form using
  61. // javascript (altering states of a container defined later).
  62. $form['vertical_tabs_example']['enabled'] = array(
  63. '#type' => 'checkbox',
  64. '#title' => t('Use custom configuration'),
  65. '#default_value' => FALSE,
  66. );
  67. // This container will be used to store the whole form for our custom
  68. // settings. This way, showing/hidding the form using javascript is easier,
  69. // as only one element should be set visible.
  70. $form['vertical_tabs_example']['vertical_tabs_examplecontainer'] = array(
  71. '#type' => 'fieldset',
  72. '#title' => t('Custom setting'),
  73. // This attribute is required for vertical tabs to track elements beneath
  74. // it's own tree.
  75. '#parents' => array('vertical_tabs_example'),
  76. );
  77. // The string of this textfield that will be shown as summary in the
  78. // vertical tab if the checkbox is enabled.
  79. $form['vertical_tabs_example']['vertical_tabs_examplecontainer']['custom_setting'] = array(
  80. '#type' => 'textfield',
  81. '#title' => t('Use this custom setting'),
  82. '#default_value' => '',
  83. );
  84. }
  85. }
  86. /**
  87. * Simple explanation page.
  88. */
  89. function _vertical_tabs_example_explanation() {
  90. return t("The Vertical Tabs Example shows how a custom module can best support vertical tabs. To see the effects of this module, look at the <a href='!node_add'>node/add</a> form", array('!node_add' => url('node/add')));
  91. }
  92. /**
  93. * @} End of "defgroup vertical_tabs_example".
  94. */