theme.inc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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. $vars['lock_feature'] = theme('features_lock_link', array('feature' => $form['#feature']->name));
  75. }
  76. /**
  77. * Themes a module status display.
  78. */
  79. function theme_features_module_status($vars) {
  80. switch ($vars['status']) {
  81. case FEATURES_MODULE_ENABLED:
  82. $text_status = t('Enabled');
  83. $class = 'admin-enabled';
  84. break;
  85. case FEATURES_MODULE_DISABLED:
  86. $text_status = t('Disabled');
  87. $class = 'admin-disabled';
  88. break;
  89. case FEATURES_MODULE_MISSING:
  90. $text_status = t('Missing');
  91. $class = 'admin-missing';
  92. break;
  93. case FEATURES_MODULE_CONFLICT:
  94. $text_status = t('Enabled');
  95. $class = 'admin-conflict';
  96. break;
  97. }
  98. $text = !empty($vars['module']) ? $vars['module'] . ' (' . $text_status . ')' : $text_status;
  99. return "<span class=\"$class\">$text</span>";
  100. }
  101. /**
  102. * Themes a lock link
  103. */
  104. function theme_features_lock_link($vars) {
  105. drupal_add_library('system', 'ui');
  106. drupal_add_library('system', 'drupal.ajax');
  107. $component = $vars['component'] ? $vars['component'] : '';
  108. if ($component && features_component_is_locked($component)) {
  109. return l(t('Component locked'), 'admin/structure/features/settings', array(
  110. 'attributes' => array(
  111. 'class' => 'features-lock-icon ui-icon ui-icon-locked',
  112. 'title' => t('This component is locked on a global level.'),
  113. ),
  114. 'fragment' => 'edit-lock-components',
  115. ));
  116. }
  117. $feature = $vars['feature'];
  118. $is_locked = features_feature_is_locked($feature, $component);
  119. $options = array(
  120. 'attributes' => array(
  121. 'class' => array('use-ajax features-lock-icon ui-icon ' . ($is_locked ? ' ui-icon-locked' : ' ui-icon-unlocked')),
  122. 'id' => 'features-lock-link-' . $feature . ($component ? '-' . $component : ''),
  123. 'title' => $is_locked ? t('This item is locked and features will not be rebuilt or reverted.') : t('This item is unlocked and will be rebuilt/reverted as normal.'),
  124. ),
  125. 'query' => array('token' => drupal_get_token('features/' . $feature . '/' . $component)),
  126. );
  127. $path = "admin/structure/features/" . $feature . "/lock/nojs" . ($component ? '/' . $component: '');
  128. return l($is_locked ? t('UnLock') : t('Lock'), $path, $options);
  129. }
  130. /**
  131. * Themes a module status display.
  132. */
  133. function theme_features_storage_link($vars) {
  134. $classes = array(
  135. FEATURES_OVERRIDDEN => 'admin-overridden',
  136. FEATURES_DEFAULT => 'admin-default',
  137. FEATURES_NEEDS_REVIEW => 'admin-needs-review',
  138. FEATURES_REBUILDING => 'admin-rebuilding',
  139. FEATURES_REBUILDABLE => 'admin-rebuilding',
  140. FEATURES_CONFLICT => 'admin-conflict',
  141. FEATURES_DISABLED => 'admin-disabled',
  142. FEATURES_CHECKING => 'admin-loading',
  143. );
  144. $default_text = array(
  145. FEATURES_OVERRIDDEN => t('Overridden'),
  146. FEATURES_DEFAULT => t('Default'),
  147. FEATURES_NEEDS_REVIEW => t('Needs review'),
  148. FEATURES_REBUILDING => t('Rebuilding'),
  149. FEATURES_REBUILDABLE => t('Rebuilding'),
  150. FEATURES_CONFLICT => t('Conflict'),
  151. FEATURES_DISABLED => t('Disabled'),
  152. FEATURES_CHECKING => t('Checking...'),
  153. );
  154. $text = isset($vars['text']) ? $vars['text'] : $default_text[$vars['storage']];
  155. if ($vars['path']) {
  156. $vars['options']['attributes']['class'][] = $classes[$vars['storage']];
  157. $vars['options']['attributes']['class'][] = 'features-storage';
  158. return l($text, $vars['path'], $vars['options']);
  159. }
  160. else {
  161. return "<span class='{$classes[$vars['storage']]} features-storage'>{$text}</span>";
  162. }
  163. }
  164. /**
  165. * Theme function for displaying form buttons
  166. */
  167. function theme_features_form_buttons(&$vars) {
  168. drupal_add_css(drupal_get_path('module', 'features') . '/features.css');
  169. $output = drupal_render_children($vars['element']);
  170. return !empty($output) ? "<div class='buttons clearfix'>{$output}</div>" : '';
  171. }
  172. /**
  173. * Theme for features management form.
  174. */
  175. function theme_features_form_package(&$vars) {
  176. drupal_add_css(drupal_get_path('module', 'features') . '/features.css');
  177. drupal_add_js(drupal_get_path('module', 'features') . '/features.js');
  178. $output = '';
  179. $header = array('', t('Feature'), t('Signature'));
  180. if (isset($vars['form']['state'])) {
  181. $header[] = t('State');
  182. }
  183. if (isset($vars['form']['actions'])) {
  184. $header[] = t('Actions');
  185. }
  186. $rows = array();
  187. foreach (element_children($vars['form']['status']) as $element) {
  188. // Yank title & description fields off the form element for
  189. // rendering in their own cells.
  190. $name = "<div class='feature'>";
  191. $name .= "<strong>{$vars['form']['status'][$element]['#title']}</strong>";
  192. $name .= "<div class='description'>{$vars['form']['status'][$element]['#description']}</div>";
  193. $name .= "</div>";
  194. unset($vars['form']['status'][$element]['#title']);
  195. unset($vars['form']['status'][$element]['#description']);
  196. // Determine row & cell classes
  197. $class = $vars['form']['status'][$element]['#default_value'] ? 'enabled' : 'disabled';
  198. $row = array();
  199. $row['status'] = array('data' => drupal_render($vars['form']['status'][$element]), 'class' => array('status'));
  200. $row['name'] = array('data' => $name, 'class' => 'name');
  201. $row['sign'] = array('data' => drupal_render($vars['form']['sign'][$element]), 'class' => array('sign'));
  202. if (isset($vars['form']['state'])) {
  203. $row['state'] = array('data' => drupal_render($vars['form']['state'][$element]), 'class' => array('state'));
  204. }
  205. if (isset($vars['form']['actions'])) {
  206. $row['actions'] = array('data' => drupal_render($vars['form']['actions'][$element]), 'class' => array('actions'));
  207. }
  208. $rows[] = array('data' => $row, 'class' => array($class));
  209. }
  210. if (empty($rows)) {
  211. $rows[] = array('', array('data' => t('No features available.'), 'colspan' => count($header)));
  212. }
  213. $class = count($header) > 3 ? 'features features-admin' : 'features features-manage';
  214. $output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'features-form-table', 'class' => array($class))));
  215. // Prevent section from being rendered by drupal_render().
  216. $output .= drupal_render($vars['form']['buttons']);
  217. $output .= drupal_render_children($vars['form']);
  218. return $output;
  219. }
  220. /**
  221. * Theme functions ====================================================
  222. */
  223. /**
  224. * Export selection / display for features export form.
  225. */
  226. function theme_features_form_export(&$vars) {
  227. drupal_add_css(drupal_get_path('module', 'features') . '/features.css');
  228. drupal_add_js(drupal_get_path('module', 'features') . '/features.js');
  229. $output = '';
  230. $output .= "<div class='clearfix features-components'>";
  231. $output .= "<div class='column'>" . drupal_render($vars['form']['components']) . drupal_render($vars['form']['sources']) . "</div>";
  232. $output .= "<div class='column'>" . drupal_render($vars['form']['preview']) . drupal_render($vars['form']['features']) . "</div>";
  233. $output .= "</div>";
  234. $output .= drupal_render_children($vars['form']);
  235. return $output;
  236. }
  237. /**
  238. * Theme a set of features export components.
  239. */
  240. function theme_features_form_components(&$vars) {
  241. $output = '';
  242. foreach (element_children($vars['form']) as $key) {
  243. unset($vars['form'][$key]['#title']);
  244. $output .= "<div class='features-select features-select-{$key}'>" . drupal_render($vars['form'][$key]) . "</div>";
  245. }
  246. $output .= drupal_render_children($vars['form']);
  247. return $output;
  248. }
  249. /**
  250. * Theme a set of features export components.
  251. */
  252. function theme_features_components($vars) {
  253. $info = $vars['info'];
  254. $sources = $vars['sources'];
  255. $output = '';
  256. $rows = array();
  257. $components = features_get_components();
  258. if (!empty($info['features']) || !empty($info['dependencies']) || !empty($sources)) {
  259. $export = array_unique(array_merge(
  260. array_keys($info['features']),
  261. array_keys($sources),
  262. array('dependencies')
  263. ));
  264. foreach ($export as $component) {
  265. if ($component === 'dependencies') {
  266. $feature_items = isset($info[$component]) ? $info[$component] : array();
  267. }
  268. else {
  269. $feature_items = isset($info['features'][$component]) ? $info['features'][$component] : array();
  270. }
  271. $source_items = isset($sources[$component]) ? $sources[$component] : array();
  272. if (!empty($feature_items) || !empty($source_items)) {
  273. $rows[] = array(array(
  274. 'data' => isset($components[$component]['name']) ? $components[$component]['name'] : $component,
  275. 'header' => TRUE
  276. ));
  277. $rows[] = array(array(
  278. 'data' => theme('features_component_list', array('components' => $feature_items, 'source' => $source_items)),
  279. 'class' => 'component'
  280. ));
  281. }
  282. }
  283. $output .= theme('table', array('header' => array(), 'rows' => $rows));
  284. $output .= theme('features_component_key', array());
  285. }
  286. return $output;
  287. }
  288. /**
  289. * Theme individual components in a component list.
  290. */
  291. function theme_features_component_list($vars) {
  292. $components = $vars['components'];
  293. $source = $vars['source'];
  294. $conflicts = $vars['conflicts'];
  295. $list = array();
  296. foreach ($components as $component) {
  297. // If component is not in source list, it was autodetected
  298. if (!in_array($component, $source)) {
  299. $list[] = "<span class='features-detected'>". check_plain($component) ."</span>";
  300. }
  301. elseif (is_array($conflicts) && in_array($component, $conflicts)) {
  302. $list[] = "<span class='features-conflict'>". check_plain($component) ."</span>";
  303. }
  304. else {
  305. $list[] = "<span class='features-source'>". check_plain($component) ."</span>";
  306. }
  307. }
  308. foreach ($source as $component) {
  309. // If a source component is no longer in the items, it was removed because
  310. // it is provided by a dependency.
  311. if (!in_array($component, $components)) {
  312. $list[] = "<span class='features-dependency'>". check_plain($component) ."</span>";
  313. }
  314. }
  315. return "<span class='features-component-list'>". implode(' ', $list) ."</span>";
  316. }
  317. /**
  318. * Provide a themed key for a component list.
  319. */
  320. function theme_features_component_key($vars) {
  321. $list = array();
  322. $list[] = "<span class='features-source'>" . t('Normal') . "</span>";
  323. $list[] = "<span class='features-detected'>" . t('Auto-detected') . "</span>";
  324. $list[] = "<span class='features-dependency'>" . t('Provided by dependency') . "</span>";
  325. return "<span class='features-component-list features-component-key'>" . implode(' ', $list) . "</span>";
  326. }