template.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <?php
  2. /**
  3. * Implementation of hook_theme().
  4. */
  5. function guibik_theme() {
  6. $items = array();
  7. // Content theming.
  8. $items['help'] =
  9. $items['node'] =
  10. $items['comment'] =
  11. $items['comment_wrapper'] = array(
  12. 'path' => drupal_get_path('theme', 'rubik') .'/templates',
  13. 'template' => 'object',
  14. );
  15. $items['node']['template'] = 'node';
  16. // Help pages really need help. See preprocess_page().
  17. $items['help_page'] = array(
  18. 'variables' => array('content' => array()),
  19. 'path' => drupal_get_path('theme', 'rubik') .'/templates',
  20. 'template' => 'object',
  21. 'preprocess functions' => array(
  22. 'template_preprocess',
  23. 'rubik_preprocess_help_page',
  24. ),
  25. 'process functions' => array('template_process'),
  26. );
  27. // Form layout: default (2 column).
  28. $items['block_add_block_form'] =
  29. $items['block_admin_configure'] =
  30. $items['comment_form'] =
  31. $items['contact_admin_edit'] =
  32. $items['contact_mail_page'] =
  33. $items['contact_mail_user'] =
  34. $items['filter_admin_format_form'] =
  35. $items['forum_form'] =
  36. $items['locale_languages_edit_form'] =
  37. $items['menu_edit_menu'] =
  38. $items['menu_edit_item'] =
  39. $items['node_type_form'] =
  40. $items['path_admin_form'] =
  41. $items['system_settings_form'] =
  42. $items['system_themes_form'] =
  43. $items['system_modules'] =
  44. $items['system_actions_configure'] =
  45. $items['taxonomy_form_term'] =
  46. $items['taxonomy_form_vocabulary'] =
  47. $items['user_profile_form'] =
  48. $items['user_admin_access_add_form'] = array(
  49. 'render element' => 'form',
  50. 'path' => drupal_get_path('theme', 'guibik') .'/templates',
  51. 'template' => 'form-default',
  52. 'preprocess functions' => array(
  53. 'rubik_preprocess_form_buttons',
  54. ),
  55. );
  56. // These forms require additional massaging.
  57. $items['confirm_form'] = array(
  58. 'render element' => 'form',
  59. 'path' => drupal_get_path('theme', 'rubik') .'/templates',
  60. 'template' => 'form-simple',
  61. 'preprocess functions' => array(
  62. 'rubik_preprocess_form_confirm'
  63. ),
  64. );
  65. $items['node_form'] = array(
  66. 'render element' => 'form',
  67. 'path' => drupal_get_path('theme', 'guibik') .'/templates',
  68. 'template' => 'form-default',
  69. 'preprocess functions' => array(
  70. 'rubik_preprocess_form_buttons',
  71. 'rubik_preprocess_form_node',
  72. ),
  73. );
  74. return $items;
  75. }
  76. /**
  77. * Preprocessor for theme('page').
  78. */
  79. function guibik_preprocess_page(&$vars) {
  80. // Show a warning if base theme is not present.
  81. if (!function_exists('rubik_theme') && user_access('administer site configuration')) {
  82. drupal_set_message(t('The Guibik theme requires the !rubik base theme in order to work properly.', array('!rubik' => l('Rubik', 'http://code.developmentseed.org/tao'))), 'warning');
  83. }
  84. // Process local tasks. Only do this processing if the current theme is
  85. // indeed Rubik. Subthemes must reimplement this call.
  86. global $theme;
  87. if ($theme === 'guibik')
  88. _rubik_local_tasks($vars);
  89. }
  90. function guibik_preprocess_html(&$vars){
  91. $heads['icon'] = array(
  92. '#tag' => 'link',
  93. '#attributes' => array(
  94. 'href' => base_path() . path_to_theme() .'/icon.png',
  95. 'rel' => 'shortcut icon',
  96. 'type' => 'image/png',
  97. ),
  98. );
  99. $heads['apple-touch-icon'] = array(
  100. '#tag' => 'link',
  101. '#attributes' => array(
  102. 'href' => base_path() . path_to_theme() .'/apple-touch-icon.png',
  103. 'rel' => 'apple-touch-icon',
  104. ),
  105. );
  106. foreach ($heads as $type=>$head)
  107. drupal_add_html_head($head, $type);
  108. }
  109. function guibik_preprocess_views_view_table(&$vars){
  110. if($vars['title'] != ''){
  111. $vars['classes_array'][] = 'has-caption';
  112. }
  113. // dsm($vars);
  114. }
  115. /**
  116. * Implements theme_form_element().
  117. */
  118. function OUT_guibik_form_element($variables) {
  119. $element = &$variables['element'];
  120. // This is also used in the installer, pre-database setup.
  121. $t = get_t();
  122. //dsm($element);
  123. // This function is invoked as theme wrapper, but the rendered form element
  124. // may not necessarily have been processed by form_builder().
  125. $element += array(
  126. '#title_display' => 'before',
  127. );
  128. // Add element #id for #type 'item'.
  129. if (isset($element['#markup']) && !empty($element['#id'])) {
  130. $attributes['id'] = $element['#id'];
  131. }
  132. // Add element's #type and #name as class to aid with JS/CSS selectors.
  133. if(!isset($element["#attributes"]['class']))
  134. $element["#attributes"]['class'] = array();
  135. $attributes['class'] = $element["#attributes"]['class'] + array('form-item');
  136. if (!empty($element['#type'])) {
  137. $attributes['class'][] = 'form-type-' . strtr($element['#type'], '_', '-');
  138. }
  139. if (!empty($element['#name'])) {
  140. $attributes['class'][] = 'form-item-' . strtr($element['#name'], array(' ' => '-', '_' => '-', '[' => '-', ']' => ''));
  141. }
  142. // Add a class for disabled elements to facilitate cross-browser styling.
  143. if (!empty($element['#attributes']['disabled'])) {
  144. $attributes['class'][] = 'form-disabled';
  145. }
  146. $output = '<div' . drupal_attributes($attributes) . '>' . "\n";
  147. // If #title is not set, we don't display any label or required marker.
  148. if (!isset($element['#title'])) {
  149. $element['#title_display'] = 'none';
  150. }
  151. $prefix = isset($element['#field_prefix']) ? '<span class="field-prefix">' . $element['#field_prefix'] . '</span> ' : '';
  152. $suffix = isset($element['#field_suffix']) ? ' <span class="field-suffix">' . $element['#field_suffix'] . '</span>' : '';
  153. switch ($element['#title_display']) {
  154. case 'before':
  155. case 'invisible':
  156. $output .= ' ' . theme('form_element_label', $variables);
  157. $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
  158. break;
  159. case 'after':
  160. $output .= ' ' . $prefix . $element['#children'] . $suffix;
  161. $output .= ' ' . theme('form_element_label', $variables) . "\n";
  162. break;
  163. case 'none':
  164. case 'attribute':
  165. // Output no label and no required marker, only the children.
  166. $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
  167. break;
  168. }
  169. if (!empty($element['#description'])) {
  170. $output .= '<div class="description">' . $element['#description'] . "</div>\n";
  171. }
  172. $output .= "</div>\n";
  173. return $output;
  174. }
  175. function guibik_form_node_form_alter(&$form, &$form_state){
  176. // dsm($form, 'guibik_form_node_form_alter | $form');
  177. // dsm($form_state, '$form_state');
  178. if(!isset($form['language']['#description']))
  179. $form['language']['#description'] = t('Please consider to leave language in neutral state <strong>if you dont plan to translate this node</strong>, even if your content is (obviously) writed in some non neutral language. Then this node will always be visible.');
  180. }
  181. function guibik_image_field_widget_process($element, &$form_state, $form){
  182. $element['title']['#type'] = "textarea";
  183. return $element;
  184. }
  185. function guibik_field_widget_form_alter(&$element, &$form_state, $context) {
  186. // dsm($context['field']['type'], '$context[field][type]');
  187. if ($context['field']['type'] == 'image') {
  188. foreach ($element as $delta => $item) {
  189. if(!isset($element[$delta]['#process']) || !is_array($element[$delta]['#process']))
  190. continue;
  191. $element[$delta]['#process'][] = "guibik_image_field_widget_process";
  192. }
  193. }
  194. }