theme.inc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <?php
  2. /**
  3. * Display feature component info
  4. */
  5. function template_preprocess_features_admin_components(&$vars) {
  6. drupal_add_css(drupal_get_path('module', 'features') . '/features.css');
  7. $form = $vars['form'];
  8. // Basic info
  9. $vars['name'] = $form['#info']['name'];
  10. $vars['description'] = isset($form['#info']['description']) ? $form['#info']['description'] : '';
  11. // Legend/key
  12. $vars['key'] = array();
  13. // Dependencies
  14. $rows = array();
  15. $modules = features_get_info();
  16. foreach ($form['#dependencies'] as $dependency => $status) {
  17. $rows[] = array(
  18. array(
  19. 'data' => isset($modules[$dependency]->info['name']) ? $modules[$dependency]->info['name'] : $dependency,
  20. 'class' => 'component'
  21. ),
  22. theme('features_module_status', array('status' => $status)),
  23. );
  24. }
  25. $vars['dependencies'] = theme('table', array('header' => array(t('Dependency'), t('Status')), 'rows' => $rows));
  26. // Components
  27. $rows = array();
  28. $components = features_get_components();
  29. // Display key for conflicting elements.
  30. if (!empty($form['#conflicts'])) {
  31. $vars['key'][] = array(
  32. 'title' => theme('features_storage_link', array('storage' => FEATURES_CONFLICT, 'text' => t('Conflicts with another feature'))),
  33. 'html' => TRUE,
  34. );
  35. }
  36. if (!empty($form['#info']['features'])) {
  37. foreach ($form['#info']['features'] as $component => $items) {
  38. if (!empty($items)) {
  39. $conflicts = array_key_exists($component, $form['#conflicts'])
  40. ? $form['#conflicts'][$component]
  41. : NULL;
  42. $header = $data = array();
  43. if (element_children($form['revert'])) {
  44. $header[] = array(
  45. 'data' => isset($form['revert'][$component]) ? drupal_render($form['revert'][$component]) : '',
  46. 'header' => TRUE
  47. );
  48. }
  49. $header[] = array(
  50. 'data' => isset($components[$component]['name']) ? $components[$component]['name'] : $component,
  51. 'header' => TRUE
  52. );
  53. $header[] = array(
  54. 'data' => drupal_render($form['components'][$component]),
  55. 'header' => TRUE
  56. );
  57. $rows[] = $header;
  58. if (element_children($form['revert'])) {
  59. $data[] = '';
  60. }
  61. $data[] = array(
  62. 'data' => theme('features_component_list', array('components' => $items, 'source' => $items, 'conflicts' => $conflicts)),
  63. 'colspan' => 2,
  64. 'class' => 'component'
  65. );
  66. $rows[] = $data;
  67. }
  68. }
  69. }
  70. $vars['components'] = theme('table', array('header' => array(), 'rows' => $rows));
  71. // Other elements
  72. $vars['buttons'] = drupal_render($form['buttons']);
  73. $vars['form'] = $form;
  74. }
  75. /**
  76. * Themes a module status display.
  77. */
  78. function theme_features_module_status($vars) {
  79. switch ($vars['status']) {
  80. case FEATURES_MODULE_ENABLED:
  81. $text_status = t('Enabled');
  82. $class = 'admin-enabled';
  83. break;
  84. case FEATURES_MODULE_DISABLED:
  85. $text_status = t('Disabled');
  86. $class = 'admin-disabled';
  87. break;
  88. case FEATURES_MODULE_MISSING:
  89. $text_status = t('Missing');
  90. $class = 'admin-missing';
  91. break;
  92. case FEATURES_MODULE_CONFLICT:
  93. $text_status = t('Enabled');
  94. $class = 'admin-conflict';
  95. break;
  96. }
  97. $text = !empty($vars['module']) ? $vars['module'] . ' (' . $text_status . ')' : $text_status;
  98. return "<span class=\"$class\">$text</span>";
  99. }
  100. /**
  101. * Themes a module status display.
  102. */
  103. function theme_features_storage_link($vars) {
  104. $classes = array(
  105. FEATURES_OVERRIDDEN => 'admin-overridden',
  106. FEATURES_DEFAULT => 'admin-default',
  107. FEATURES_NEEDS_REVIEW => 'admin-needs-review',
  108. FEATURES_REBUILDING => 'admin-rebuilding',
  109. FEATURES_REBUILDABLE => 'admin-rebuilding',
  110. FEATURES_CONFLICT => 'admin-conflict',
  111. FEATURES_DISABLED => 'admin-disabled',
  112. FEATURES_CHECKING => 'admin-loading',
  113. );
  114. $default_text = array(
  115. FEATURES_OVERRIDDEN => t('Overridden'),
  116. FEATURES_DEFAULT => t('Default'),
  117. FEATURES_NEEDS_REVIEW => t('Needs review'),
  118. FEATURES_REBUILDING => t('Rebuilding'),
  119. FEATURES_REBUILDABLE => t('Rebuilding'),
  120. FEATURES_CONFLICT => t('Conflict'),
  121. FEATURES_DISABLED => t('Disabled'),
  122. FEATURES_CHECKING => t('Checking...'),
  123. );
  124. $text = isset($vars['text']) ? $vars['text'] : $default_text[$vars['storage']];
  125. if ($vars['path']) {
  126. $vars['options']['attributes']['class'][] = $classes[$vars['storage']];
  127. $vars['options']['attributes']['class'][] = 'features-storage';
  128. return l($text, $vars['path'], $vars['options']);
  129. }
  130. else {
  131. return "<span class='{$classes[$vars['storage']]} features-storage'>{$text}</span>";
  132. }
  133. }
  134. /**
  135. * Theme function for displaying form buttons
  136. */
  137. function theme_features_form_buttons(&$vars) {
  138. drupal_add_css(drupal_get_path('module', 'features') . '/features.css');
  139. $output = drupal_render_children($vars['element']);
  140. return !empty($output) ? "<div class='buttons clearfix'>{$output}</div>" : '';
  141. }
  142. /**
  143. * Theme for features management form.
  144. */
  145. function theme_features_form_package(&$vars) {
  146. drupal_add_css(drupal_get_path('module', 'features') . '/features.css');
  147. drupal_add_js(drupal_get_path('module', 'features') . '/features.js');
  148. $output = '';
  149. $header = array('', t('Feature'), t('Signature'));
  150. if (isset($vars['form']['state'])) {
  151. $header[] = t('State');
  152. }
  153. if (isset($vars['form']['actions'])) {
  154. $header[] = t('Actions');
  155. }
  156. $rows = array();
  157. foreach (element_children($vars['form']['status']) as $element) {
  158. // Yank title & description fields off the form element for
  159. // rendering in their own cells.
  160. $name = "<div class='feature'>";
  161. $name .= "<strong>{$vars['form']['status'][$element]['#title']}</strong>";
  162. $name .= "<div class='description'>{$vars['form']['status'][$element]['#description']}</div>";
  163. $name .= "</div>";
  164. unset($vars['form']['status'][$element]['#title']);
  165. unset($vars['form']['status'][$element]['#description']);
  166. // Determine row & cell classes
  167. $class = $vars['form']['status'][$element]['#default_value'] ? 'enabled' : 'disabled';
  168. $row = array();
  169. $row['status'] = array('data' => drupal_render($vars['form']['status'][$element]), 'class' => array('status'));
  170. $row['name'] = array('data' => $name, 'class' => 'name');
  171. $row['sign'] = array('data' => drupal_render($vars['form']['sign'][$element]), 'class' => array('sign'));
  172. if (isset($vars['form']['state'])) {
  173. $row['state'] = array('data' => drupal_render($vars['form']['state'][$element]), 'class' => array('state'));
  174. }
  175. if (isset($vars['form']['actions'])) {
  176. $row['actions'] = array('data' => drupal_render($vars['form']['actions'][$element]), 'class' => array('actions'));
  177. }
  178. $rows[] = array('data' => $row, 'class' => array($class));
  179. }
  180. if (empty($rows)) {
  181. $rows[] = array('', array('data' => t('No features available.'), 'colspan' => count($header)));
  182. }
  183. $class = count($header) > 3 ? 'features features-admin' : 'features features-manage';
  184. $output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'features-form-table', 'class' => array($class))));
  185. // Prevent section from being rendered by drupal_render().
  186. $output .= drupal_render($vars['form']['buttons']);
  187. $output .= drupal_render_children($vars['form']);
  188. return $output;
  189. }
  190. /**
  191. * Theme functions ====================================================
  192. */
  193. /**
  194. * Export selection / display for features export form.
  195. */
  196. function theme_features_form_export(&$vars) {
  197. drupal_add_css(drupal_get_path('module', 'features') . '/features.css');
  198. drupal_add_js(drupal_get_path('module', 'features') . '/features.js');
  199. $output = '';
  200. $output .= "<div class='clearfix features-components'>";
  201. $output .= "<div class='column'>" . drupal_render($vars['form']['components']) . drupal_render($vars['form']['sources']) . "</div>";
  202. $output .= "<div class='column'>" . drupal_render($vars['form']['preview']) . drupal_render($vars['form']['features']) . "</div>";
  203. $output .= "</div>";
  204. $output .= drupal_render_children($vars['form']);
  205. return $output;
  206. }
  207. /**
  208. * Theme a set of features export components.
  209. */
  210. function theme_features_form_components(&$vars) {
  211. $output = '';
  212. foreach (element_children($vars['form']) as $key) {
  213. unset($vars['form'][$key]['#title']);
  214. $output .= "<div class='features-select features-select-{$key}'>" . drupal_render($vars['form'][$key]) . "</div>";
  215. }
  216. $output .= drupal_render_children($vars['form']);
  217. return $output;
  218. }
  219. /**
  220. * Theme a set of features export components.
  221. */
  222. function theme_features_components($vars) {
  223. $info = $vars['info'];
  224. $sources = $vars['sources'];
  225. $output = '';
  226. $rows = array();
  227. $components = features_get_components();
  228. if (!empty($info['features']) || !empty($info['dependencies']) || !empty($sources)) {
  229. $export = array_unique(array_merge(
  230. array_keys($info['features']),
  231. array_keys($sources),
  232. array('dependencies')
  233. ));
  234. foreach ($export as $component) {
  235. if ($component === 'dependencies') {
  236. $feature_items = isset($info[$component]) ? $info[$component] : array();
  237. }
  238. else {
  239. $feature_items = isset($info['features'][$component]) ? $info['features'][$component] : array();
  240. }
  241. $source_items = isset($sources[$component]) ? $sources[$component] : array();
  242. if (!empty($feature_items) || !empty($source_items)) {
  243. $rows[] = array(array(
  244. 'data' => isset($components[$component]['name']) ? $components[$component]['name'] : $component,
  245. 'header' => TRUE
  246. ));
  247. $rows[] = array(array(
  248. 'data' => theme('features_component_list', array('components' => $feature_items, 'source' => $source_items)),
  249. 'class' => 'component'
  250. ));
  251. }
  252. }
  253. $output .= theme('table', array('header' => array(), 'rows' => $rows));
  254. $output .= theme('features_component_key', array());
  255. }
  256. return $output;
  257. }
  258. /**
  259. * Theme individual components in a component list.
  260. */
  261. function theme_features_component_list($vars) {
  262. $components = $vars['components'];
  263. $source = $vars['source'];
  264. $conflicts = $vars['conflicts'];
  265. $list = array();
  266. foreach ($components as $component) {
  267. // If component is not in source list, it was autodetected
  268. if (!in_array($component, $source)) {
  269. $list[] = "<span class='features-detected'>". check_plain($component) ."</span>";
  270. }
  271. elseif (is_array($conflicts) && in_array($component, $conflicts)) {
  272. $list[] = "<span class='features-conflict'>". check_plain($component) ."</span>";
  273. }
  274. else {
  275. $list[] = "<span class='features-source'>". check_plain($component) ."</span>";
  276. }
  277. }
  278. foreach ($source as $component) {
  279. // If a source component is no longer in the items, it was removed because
  280. // it is provided by a dependency.
  281. if (!in_array($component, $components)) {
  282. $list[] = "<span class='features-dependency'>". check_plain($component) ."</span>";
  283. }
  284. }
  285. return "<span class='features-component-list'>". implode(' ', $list) ."</span>";
  286. }
  287. /**
  288. * Provide a themed key for a component list.
  289. */
  290. function theme_features_component_key($vars) {
  291. $list = array();
  292. $list[] = "<span class='features-source'>" . t('Normal') . "</span>";
  293. $list[] = "<span class='features-detected'>" . t('Auto-detected') . "</span>";
  294. $list[] = "<span class='features-dependency'>" . t('Provided by dependency') . "</span>";
  295. return "<span class='features-component-list features-component-key'>" . implode(' ', $list) . "</span>";
  296. }