i18n_translation.admin.inc 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * @file
  4. * Internationalization (i18n) module. Translation sets admin
  5. */
  6. /**
  7. * Overview page for translation sets
  8. *
  9. * @param $type
  10. * Translation set type to get a listing for this type only
  11. * @param $query
  12. * Base query to build upon
  13. */
  14. function i18n_translation_admin_overview($type = NULL, $query = NULL) {
  15. // Build the sortable table header.
  16. $header['title'] = array('data' => t('Title'), 'field' => 't.title');
  17. if (!$type) {
  18. $header['type'] = array('data' => t('Type'), 'field' => 't.type');
  19. }
  20. $header['items'] = t('Items');
  21. $header['created'] = array('data' => t('Created'), 'field' => 't.created');
  22. $header['changed'] = array('data' => t('Updated'), 'field' => 't.changed', 'sort' => 'desc');
  23. $header['operations'] = array('data' => t('Operations'));
  24. // Get the translation sets for this form
  25. $query = $query ? $query : db_select('i18n_translation_set', 't');
  26. $query = $query->extend('PagerDefault')->extend('TableSort');
  27. if ($type) {
  28. $query->condition('t.type', $type);
  29. }
  30. $tsids = $query
  31. ->fields('t', array('tsid'))
  32. ->limit(20)
  33. ->orderByHeader($header)
  34. ->execute()
  35. ->fetchCol();
  36. $translations = $tsids ? entity_load('i18n_translation', $tsids) : array();
  37. $form = drupal_get_form('i18n_translation_admin_form', $translations, $header);
  38. $form['pager'] = array('#markup' => theme('pager'));
  39. return $form;
  40. }
  41. /**
  42. * Admin form
  43. */
  44. function i18n_translation_admin_form($form, &$form_state, $translations, $header) {
  45. $destination = drupal_get_destination();
  46. $rows = array();
  47. foreach ($translations as $set) {
  48. $info = i18n_object_info($set->type);
  49. $rows[$set->tsid]['title'] = check_plain($set->get_title());
  50. if (isset($header['type'])) {
  51. $rows[$set->tsid]['type'] = isset($info['title']) ? $info['title'] : t('Unknown');
  52. }
  53. $rows[$set->tsid]['items'] = ($items = $set->get_links()) ? theme('links', array('links' => $items)) : '';
  54. $rows[$set->tsid] += array(
  55. 'created' => format_date($set->created, 'short'),
  56. 'changed' => format_date($set->changed, 'short'),
  57. 'operations' => '',
  58. );
  59. // Build a list of all the accessible operations for the current set.
  60. $operations = $set->get_operations();
  61. if (count($operations) > 1) {
  62. // Render an unordered list of operations links.
  63. $rows[$set->tsid]['operations'] = array(
  64. 'data' => array(
  65. '#theme' => 'links__node_operations',
  66. '#links' => $operations,
  67. '#attributes' => array('class' => array('links', 'inline')),
  68. ),
  69. );
  70. }
  71. elseif (!empty($operations)) {
  72. // Render the first and only operation as a link.
  73. $link = reset($operations);
  74. $rows[$set->tsid]['operations'] = array(
  75. 'data' => array(
  76. '#type' => 'link',
  77. '#title' => $link['title'],
  78. '#href' => $link['href'],
  79. '#options' => array('query' => $link['query']),
  80. ),
  81. );
  82. }
  83. }
  84. $form['translations'] = array(
  85. '#theme' => 'table',
  86. '#header' => $header,
  87. '#rows' => $rows,
  88. '#empty' => t('No translation sets available.'),
  89. );
  90. return $form;
  91. }