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