Révision 74f6bef0
Ajouté par Assos Assos il y a plus de 10 ans
drupal7/sites/all/themes/adaptivetheme/at_core/inc/forms/settings.contextregions.inc | ||
---|---|---|
4 | 4 |
* @file |
5 | 5 |
* Generate form elments for the Mobile Regions settings. |
6 | 6 |
*/ |
7 |
function at_core_context_regions_form(&$form, $info_array) { |
|
8 |
// Regions we don't want to include |
|
9 |
$unset_mobile_regions = array( |
|
10 |
'dashboard_main', |
|
11 |
'dashboard_sidebar', |
|
12 |
'dashboard_inactive', |
|
13 |
'page_bottom', |
|
14 |
'page_top', |
|
15 |
'menu_bar', // exclude the menu bar, it has bespoke region markup and moving something to this will end in tears. |
|
16 |
'content', // exclude the main content region, we don't want to unset this? |
|
17 |
); |
|
7 | 18 |
|
8 |
// Regions we don't want to include |
|
9 |
$unset_mobile_regions = array( |
|
10 |
'dashboard_main', |
|
11 |
'dashboard_sidebar', |
|
12 |
'dashboard_inactive', |
|
13 |
'page_bottom', |
|
14 |
'page_top', |
|
15 |
'menu_bar', // exclude the menu bar, it has bespoke region markup and moving something to this will end in tears. |
|
16 |
'content', // exclude the main content region, we don't want to unset this? |
|
17 |
); |
|
18 |
|
|
19 |
// Prepare regions |
|
20 |
foreach ($info_array['regions'] as $key => $value) { |
|
21 |
if (in_array($key, $unset_mobile_regions)) { |
|
22 |
unset($key); |
|
23 |
} |
|
24 |
if (isset($key)) { |
|
25 |
$mobile_regions[$key] = $value; |
|
19 |
// Initialize variable for detection, we reset this to TRUE if a detection module is installed |
|
20 |
$detection = FALSE; |
|
21 |
$browscap_detect = FALSE; |
|
22 |
$mobile_detect = FALSE; |
|
23 |
|
|
24 |
// Prepare regions |
|
25 |
foreach ($info_array['regions'] as $key => $value) { |
|
26 |
if (in_array($key, $unset_mobile_regions)) { |
|
27 |
unset($key); |
|
28 |
} |
|
29 |
if (isset($key)) { |
|
30 |
$mobile_regions[$key] = $value; |
|
31 |
} |
|
26 | 32 |
} |
27 |
} |
|
28 | 33 |
|
29 |
// Add a <do-not-move> option to the move regions list |
|
30 |
$do_not_move = array('do_not_move' => '<do-not-move>'); |
|
31 |
$move_regions_list = array_merge($do_not_move, $mobile_regions); |
|
32 |
array_reverse($move_regions_list); |
|
33 |
|
|
34 |
// Top level wrapper fieldset |
|
35 |
$form['at']['context-regions'] = array( |
|
36 |
'#type' => 'fieldset', |
|
37 |
'#title' => t('Mobile Regions (beta)'), |
|
38 |
'#description' => t('<h3>Mobile Regions and Blocks <sup>(beta)</sup></h3><p>These settings allow you to either <abbr title="Unset means they won\'t print in the output at all, i.e. they are totally nuked">unset</abbr> regions in mobile devices, or move the regions blocks to another region when a mobile device is detected. Device detection is supplied by the Browscap module.</p><p>This feature should be considered beta at this time and has only been tested with the Drupal core block system, please post issues to the <a href="!issue_queue" target="_blank">issue queue</a>.</p><p>Caveats:<p><ol><li>Normal weight settings are lost when blocks are moved.</li><li>If the target region has no blocks by default, Adaptivetheme will generate the region markup. The markup is hard coded and does not account for modifications elsewhere in your theme, such as region template suggestion overrides.</li></ol>', array('!issue_queue' => 'http://drupal.org/project/issues/adaptivetheme')), |
|
39 |
'#weight' => 30, |
|
40 |
); |
|
41 |
if (!function_exists('browscap_get_browser')) { |
|
42 |
$form['at']['context-regions']['requirements'] = array( |
|
43 |
'#markup' => t('<strong>Required:</strong> To use these settings you must first install the <a href="!browscap_module" target="_blank">Browscap module</a>. New settings will appear after you have enabled Browscap.', array('!browscap_module' => 'http://drupal.org/project/browscap')), |
|
34 |
// Add a do-not-move option to the move regions list |
|
35 |
$do_not_move = array('do_not_move' => '-- nothing selected --'); |
|
36 |
$move_regions_list = array_merge($do_not_move, $mobile_regions); |
|
37 |
array_reverse($move_regions_list); |
|
38 |
|
|
39 |
// Top level wrapper fieldset |
|
40 |
$form['at']['context-regions'] = array( |
|
41 |
'#type' => 'fieldset', |
|
42 |
'#title' => t('Mobile Regions (beta)'), |
|
43 |
'#description' => t('<h3>Mobile Regions and Blocks <sup>(beta)</sup></h3><p>These settings allow you to either <abbr title="Hiding a region means it won\'t print in the output at all, i.e. they are totally nuked">hide</abbr> regions in mobile devices, or move the regions blocks to another region when a mobile device is detected.</p>'), |
|
44 |
'#weight' => 30, |
|
44 | 45 |
); |
45 |
} |
|
46 |
elseif (function_exists('browscap_get_browser')) { |
|
47 |
// Build form elements for each region |
|
48 |
foreach ($mobile_regions as $mobile_region_name => $mobile_region_label) { |
|
49 | 46 |
|
50 |
$mobile_region_title = check_plain($mobile_region_label); |
|
51 |
$mobile_region_name = check_plain($mobile_region_name); |
|
47 |
// Set various messages based on what detection modules are installed, we can leverage both Browscap (legacy reasons) and Mobile Detect |
|
48 |
if (!function_exists('browscap_get_browser') && !function_exists('mobile_detect_get_object')) { |
|
49 |
$form['at']['context-regions']['requirements'] = array( |
|
50 |
'#markup' => t('<p><strong>Detection:</strong> <span class="no-detection">No detection module installed.</span> Please install either the Browscap or Mobile Detect module.</p> |
|
51 |
<ul> |
|
52 |
<li><a href="!browscap_module" target="_blank">Browscap module</a>: allows you to hide or move blocks for all mobile devices.</li> |
|
53 |
<li><a href="!mobiledetect_module" target="_blank">Mobile Detect module</a>: allows you to hide regions in all just smalltouch devices (exclude tablets) or all mobile devices (smalltouch and tablets).</li> |
|
54 |
</ul>', array('!browscap_module' => 'http://drupal.org/project/browscap', '!mobiledetect_module' => 'http://drupal.org/project/mobile_detect')), |
|
55 |
); |
|
56 |
} |
|
57 |
if (function_exists('browscap_get_browser') && !function_exists('mobile_detect_get_object')) { |
|
58 |
$detection = TRUE; |
|
59 |
$browscap_detect = TRUE; |
|
60 |
$form['at']['context-regions']['requirements'] = array( |
|
61 |
'#markup' => t('<p><strong>Detection module:</strong> <span class="detection">Browscap</span></p> |
|
62 |
<p>Alternatively use the <a href="!mobiledetect_module" target="_blank">Mobile Detect module</a> which allows you to hide regions in all just Smalltouchs or all mobile devices.</p> |
|
63 |
</ul>', array('!mobiledetect_module' => 'http://drupal.org/project/mobile_detect')), |
|
64 |
); |
|
65 |
} |
|
66 |
if (function_exists('mobile_detect_get_object') && !function_exists('browscap_get_browser')) { |
|
67 |
$detection = TRUE; |
|
68 |
$mobile_detect = TRUE; |
|
69 |
$form['at']['context-regions']['requirements'] = array( |
|
70 |
'#markup' => t('<p><strong>Detection module:</strong> <span class="detection">Mobile Detect</span></p>'), |
|
71 |
); |
|
72 |
} |
|
73 |
if (function_exists('browscap_get_browser') && function_exists('mobile_detect_get_object')) { |
|
74 |
$detection = TRUE; |
|
75 |
$mobile_detect = TRUE; |
|
76 |
$browscap_detect = FALSE; |
|
77 |
$form['at']['context-regions']['requirements'] = array( |
|
78 |
'#markup' => t('<p><strong>Detection module:</strong> <span class="detection">Mobile Detect</span>. You have both the Browscap and Mobile Detect modules installed, in this case the Mobile Detect module is being used.</p>'), |
|
79 |
); |
|
80 |
} |
|
81 |
|
|
82 |
// Only show the form if detection is true |
|
83 |
if ($detection === TRUE) { |
|
52 | 84 |
|
53 |
$form['at']['context-regions']['region-options-' . $mobile_region_name] = array( |
|
54 |
'#type' => 'fieldset', |
|
55 |
'#title' => t($mobile_region_title), |
|
85 |
// Include a bunch of hidden form elements, we will save these to the variables table later |
|
86 |
// so we do not need to repeat the logic in alter's or other page building operations |
|
87 |
$form['at']['context-regions']['detection'] = array( |
|
88 |
'#type' => 'hidden', |
|
89 |
'#default_value' => $detection, |
|
56 | 90 |
); |
57 |
$form['at']['context-regions']['region-options-' . $mobile_region_name]['unset_' . $mobile_region_name] = array( |
|
58 |
'#type' => 'checkbox', |
|
59 |
'#title' => t('Unset'), |
|
60 |
'#default_value' => at_get_setting('unset_' . $mobile_region_name), |
|
91 |
$form['at']['context-regions']['browscap_detect'] = array( |
|
92 |
'#type' => 'hidden', |
|
93 |
'#default_value' => $browscap_detect, |
|
61 | 94 |
); |
62 |
$form['at']['context-regions']['region-options-' . $mobile_region_name]['move_' . $mobile_region_name] = array( |
|
63 |
'#type' => 'select', |
|
64 |
'#title' => t('Move blocks:'), |
|
65 |
'#default_value' => at_get_setting('move_' . $mobile_region_name), |
|
66 |
'#options' => $move_regions_list, |
|
67 |
'#states' => array('invisible' => array('input[name=unset_' . $mobile_region_name . ']' => array('checked' => TRUE))), |
|
95 |
$form['at']['context-regions']['mobile_detect'] = array( |
|
96 |
'#type' => 'hidden', |
|
97 |
'#default_value' => $mobile_detect, |
|
98 |
); |
|
99 |
|
|
100 |
// Build form elements for each region |
|
101 |
foreach ($mobile_regions as $mobile_region_name => $mobile_region_label) { |
|
102 |
|
|
103 |
$mobile_region_title = check_plain($mobile_region_label); |
|
104 |
$mobile_region_name = check_plain($mobile_region_name); |
|
105 |
|
|
106 |
$form['at']['context-regions']['region-options-' . $mobile_region_name] = array( |
|
107 |
'#type' => 'fieldset', |
|
108 |
'#title' => t($mobile_region_title), |
|
109 |
); |
|
110 |
|
|
111 |
// UNSET |
|
112 |
$form['at']['context-regions']['region-options-' . $mobile_region_name]['unset'] = array( |
|
113 |
'#type' => 'fieldset', |
|
114 |
'#title' => t('Hide'), |
|
115 |
); |
|
116 |
|
|
117 |
// When browscap provides detection we only show a simplified option to hide the region - we can use this both as a trigger to show |
|
118 |
// more options when Mobile Detect is active, or as the actual setting when only Browscap is active. |
|
119 |
$form['at']['context-regions']['region-options-' . $mobile_region_name]['unset']['unset_' . $mobile_region_name] = array( |
|
120 |
'#type' => 'checkbox', |
|
121 |
'#title' => t('Hide region'), |
|
122 |
'#default_value' => at_get_setting('unset_' . $mobile_region_name), |
|
123 |
'#states' => array( |
|
124 |
'disabled' => array( |
|
125 |
'input[name=move_region_' . $mobile_region_name . ']' => array('checked' => TRUE), |
|
126 |
) |
|
127 |
), |
|
128 |
); |
|
129 |
|
|
130 |
// When Mobile Detect provides detection we have an expanded set of advanced options |
|
131 |
if ($mobile_detect === TRUE) { |
|
132 |
$form['at']['context-regions']['region-options-' . $mobile_region_name]['unset']['unset_options_' . $mobile_region_name] = array( |
|
133 |
'#type' => 'radios', |
|
134 |
'#title' => t('Hide region options'), |
|
135 |
'#options' => array( |
|
136 |
'unset_smalltouch' => t('Hide in Smalltouch devicess'), |
|
137 |
'unset_all_devices' => t('Hide in all mobile devices'), |
|
138 |
), |
|
139 |
'#default_value' => at_get_setting('unset_options_' . $mobile_region_name) ? at_get_setting('unset_options_' . $mobile_region_name) : 'unset_smalltouch', |
|
140 |
'#states' => array( |
|
141 |
'visible' => array( |
|
142 |
'input[name=unset_' . $mobile_region_name . ']' => array('checked' => TRUE), |
|
143 |
), |
|
144 |
'disabled' => array( |
|
145 |
'input[name=move_region_' . $mobile_region_name . ']' => array('checked' => TRUE), |
|
146 |
), |
|
147 |
), |
|
148 |
); |
|
149 |
} |
|
150 |
|
|
151 |
// MOVE |
|
152 |
$form['at']['context-regions']['region-options-' . $mobile_region_name]['move'] = array( |
|
153 |
'#type' => 'fieldset', |
|
154 |
'#title' => t('Move'), |
|
155 |
); |
|
156 |
// When browscap provides detection we only show a simplified option to hide the region - we can use this both as a trigger to show |
|
157 |
// more options when Mobile Detect is active, or as the actual setting when only Browscap is active. |
|
158 |
$form['at']['context-regions']['region-options-' . $mobile_region_name]['move']['move_region_' . $mobile_region_name] = array( |
|
159 |
'#type' => 'checkbox', |
|
160 |
'#title' => t('Move blocks'), |
|
161 |
'#default_value' => at_get_setting('move_region_' . $mobile_region_name), |
|
162 |
'#states' => array( |
|
163 |
'disabled' => array( |
|
164 |
'input[name=unset_' . $mobile_region_name . ']' => array('checked' => TRUE), |
|
165 |
) |
|
166 |
), |
|
167 |
); |
|
168 |
// When Mobile Detect provides detection we have an expanded set of advanced options |
|
169 |
if ($mobile_detect === TRUE) { |
|
170 |
$form['at']['context-regions']['region-options-' . $mobile_region_name]['move']['move_options_' . $mobile_region_name] = array( |
|
171 |
'#type' => 'radios', |
|
172 |
'#title' => t('Move region options'), |
|
173 |
'#options' => array( |
|
174 |
'move_smalltouch' => t('Move in Smalltouchs'), |
|
175 |
'move_all_devices' => t('Move in all mobile devices'), |
|
176 |
), |
|
177 |
'#default_value' => at_get_setting('move_options_' . $mobile_region_name) ? at_get_setting('move_options_' . $mobile_region_name) : 'move_smalltouch', |
|
178 |
'#states' => array( |
|
179 |
'visible' => array( |
|
180 |
'input[name=move_region_' . $mobile_region_name . ']' => array('checked' => TRUE), |
|
181 |
), |
|
182 |
'disabled' => array( |
|
183 |
'input[name=unset_region_' . $mobile_region_name . ']' => array('checked' => TRUE), |
|
184 |
), |
|
185 |
), |
|
186 |
); |
|
187 |
} |
|
188 |
$form['at']['context-regions']['region-options-' . $mobile_region_name]['move']['move_' . $mobile_region_name] = array( |
|
189 |
'#type' => 'select', |
|
190 |
'#title' => t('Move to:'), |
|
191 |
'#default_value' => at_get_setting('move_' . $mobile_region_name), |
|
192 |
'#options' => $move_regions_list, |
|
193 |
'#states' => array( |
|
194 |
'invisible' => array( |
|
195 |
array('input[name=move_region_' . $mobile_region_name . ']' => array('checked' => FALSE)), |
|
196 |
), |
|
197 |
), |
|
198 |
); |
|
199 |
} |
|
200 |
|
|
201 |
// Caveats |
|
202 |
$form['at']['context-regions']['caveats'] = array( |
|
203 |
'#markup' => t('<p>Caveats:<p><ol><li>Normal weight settings are lost when blocks are moved.</li><li>If the target region has no blocks by default, Adaptivetheme will generate the region markup. The markup is hard coded and does not account for modifications elsewhere in your theme, such as region template suggestion overrides.</li></ol>'), |
|
68 | 204 |
); |
69 | 205 |
} |
70 | 206 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules