quicktabs_tabstyles.module 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * Implements hook_theme().
  4. */
  5. function quicktabs_tabstyles_theme() {
  6. return array(
  7. 'quicktabs_style_options' => array(
  8. 'render element' => 'quicktabs_tabstyle',
  9. ),
  10. );
  11. }
  12. /**
  13. * Implements hook_menu().
  14. */
  15. function quicktabs_tabstyles_menu() {
  16. $items['admin/structure/quicktabs/styles'] = array(
  17. 'title' => 'Styles',
  18. 'page callback' => 'drupal_get_form',
  19. 'page arguments' => array('quicktabs_tabstyles_styles'),
  20. 'access arguments' => array('administer quicktabs'),
  21. 'type' => MENU_LOCAL_TASK,
  22. );
  23. return $items;
  24. }
  25. /**
  26. * Callback function for admin/structure/quicktabs/styles. The style chooser form.
  27. */
  28. function quicktabs_tabstyles_styles() {
  29. $options = array();
  30. $styles = module_invoke_all('quicktabs_tabstyles');
  31. // The keys used for options must be valid html id-s.
  32. // Removing the css file path, because that can't be used.
  33. foreach ($styles as $style) {
  34. $options[$style] = $style;
  35. }
  36. ksort($options);
  37. $form['quicktabs_tabstyle'] = array(
  38. '#type' => 'radios',
  39. '#title' => t('Quicktab styles'),
  40. '#options' => array('nostyle' => t('No style')) + $options,
  41. '#default_value' => variable_get('quicktabs_tabstyle', 'nostyle'),
  42. '#description' => t('Select the default style for quicktabs.'),
  43. '#attributes' => array('class' => array('quicktabs-tabstyles', 'clear-block')),
  44. '#theme' => 'quicktabs_style_options',
  45. );
  46. $form['submit'] = array(
  47. '#type' => 'submit',
  48. '#value' => t('Save'),
  49. );
  50. return $form;
  51. }
  52. /**
  53. * Submit handler for QuickTabs styles.
  54. */
  55. function quicktabs_tabstyles_styles_submit($form, &$form_state) {
  56. variable_set('quicktabs_tabstyle', $form_state['values']['quicktabs_tabstyle']);
  57. drupal_set_message(t('The default quicktab style has been saved.'));
  58. }
  59. /**
  60. * Theme function for quicktabs style radio options.
  61. *
  62. * @ingroup themeable
  63. */
  64. function theme_quicktabs_style_options($variables) {
  65. $style_element = $variables['quicktabs_tabstyle'];
  66. $markup = '';
  67. $tabs = array(
  68. array('title' => t('One'), 'contents' => array('#markup' => t('First tab')), 'weight' => 0),
  69. array('title' => t('Two'), 'contents' => array('#markup' => t('Second tab')), 'weight' => 1),
  70. array('title' => t('Three'), 'contents' => array('#markup' => t('Third tab')), 'weight' => 2)
  71. );
  72. $options = array('renderer' => 'quicktabs', 'hide_empty_tabs' => 0, 'ajax' => 0);
  73. // Preview for each style.
  74. foreach (element_children($style_element) as $style) {
  75. $element = $style_element[$style];
  76. $options['style'] = $style;
  77. $quicktabs = quicktabs_build_quicktabs(drupal_strtolower($style), $options, $tabs);
  78. $preview = '<div class="quicktabs-preview">'. drupal_render($quicktabs['content']) .'</div>';
  79. $element['#description'] = t('%style preview', array('%style' => $element['#title'])) .':<br />'. $preview;
  80. $markup .= drupal_render($element);
  81. }
  82. $build = array(
  83. 'style' => array('#markup' => $markup),
  84. '#attached' => array('css' => array(drupal_get_path('module', 'quicktabs_tabstyles') . '/css/quicktabs-tabstyles-admin.css')),
  85. );
  86. return drupal_render($build);
  87. }
  88. /**
  89. * Implements hook_quicktabs_tabstyles().
  90. */
  91. function quicktabs_tabstyles_quicktabs_tabstyles() {
  92. $tabstyles_directory = drupal_get_path('module', 'quicktabs_tabstyles') . '/tabstyles';
  93. $files = file_scan_directory($tabstyles_directory, '/\.css$/');
  94. $tabstyles = array();
  95. foreach ($files as $file) {
  96. // Skip RTL files.
  97. if (!strpos($file->name, '-rtl')) {
  98. $tabstyles[$file->uri] = drupal_ucfirst($file->name);
  99. }
  100. }
  101. return $tabstyles;
  102. }