translation.handler.node.inc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /**
  3. * @file
  4. * Node translation handler for the entity translation module.
  5. */
  6. /**
  7. * Node translation handler.
  8. *
  9. * Overrides default behaviours for Node properties.
  10. */
  11. class EntityTranslationNodeHandler extends EntityTranslationDefaultHandler {
  12. public function __construct($entity_type, $entity_info, $entity) {
  13. parent::__construct('node', $entity_info, $entity);
  14. }
  15. /**
  16. * @see EntityTranslationDefaultHandler::isRevision()
  17. */
  18. public function isRevision() {
  19. return !empty($this->entity->revision);
  20. }
  21. /**
  22. * @see EntityTranslationDefaultHandler::getAccess()
  23. */
  24. public function getAccess($op) {
  25. return node_access($op, $this->entity);
  26. }
  27. /**
  28. * @see EntityTranslationDefaultHandler::getTranslationAccess()
  29. */
  30. public function getTranslationAccess($langcode) {
  31. return user_access('bypass node access') || parent::getTranslationAccess($langcode);
  32. }
  33. /**
  34. * Convert the translation update status fieldset into a vartical tab.
  35. */
  36. public function entityForm(&$form, &$form_state) {
  37. parent::entityForm($form, $form_state);
  38. // Move the translation fieldset to a vertical tab.
  39. if (isset($form['translation'])) {
  40. $form['translation'] += array(
  41. '#group' => 'additional_settings',
  42. '#weight' => 100,
  43. '#attached' => array(
  44. 'js' => array(drupal_get_path('module', 'entity_translation') . '/entity_translation.node-form.js'),
  45. ),
  46. );
  47. if (!$this->isTranslationForm()) {
  48. $form['translation']['name']['#access'] = FALSE;
  49. $form['translation']['created']['#access'] = FALSE;
  50. }
  51. }
  52. // Path aliases natively support multilingual values.
  53. if (isset($form['path'])) {
  54. $form['path']['#multilingual'] = TRUE;
  55. }
  56. }
  57. /**
  58. * @see EntityTranslationDefaultHandler::menuForm()
  59. */
  60. protected function menuForm(&$form, &$form_state) {
  61. entity_translation_i18n_menu_form($form, $form_state);
  62. }
  63. /**
  64. * @see EntityTranslationDefaultHandler::entityFormLanguageWidgetSubmit()
  65. */
  66. function entityFormLanguageWidgetSubmit($form, &$form_state) {
  67. $this->updateFormLanguage($form_state);
  68. }
  69. /**
  70. * @see EntityTranslationDefaultHandler::entityFormSubmit()
  71. */
  72. public function entityFormSubmit($form, &$form_state) {
  73. if (!isset($form_state['values']['translation'])) {
  74. // Always publish the original values when we have no translations.
  75. $form_state['values']['translation'] = array('status' => TRUE);
  76. }
  77. $values = &$form_state['values']['translation'];
  78. if (!$this->isTranslationForm()) {
  79. // Inherit entity authoring information for the original values.
  80. if (isset($form_state['values']['name'])) {
  81. $values['name'] = $form_state['values']['name'];
  82. }
  83. if (!empty($form_state['values']['date'])) {
  84. $values['created'] = $form_state['values']['date'];
  85. }
  86. }
  87. parent::entityFormSubmit($form, $form_state);
  88. }
  89. /**
  90. * @see EntityTranslationDefaultHandler::entityFormTitle()
  91. */
  92. protected function entityFormTitle() {
  93. $type_name = node_type_get_name($this->entity);
  94. return t('<em>Edit @type</em> @title', array('@type' => $type_name, '@title' => $this->getLabel()));
  95. }
  96. /**
  97. * @see EntityTranslationDefaultHandler::getStatus()
  98. */
  99. protected function getStatus() {
  100. return (boolean) $this->entity->status;
  101. }
  102. }