template.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. /**
  110. * Implements theme_form_element().
  111. */
  112. function OUT_guibik_form_element($variables) {
  113. $element = &$variables['element'];
  114. // This is also used in the installer, pre-database setup.
  115. $t = get_t();
  116. dsm($element);
  117. // This function is invoked as theme wrapper, but the rendered form element
  118. // may not necessarily have been processed by form_builder().
  119. $element += array(
  120. '#title_display' => 'before',
  121. );
  122. // Add element #id for #type 'item'.
  123. if (isset($element['#markup']) && !empty($element['#id'])) {
  124. $attributes['id'] = $element['#id'];
  125. }
  126. // Add element's #type and #name as class to aid with JS/CSS selectors.
  127. if(!isset($element["#attributes"]['class']))
  128. $element["#attributes"]['class'] = array();
  129. $attributes['class'] = $element["#attributes"]['class'] + array('form-item');
  130. if (!empty($element['#type'])) {
  131. $attributes['class'][] = 'form-type-' . strtr($element['#type'], '_', '-');
  132. }
  133. if (!empty($element['#name'])) {
  134. $attributes['class'][] = 'form-item-' . strtr($element['#name'], array(' ' => '-', '_' => '-', '[' => '-', ']' => ''));
  135. }
  136. // Add a class for disabled elements to facilitate cross-browser styling.
  137. if (!empty($element['#attributes']['disabled'])) {
  138. $attributes['class'][] = 'form-disabled';
  139. }
  140. $output = '<div' . drupal_attributes($attributes) . '>' . "\n";
  141. // If #title is not set, we don't display any label or required marker.
  142. if (!isset($element['#title'])) {
  143. $element['#title_display'] = 'none';
  144. }
  145. $prefix = isset($element['#field_prefix']) ? '<span class="field-prefix">' . $element['#field_prefix'] . '</span> ' : '';
  146. $suffix = isset($element['#field_suffix']) ? ' <span class="field-suffix">' . $element['#field_suffix'] . '</span>' : '';
  147. switch ($element['#title_display']) {
  148. case 'before':
  149. case 'invisible':
  150. $output .= ' ' . theme('form_element_label', $variables);
  151. $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
  152. break;
  153. case 'after':
  154. $output .= ' ' . $prefix . $element['#children'] . $suffix;
  155. $output .= ' ' . theme('form_element_label', $variables) . "\n";
  156. break;
  157. case 'none':
  158. case 'attribute':
  159. // Output no label and no required marker, only the children.
  160. $output .= ' ' . $prefix . $element['#children'] . $suffix . "\n";
  161. break;
  162. }
  163. if (!empty($element['#description'])) {
  164. $output .= '<div class="description">' . $element['#description'] . "</div>\n";
  165. }
  166. $output .= "</div>\n";
  167. return $output;
  168. }
  169. function guibik_form_node_form_alter(&$form, &$form_state){
  170. // dsm($form, 'guibik_form_node_form_alter | $form');
  171. // dsm($form_state, '$form_state');
  172. if(!isset($form['language']['#description']))
  173. $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.');
  174. }