PageRenderTime 52ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/sites/all/themes/radix/template.php

https://bitbucket.org/niccolo/open-outreach-rc9-radix-bootswatch
PHP | 376 lines | 230 code | 38 blank | 108 comment | 45 complexity | 01ebed3eb865c5a1e4b3bde6a9f44918 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Implementation of template_preprocess_html()
  4. */
  5. function radix_preprocess_html(&$variables) {
  6. // add meta for Bootstrap Responsive
  7. // <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8. $element = array(
  9. '#tag' => 'meta',
  10. '#attributes' => array(
  11. 'name' => 'viewport',
  12. 'content' => 'width=device-width, initial-scale=1.0',
  13. ),
  14. );
  15. drupal_add_html_head($element, 'bootstrap_responsive');
  16. }
  17. /**
  18. * Implements hook_js_alter().
  19. */
  20. function radix_js_alter(&$js) {
  21. //$js['misc/jquery.js']['data'] = 'http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js';
  22. }
  23. /**
  24. * Implements hook_css_alter().
  25. */
  26. function radix_css_alter(&$css) {
  27. if (isset($css['sites/all/modules/panopoly/panopoly_admin/panopoly-admin.css'])) {
  28. unset($css['sites/all/modules/panopoly/panopoly_admin/panopoly-admin.css']);
  29. }
  30. }
  31. /**
  32. * Implements template_preprocess_page().
  33. */
  34. function radix_preprocess_page(&$variables) {
  35. // determine if the page is rendered using panels
  36. $variables['is_panel'] = FALSE;
  37. if (module_exists('page_manager') && sizeof(page_manager_get_current_page())) {
  38. $variables['is_panel'] = TRUE;
  39. }
  40. // Add search_form to theme
  41. $variables['search_form'] = '';
  42. if (module_exists('search') && user_access('search content')) {
  43. $search_box_form = drupal_get_form('search_form');
  44. $search_box_form['basic']['keys']['#title'] = '';
  45. $search_box_form['basic']['keys']['#attributes'] = array('placeholder' => 'Search');
  46. $search_box_form['basic']['keys']['#attributes']['class'][] = 'search-query';
  47. $search_box_form['basic']['submit']['#value'] = t('Search');
  48. $search_box_form['#attributes']['class'][] = 'navbar-form';
  49. $search_box_form['#attributes']['class'][] = 'pull-right';
  50. $search_box = drupal_render($search_box_form);
  51. $variables['search_form'] = (user_access('search content')) ? $search_box : NULL;
  52. }
  53. // Format and add main menu to theme
  54. $main_menu_tree = menu_tree_all_data('main-menu');
  55. $variables['main_menu'] = menu_tree_output($main_menu_tree);
  56. // Format and add footer menu to theme
  57. $footer_menu_tree = menu_tree_all_data('menu-footer-menu');
  58. $variables['footer_menu'] = menu_tree_output($footer_menu_tree);
  59. }
  60. /**
  61. * Implements theme_table().
  62. */
  63. function radix_table($variables) {
  64. // add default classes to table elements
  65. $variables['attributes']['class'] = (isset($variables['attributes']['class'])) ? $variables['attributes']['class'] : array();
  66. $variables['attributes']['class'] = (is_array($variables['attributes']['class'])) ? $variables['attributes']['class'] : array($variables['attributes']['class']);
  67. $variables['attributes']['class'] = array_merge($variables['attributes']['class'], array('table', 'table-striped', 'table-bordered'));
  68. $header = $variables['header'];
  69. $rows = $variables['rows'];
  70. $attributes = $variables['attributes'];
  71. $caption = $variables['caption'];
  72. $colgroups = $variables['colgroups'];
  73. $sticky = $variables['sticky'];
  74. $empty = $variables['empty'];
  75. // Add sticky headers, if applicable.
  76. if (count($header) && $sticky) {
  77. drupal_add_js('misc/tableheader.js');
  78. // Add 'sticky-enabled' class to the table to identify it for JS.
  79. // This is needed to target tables constructed by this function.
  80. $attributes['class'][] = 'sticky-enabled';
  81. }
  82. $output = '<table' . drupal_attributes($attributes) . ">\n";
  83. if (isset($caption)) {
  84. $output .= '<caption>' . $caption . "</caption>\n";
  85. }
  86. // Format the table columns:
  87. if (count($colgroups)) {
  88. foreach ($colgroups as $number => $colgroup) {
  89. $attributes = array();
  90. // Check if we're dealing with a simple or complex column
  91. if (isset($colgroup['data'])) {
  92. foreach ($colgroup as $key => $value) {
  93. if ($key == 'data') {
  94. $cols = $value;
  95. }
  96. else {
  97. $attributes[$key] = $value;
  98. }
  99. }
  100. }
  101. else {
  102. $cols = $colgroup;
  103. }
  104. // Build colgroup
  105. if (is_array($cols) && count($cols)) {
  106. $output .= ' <colgroup' . drupal_attributes($attributes) . '>';
  107. $i = 0;
  108. foreach ($cols as $col) {
  109. $output .= ' <col' . drupal_attributes($col) . ' />';
  110. }
  111. $output .= " </colgroup>\n";
  112. }
  113. else {
  114. $output .= ' <colgroup' . drupal_attributes($attributes) . " />\n";
  115. }
  116. }
  117. }
  118. // Add the 'empty' row message if available.
  119. if (!count($rows) && $empty) {
  120. $header_count = 0;
  121. foreach ($header as $header_cell) {
  122. if (is_array($header_cell)) {
  123. $header_count += isset($header_cell['colspan']) ? $header_cell['colspan'] : 1;
  124. }
  125. else {
  126. $header_count++;
  127. }
  128. }
  129. $rows[] = array(array(
  130. 'data' => $empty,
  131. 'colspan' => $header_count,
  132. 'class' => array('empty', 'message'),
  133. ));
  134. }
  135. // Format the table header:
  136. if (count($header)) {
  137. $ts = tablesort_init($header);
  138. // HTML requires that the thead tag has tr tags in it followed by tbody
  139. // tags. Using ternary operator to check and see if we have any rows.
  140. $output .= (count($rows) ? ' <thead><tr>' : ' <tr>');
  141. foreach ($header as $cell) {
  142. $cell = tablesort_header($cell, $header, $ts);
  143. $output .= _theme_table_cell($cell, TRUE);
  144. }
  145. // Using ternary operator to close the tags based on whether or not there are rows
  146. $output .= (count($rows) ? " </tr></thead>\n" : "</tr>\n");
  147. }
  148. else {
  149. $ts = array();
  150. }
  151. // Format the table rows:
  152. if (count($rows)) {
  153. $output .= "<tbody>\n";
  154. $flip = array(
  155. 'even' => 'odd',
  156. 'odd' => 'even',
  157. );
  158. $class = 'even';
  159. foreach ($rows as $number => $row) {
  160. $attributes = array();
  161. // Check if we're dealing with a simple or complex row
  162. if (isset($row['data'])) {
  163. foreach ($row as $key => $value) {
  164. if ($key == 'data') {
  165. $cells = $value;
  166. }
  167. else {
  168. $attributes[$key] = $value;
  169. }
  170. }
  171. }
  172. else {
  173. $cells = $row;
  174. }
  175. if (count($cells)) {
  176. // Add odd/even class
  177. if (empty($row['no_striping'])) {
  178. $class = $flip[$class];
  179. $attributes['class'][] = $class;
  180. }
  181. // Build row
  182. $output .= ' <tr' . drupal_attributes($attributes) . '>';
  183. $i = 0;
  184. foreach ($cells as $cell) {
  185. $cell = tablesort_cell($cell, $header, $ts, $i++);
  186. $output .= _theme_table_cell($cell);
  187. }
  188. $output .= " </tr>\n";
  189. }
  190. }
  191. $output .= "</tbody>\n";
  192. }
  193. $output .= "</table>\n";
  194. return $output;
  195. }
  196. /**
  197. * Returns HTML for a button form element.
  198. *
  199. * @param $variables
  200. * An associative array containing:
  201. * - element: An associative array containing the properties of the element.
  202. * Properties used: #attributes, #button_type, #name, #value.
  203. *
  204. * @ingroup themeable
  205. */
  206. function radix_button($variables) {
  207. $element = $variables['element'];
  208. $element['#attributes']['type'] = 'submit';
  209. element_set_attributes($element, array('id', 'name', 'value'));
  210. $element['#attributes']['class'][] = 'form-' . $element['#button_type'];
  211. $element['#attributes']['class'][] = 'btn';
  212. if (!empty($element['#attributes']['disabled'])) {
  213. $element['#attributes']['class'][] = 'form-button-disabled';
  214. }
  215. // add a btn-primary class if submit button
  216. if ($element['#parents'][0] == 'submit') {
  217. $element['#attributes']['class'][] = 'btn-primary';
  218. }
  219. return '<input' . drupal_attributes($element['#attributes']) . ' />';
  220. }
  221. /**
  222. * Implements theme_menu_link().
  223. */
  224. function radix_link($variables) {
  225. $icons = '';
  226. if (isset($variables['options']['attributes']['class']) && is_array($variables['options']['attributes']['class'])) {
  227. $css_classes = $variables['options']['attributes']['class'];
  228. if ($icon_classes = preg_grep('/^icon\-.*/', $css_classes)) {
  229. // render an icon for each class
  230. foreach ($icon_classes as $icon_class) {
  231. $icons .= '<i class="' . $icon_class . '"></i>';
  232. }
  233. // unset icon classes for attributes to prevent double rendering
  234. $variables['options']['attributes']['class'] = array_diff($css_classes, $icon_classes);
  235. }
  236. }
  237. return '<a href="' . check_plain(url($variables['path'], $variables['options'])) . '"' . drupal_attributes($variables['options']['attributes']) . '>' . $icons . '<span>' . ($variables['options']['html'] ? $variables['text'] : check_plain($variables['text'])) . '</span>' . '</a>';
  238. }
  239. /**
  240. * Returns HTML for a form element.
  241. *
  242. * Each form element is wrapped in a DIV container having the following CSS
  243. * classes:
  244. * - form-item: Generic for all form elements.
  245. * - form-type-#type: The internal element #type.
  246. * - form-item-#name: The internal form element #name (usually derived from the
  247. * $form structure and set via form_builder()).
  248. * - form-disabled: Only set if the form element is #disabled.
  249. *
  250. * In addition to the element itself, the DIV contains a label for the element
  251. * based on the optional #title_display property, and an optional #description.
  252. *
  253. * The optional #title_display property can have these values:
  254. * - before: The label is output before the element. This is the default.
  255. * The label includes the #title and the required marker, if #required.
  256. * - after: The label is output after the element. For example, this is used
  257. * for radio and checkbox #type elements as set in system_element_info().
  258. * If the #title is empty but the field is #required, the label will
  259. * contain only the required marker.
  260. * - invisible: Labels are critical for screen readers to enable them to
  261. * properly navigate through forms but can be visually distracting. This
  262. * property hides the label for everyone except screen readers.
  263. * - attribute: Set the title attribute on the element to create a tooltip
  264. * but output no label element. This is supported only for checkboxes
  265. * and radios in form_pre_render_conditional_form_element(). It is used
  266. * where a visual label is not needed, such as a table of checkboxes where
  267. * the row and column provide the context. The tooltip will include the
  268. * title and required marker.
  269. *
  270. * If the #title property is not set, then the label and any required marker
  271. * will not be output, regardless of the #title_display or #required values.
  272. * This can be useful in cases such as the password_confirm element, which
  273. * creates children elements that have their own labels and required markers,
  274. * but the parent element should have neither. Use this carefully because a
  275. * field without an associated label can cause accessibility challenges.
  276. *
  277. * @param $variables
  278. * An associative array containing:
  279. * - element: An associative array containing the properties of the element.
  280. * Properties used: #title, #title_display, #description, #id, #required,
  281. * #children, #type, #name.
  282. *
  283. * @ingroup themeable
  284. */
  285. function radix_form_element($variables) {
  286. $element = &$variables['element'];
  287. // This is also used in the installer, pre-database setup.
  288. $t = get_t();
  289. // This function is invoked as theme wrapper, but the rendered form element
  290. // may not necessarily have been processed by form_builder().
  291. $element += array(
  292. '#title_display' => 'before',
  293. );
  294. // Add element #id for #type 'item'.
  295. if (isset($element['#markup']) && !empty($element['#id'])) {
  296. $attributes['id'] = $element['#id'];
  297. }
  298. // Add element's #type and #name as class to aid with JS/CSS selectors.
  299. $attributes['class'] = array('form-item');
  300. if (!empty($element['#type'])) {
  301. $attributes['class'][] = 'form-type-' . strtr($element['#type'], '_', '-');
  302. }
  303. if (!empty($element['#name'])) {
  304. $attributes['class'][] = 'form-item-' . strtr($element['#name'], array(' ' => '-', '_' => '-', '[' => '-', ']' => ''));
  305. }
  306. // Add a class for disabled elements to facilitate cross-browser styling.
  307. if (!empty($element['#attributes']['disabled'])) {
  308. $attributes['class'][] = 'form-disabled';
  309. }
  310. $output = '<div' . drupal_attributes($attributes) . '>' . "\n";
  311. // If #title is not set, we don't display any label or required marker.
  312. if (!isset($element['#title'])) {
  313. $element['#title_display'] = 'none';
  314. }
  315. $prefix = isset($element['#field_prefix']) ? '<span class="field-prefix">' . $element['#field_prefix'] . '</span> ' : '';
  316. $suffix = isset($element['#field_suffix']) ? ' <span class="field-suffix">' . $element['#field_suffix'] . '</span>' : '';
  317. switch ($element['#title_display']) {
  318. case 'before':
  319. case 'invisible':
  320. $output .= ' ' . theme('form_element_label', $variables);
  321. $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
  322. break;
  323. case 'after':
  324. $output .= ' ' . $prefix . $element['#children'] . $suffix;
  325. $output .= ' ' . theme('form_element_label', $variables) . "\n";
  326. break;
  327. case 'none':
  328. case 'attribute':
  329. // Output no label and no required marker, only the children.
  330. $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
  331. break;
  332. }
  333. if (!empty($element['#description'])) {
  334. $output .= '<div class="description">' . $element['#description'] . "</div>\n";
  335. }
  336. $output .= "</div>\n";
  337. return $output;
  338. }