vertical_tabs_example.module

  1. examples
    1. 6 vertical_tabs_example/vertical_tabs_example.module
    2. 7 vertical_tabs_example/vertical_tabs_example.module
    3. 8 vertical_tabs_example/vertical_tabs_example.module

Module file for vertical_tabs_example module.

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

vertical_tabs_example/vertical_tabs_example.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * Module file for vertical_tabs_example module.
  5. */
  6. /**
  7. * @defgroup vertical_tabs_example Example: Vertical Tabs
  8. * @ingroup examples
  9. * @{
  10. * Demonstrates the vertical tabs functionality provided by Drupal 7.
  11. *
  12. * This example does not cover how to save / load custom setting, and only
  13. * deals with elements visibility.
  14. *
  15. * @see vertical_tabs_example.js
  16. */
  17. /**
  18. * Implements hook_menu for a simple explanation page.
  19. */
  20. function vertical_tabs_example_menu() {
  21. $items['examples/vertical_tabs'] = array(
  22. 'title' => 'Vertical tabs example',
  23. 'description' => 'Shows how vertical tabs can best be supported by a custom module',
  24. 'page callback' => '_vertical_tabs_example_explanation',
  25. 'access callback' => TRUE,
  26. );
  27. return $items;
  28. }
  29. /**
  30. * Implement hook_form_alter().
  31. *
  32. * Adds custom fieldset to the node form, and attach ajax behaviour for vertical
  33. * panels to update the settings description.
  34. */
  35. function vertical_tabs_example_form_alter(&$form, $form_state, $form_id) {
  36. // Only include on node add/edit forms.
  37. if (!empty($form['#node_edit_form'])) {
  38. $form['vertical_tabs_example'] = array(
  39. '#type' => 'fieldset',
  40. '#title' => t('Example vertical tab'),
  41. '#collapsible' => TRUE,
  42. '#collapsed' => FALSE,
  43. // The #group value must match the name of the vertical tabs element.
  44. // In most cases, this is 'additional_settings'.
  45. '#group' => 'additional_settings',
  46. // Attach the javascript for vertical tabs.
  47. '#attached' => array(
  48. 'js' => array(
  49. 'vertical-tabs' => drupal_get_path('module', 'vertical_tabs_example') . '/vertical_tabs_example.js',
  50. ),
  51. ),
  52. '#tree' => TRUE,
  53. '#weight' => -2,
  54. );
  55. // This checkbox is used to show or hide the custom settings form using
  56. // javascript (altering states of a container defined later).
  57. $form['vertical_tabs_example']['enabled'] = array(
  58. '#type' => 'checkbox',
  59. '#title' => t('Use custom configuration'),
  60. '#default_value' => FALSE,
  61. );
  62. // This container will be used to store the whole form for our custom
  63. // settings. This way, showing/hidding the form using javascript is easier,
  64. // as only one element should be set visible.
  65. $form['vertical_tabs_example']['vertical_tabs_examplecontainer'] = array(
  66. '#type' => 'container',
  67. '#parents' => array('vertical_tabs_example'),
  68. '#states' => array(
  69. 'invisible' => array(
  70. // If the checkbox is not enabled, show the container.
  71. 'input[name="vertical_tabs_example[enabled]"]' => array('checked' => FALSE),
  72. ),
  73. ),
  74. );
  75. // The string of this textfield will be shown as summary in the vertical
  76. // tab.
  77. $form['vertical_tabs_example']['vertical_tabs_examplecontainer']['custom_setting'] = array(
  78. '#type' => 'textfield',
  79. '#title' => t('Use this custom setting'),
  80. '#default_value' => '',
  81. );
  82. }
  83. }
  84. /**
  85. * Simple explanation page.
  86. */
  87. function _vertical_tabs_example_explanation() {
  88. 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')));
  89. }
  90. /**
  91. * @} End of "defgroup vertical_tabs_example".
  92. */
Login or register to post comments