tmgmt_ui.theme.inc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <?php
  2. /**
  3. * @file
  4. * Theme file stub for tmgmt.
  5. */
  6. /**
  7. * Generic theme function for use with Render API.
  8. *
  9. * Renders the #title and #attributes properties if they are present.
  10. */
  11. function theme_tmgmt_ui_element($variables) {
  12. $element = $variables['element'];
  13. // Use the #title attribute.
  14. $title = '';
  15. if (!empty($element['#title'])) {
  16. $title = '<h3>' . check_plain($element['#title']) . '</h3>';
  17. }
  18. // Use #attributes to customize a wrapper <div>.
  19. $attributes = '';
  20. if (!empty($element['#attributes'])) {
  21. $attributes = drupal_attributes($element['#attributes']);
  22. }
  23. // Render any child items.
  24. if (!$element['#children']) {
  25. $element['#children'] = drupal_render_children($element);
  26. }
  27. // Build simple output.
  28. $output = "<div{$attributes}>{$title}{$element['#children']}</div>";
  29. return $output;
  30. }
  31. /**
  32. * Gets translation language status.
  33. *
  34. * @param array $variables
  35. * - 'translation_status': A flag that determines the status. Possible values:
  36. * original, missing, outofdate.
  37. * - 'job_item': Current job item entity associated with translation.
  38. *
  39. * @return string
  40. * Icon or a link icon that explains the translation status and possibly
  41. * links to an active translation job.
  42. */
  43. function theme_tmgmt_ui_translation_language_status_single($variables) {
  44. switch ($variables['translation_status']) {
  45. case 'original':
  46. $label = t('Source language');
  47. $icon_color = 'tmgmt-ui-icon-white';
  48. break;
  49. case 'missing':
  50. $label = t('Not translated');
  51. $icon_color = 'tmgmt-ui-icon-grey';
  52. break;
  53. case 'outofdate':
  54. $label = t('Translation Outdated');
  55. $icon_color = 'tmgmt-ui-icon-orange';
  56. break;
  57. default:
  58. $label = t('Translation up to date');
  59. $icon_color = 'tmgmt-ui-icon-green';
  60. }
  61. // Add classes to show the correct html icon.
  62. $classes = array();
  63. $classes[] = 'tmgmt-ui-icon';
  64. // Icon size 10px square.
  65. $classes[] = 'tmgmt-ui-icon-10';
  66. $classes[] = $icon_color;
  67. // Add necessary css file.
  68. drupal_add_css(drupal_get_path('module', 'tmgmt_ui') . '/css/tmgmt_ui.admin.css');
  69. $status = sprintf('<div class="%s" title="%s"><span></span></div>', implode(' ', $classes), $label);
  70. // If we have an active job item, wrap it in a link.
  71. if (!empty($variables['job_item'])) {
  72. $job_item_wrapper = entity_metadata_wrapper('tmgmt_job_item', $variables['job_item']);
  73. $label = t('Active job item: @state', array('@state' => $job_item_wrapper->state->label()));
  74. $uri = $variables['job_item']->uri();
  75. /** @var TMGMTJob $job */
  76. $job = $variables['job_item']->getJob();
  77. $job_wrapper = entity_metadata_wrapper('tmgmt_job', $job);
  78. switch ($variables['job_item']->state) {
  79. case TMGMT_JOB_ITEM_STATE_ACTIVE:
  80. if ($job->isUnprocessed()) {
  81. $uri = $job->uri();
  82. $label = t('Active job item: @state', array('@state' => $job_wrapper->state->label()));
  83. }
  84. $icon_color = 'tmgmt-ui-icon-blue';
  85. break;
  86. case TMGMT_JOB_ITEM_STATE_REVIEW:
  87. $icon_color = 'tmgmt-ui-icon-yellow';
  88. break;
  89. }
  90. // Add classes to show the correct html icon.
  91. $classes = array();
  92. $classes[] = 'tmgmt-ui-icon';
  93. // Icon size 10px square.
  94. $classes[] = 'tmgmt-ui-icon-10';
  95. $classes[] = $icon_color;
  96. $job_status = sprintf('<div class="%s" title="%s"><span></span></div>', implode(' ', $classes), $label);
  97. $status .= l($job_status, $uri['path'], array(
  98. 'query' => array('destination' => current_path()),
  99. 'html' => TRUE,
  100. 'attributes' => array('title' => $label),
  101. ));
  102. }
  103. return $status;
  104. }
  105. /**
  106. * Renders a data item status as an HTML/CSS icon.
  107. */
  108. function theme_tmgmt_ui_translator_review_form_element_status($variables) {
  109. $classes = array();
  110. $classes[] = 'tmgmt-ui-icon';
  111. $classes[] = 'tmgmt-ui-icon-32'; // Icon size 32px square.
  112. switch ($variables['status']['#value']) {
  113. case TMGMT_DATA_ITEM_STATE_ACCEPTED:
  114. $title = t('Accepted');
  115. // Unicode character U+2611 BALLOT BOX WITH CHECK.
  116. $icon = '&#x2611;';
  117. $classes[] = 'tmgmt-ui-icon-darkgreen';
  118. $classes[] = 'tmgmt-ui-state-accepted';
  119. break;
  120. case TMGMT_DATA_ITEM_STATE_REVIEWED:
  121. $title = t('Reviewed');
  122. // Unicode character U+2611 BALLOT BOX WITH CHECK.
  123. $icon = '&#x2611;';
  124. $classes[] = 'tmgmt-ui-icon-green';
  125. $classes[] = 'tmgmt-ui-state-reviewed';
  126. break;
  127. case TMGMT_DATA_ITEM_STATE_TRANSLATED:
  128. $title = t('Translated');
  129. // Unicode character U+2610 BALLOT BOX.
  130. $icon = '&#x2610;';
  131. $classes[] = 'tmgmt-ui-icon-yellow';
  132. $classes[] = 'tmgmt-ui-state-translated';
  133. break;
  134. case TMGMT_DATA_ITEM_STATE_PENDING:
  135. default:
  136. $title = t('Pending');
  137. // Just an empty icon without a sign.
  138. $icon = '';
  139. $classes[] = 'tmgmt-ui-icon-grey';
  140. $classes[] = 'tmgmt-ui-state-pending';
  141. break;
  142. }
  143. return sprintf('<div class="%s" title="%s"><span>%s</span></div>', implode(' ', $classes), $title, $icon);
  144. }
  145. /**
  146. * Render one single data item as a table row.
  147. */
  148. function theme_tmgmt_ui_translator_review_form_element($variables) {
  149. $element = $variables['element'];
  150. // Label of all element groups.
  151. if (!isset($element['#top_label'])) {
  152. $element['#top_label'] = array_shift($element['#parent_label']);
  153. }
  154. // Label of the current data item.
  155. if (!isset($element['#leave_label'])) {
  156. $element['#leave_label'] = array_pop($element['#parent_label']);
  157. }
  158. // Do not repeat labels inside the same hierarchy.
  159. if ($element['#top_label'] == $element['#leave_label']) {
  160. $element['#leave_label'] = '';
  161. }
  162. $result = '<tr' . drupal_attributes(array('class' => $element['#zebra'])) . '>';
  163. $row = array();
  164. $leaf_label = '<label>' . $element['#leave_label'] . '</label>';
  165. $leaf_label = '<div class="form-item form-type-label">' . $leaf_label . '</div>';
  166. $row[] = array(
  167. 'data' => $leaf_label . '<div class="tmgmt-ui-state">' . drupal_render($element['status']) . '</div>',
  168. 'class' => 'tmgmt-ui-data-item-label',
  169. );
  170. $row[] = array(
  171. 'data' => drupal_render($element['source']),
  172. 'class' => 'tmgmt-ui-data-item-source',
  173. );
  174. $row[] = array(
  175. 'data' => drupal_render($element['translation']),
  176. 'class' => 'tmgmt-ui-data-item-translation',
  177. );
  178. $row[] = array(
  179. 'data' => drupal_render($element['actions']),
  180. 'class' => 'tmgmt-ui-data-item-actions',
  181. );
  182. foreach ($row as $cell) {
  183. $result .= _theme_table_cell($cell);
  184. }
  185. $result .= '</tr>';
  186. if (!empty($element['below'])) {
  187. $result .= '<tr' . drupal_attributes(array('class' => $element['#zebra'])) . '>';
  188. $result .= _theme_table_cell(array(
  189. 'data' => drupal_render($element['below']),
  190. 'colspan' => '4',
  191. ));
  192. $result .= '</tr>';
  193. }
  194. return $result;
  195. }
  196. /**
  197. * Renders a table containing a group of data items belonging to the same field.
  198. */
  199. function theme_tmgmt_ui_translator_review_form($variables) {
  200. $element = $variables['element'];
  201. $result = '';
  202. $labels = '';
  203. $parent_label = '';
  204. $element_groups = array();
  205. $element_group = '';
  206. foreach (element_children($element) as $key) {
  207. // Label of all element groups.
  208. $parent_label = array_shift($element[$key]['#parent_label']);
  209. $element[$key]['#top_label'] = $parent_label;
  210. $element[$key]['#leave_label'] = array_pop($element[$key]['#parent_label']);
  211. // Start a new element group.
  212. if ($labels != $element[$key]['#parent_label']) {
  213. $labels = $element[$key]['#parent_label'];
  214. if (!empty($labels)) {
  215. // Append to previous group to the group collection.
  216. if (!empty($element_group)) {
  217. $element_groups[] = '<tbody>' . $element_group . '</tbody>';
  218. }
  219. // Header row for the current element group.
  220. $cell = array(
  221. // @todo: Deal with right to left languages.
  222. 'data' => check_plain(implode(t(' > '), $labels)),
  223. 'colspan' => 4,
  224. );
  225. $element_group = '<tr>' . _theme_table_cell($cell, TRUE) . '</tr>';
  226. }
  227. }
  228. $element_group .= drupal_render($element[$key]);
  229. }
  230. // Append the last group to the group collection.
  231. $element_groups[] = '<tbody>' . $element_group . '</tbody>';
  232. // Display the label of all element groups inside a table header.
  233. if (!empty($parent_label)) {
  234. $cell = array(
  235. 'data' => $parent_label,
  236. 'colspan' => 5,
  237. );
  238. $result = '<thead><tr>' . _theme_table_cell($cell, TRUE) . '</tr></thead>' . implode('', $element_groups);
  239. }
  240. $table = '<table class="tmgmt-ui-review"><colgroup width="100" /><colgroup width="*" span="2" /><colgroup width="100" />' . $result . '</table>';
  241. return '<div id="' . $element['#ajaxid'] . '">' . $table . '</div>';
  242. }
  243. /**
  244. * Adds a description to the translator entity on the entity overview form.
  245. *
  246. * @see theme_entity_ui_overview_item()
  247. */
  248. function theme_tmgmt_ui_translator_overview_item($variables) {
  249. $output = theme('entity_ui_overview_item', $variables);
  250. if (!empty($variables['description'])) {
  251. $output = '<div class="tmgmt-ui-translator-label-wrapper">' . $output . '<div class="description">' . $variables['description'] . '</div></div>';
  252. }
  253. return $output;
  254. }
  255. /**
  256. * Theme callback for adding the tabledrag to the translator entity overview
  257. * form.
  258. */
  259. function theme_tmgmt_ui_translator_overview_form($variables) {
  260. $form = $variables['form'];
  261. $colspan = !empty($form['#entity_info']['exportable']) ? 4 : 3;
  262. $rows = array();
  263. $header = array(
  264. t('Label'),
  265. t('Plugin'),
  266. t('Configured'),
  267. t('Status'),
  268. array('data' => t('Operations'), 'colspan' => $colspan),
  269. t('Weight'),
  270. );
  271. foreach (element_children($form) as $key) {
  272. $row = array();
  273. $form[$key]['weight']['#attributes']['class'] = array('tmgmt-ui-translator-weight');
  274. $row[] = drupal_render($form[$key]['label']);
  275. $row[] = drupal_render($form[$key]['plugin']);
  276. $row[] = drupal_render($form[$key]['configured']);
  277. $row[] = drupal_render($form[$key]['status']);
  278. $operations = element_children($form[$key]['operations']);
  279. foreach ($operations as $op) {
  280. $row[] = array('data' => $form[$key]['operations'][$op]);
  281. }
  282. $row[] = drupal_render($form[$key]['weight']);
  283. $rows[] = array('data' => $row, 'class' => array('draggable'));
  284. }
  285. drupal_add_tabledrag('tmgmt-ui-translator-overview', 'order', 'sibling', 'tmgmt-ui-translator-weight');
  286. return theme('table', array('header' => $header, 'rows' => $rows, 'empty' => t('None.'), 'attributes' => array('id' => 'tmgmt-ui-translator-overview')));
  287. }