entity_translation.taxonomy.inc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * @file
  4. * The taxonomy specific translation functions and hook implementations.
  5. */
  6. /**
  7. * Returns whether the given taxonomy vocabulary has support for translations.
  8. *
  9. * @return bool
  10. * TRUE if translation is enabled, FALSE otherwise.
  11. */
  12. function entity_translation_taxonomy_term_enabled_vocabulary($vocabulary_name) {
  13. $info = variable_get('entity_translation_taxonomy', array());
  14. return !empty($info[$vocabulary_name]);
  15. }
  16. /**
  17. * Taxonomy-term-specific menu alterations.
  18. */
  19. function entity_translation_taxonomy_term_menu_alter(&$items, $backup) {
  20. if (isset($backup['taxonomy_term'])) {
  21. $item = $backup['taxonomy_term'];
  22. // Preserve the menu router item defined by other modules.
  23. $callback['page callback'] = $item['page callback'];
  24. $callback['file'] = $item['file'];
  25. $callback['module'] = $item['module'];
  26. $access_arguments = array_merge(array(2, $item['access callback']), $item['access arguments']);
  27. $page_arguments = array_merge(array('taxonomy_term', 2, $callback), $item['page arguments']);
  28. }
  29. else {
  30. $access_arguments = array(2);
  31. $page_arguments = array('taxonomy_term', 2);
  32. }
  33. $items['taxonomy/term/%taxonomy_term/translate']['page callback'] = 'entity_translation_overview';
  34. $items['taxonomy/term/%taxonomy_term/translate']['page arguments'] = $page_arguments;
  35. $items['taxonomy/term/%taxonomy_term/translate']['access arguments'] = $access_arguments;
  36. $items['taxonomy/term/%taxonomy_term/translate']['access callback'] = 'entity_translation_taxonomy_term_tab_access';
  37. $items['taxonomy/term/%taxonomy_term/translate']['file'] = 'entity_translation.admin.inc';
  38. $items['taxonomy/term/%taxonomy_term/translate']['module'] = 'entity_translation';
  39. }
  40. /**
  41. * Taxonomy term specific access callback.
  42. */
  43. function entity_translation_taxonomy_term_tab_access() {
  44. $args = func_get_args();
  45. $term = array_shift($args);
  46. if (entity_translation_enabled('taxonomy_term', $term)) {
  47. return entity_translation_tab_access('taxonomy_term', $term);
  48. }
  49. else {
  50. $function = array_shift($args);
  51. return $function ? call_user_func_array($function, $args) : FALSE;
  52. }
  53. }
  54. /**
  55. * Implements hook_form_FORM_ID_alter()
  56. */
  57. function entity_translation_form_taxonomy_form_vocabulary_alter(&$form, &$form_state) {
  58. if (entity_translation_enabled('taxonomy_term')) {
  59. $name = $form_state['vocabulary']->machine_name;
  60. if (isset($form['i18n_translation']['i18n_mode'])) {
  61. $args = array('!url' => url('admin/config/regional/entity_translation'));
  62. $form['i18n_translation']['i18n_mode']['#options'][I18N_MODE_ENTITY_TRANSLATION] = t('Field translation. Term fields will be translated through the <a href="!url">Entity translation</a> module.', $args);
  63. if (entity_translation_enabled_bundle('taxonomy_term', $name)) {
  64. $form['i18n_translation']['i18n_mode']['#default_value'] = I18N_MODE_ENTITY_TRANSLATION;
  65. }
  66. }
  67. else {
  68. $form['entity_translation_taxonomy'] = array(
  69. '#title' => t('Enable field translation'),
  70. '#type' => 'checkbox',
  71. '#prefix' => '<label>' . t('Translation') . '</label>',
  72. '#default_value' => entity_translation_enabled('taxonomy_term', $name),
  73. );
  74. }
  75. $form['#submit'][] = 'entity_translation_form_taxonomy_form_vocabulary_submit';
  76. }
  77. }
  78. /**
  79. * Submit handler for the taxonomy vocabulary form.
  80. */
  81. function entity_translation_form_taxonomy_form_vocabulary_submit($form, &$form_state) {
  82. if (!empty($form_state['values']['i18n_mode']) && $form_state['values']['i18n_mode'] == I18N_MODE_ENTITY_TRANSLATION) {
  83. $form_state['values']['entity_translation_taxonomy'] = TRUE;
  84. }
  85. $info = variable_get('entity_translation_taxonomy', array());
  86. $info[$form_state['vocabulary']->machine_name] = !empty($form_state['values']['entity_translation_taxonomy']);
  87. variable_set('entity_translation_taxonomy', $info);
  88. }