summaryrefslogtreecommitdiff
path: root/sites/all/modules/media/includes/MediaEntityTranslationHandler.inc
blob: 4e78ed18db80673d3508d2e527080cc384350bd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php

/**
 * @file
 * Media translation handler for the entity translation module.
 */


/**
 * Media translation handler.
 */
class MediaEntityTranslationHandler extends EntityTranslationDefaultHandler {

  /**
   * Constructor function.
   */
  public function __construct($entity_type, $entity_info, $entity) {
    parent::__construct('file', $entity_info, $entity);
  }

  /**
   * Entity form handler.
   *
   * @see EntityTranslationDefaultHandler::entityForm()
   */
  public function entityForm(&$form, &$form_state) {
    parent::entityForm($form, $form_state);

    if (isset($form['actions']['delete_translation'])) {
      $form['actions']['delete_translation']['#weight'] = 10;
    }

    if ($this->getPathScheme() == 'media') {
      $language = $GLOBALS[LANGUAGE_TYPE_CONTENT];
      $form_langcode = $this->getFormLanguage();
      $source_langcode = $this->getSourceLanguage();
      $translations = $this->getTranslations();

      // If a translation in the current content language is missing we display
      // a link to create it, unless we are not already doing it.
      if ($language->language != $form_langcode && empty($source_langcode) && !isset($translations->data[$language->language])) {
        $link = array(
          'title' => t('Add @language translation', array('@language' => $language->name)),
          'href' => $this->getEditPath() . '/add/' . $form_langcode . '/' . $language->language,
          'localized_options' => array('attributes' => array('class' => array('ctools-use-modal'))),
        );
        $form['media_add_translation'] = array(
          '#theme' => 'menu_local_action',
          '#link' => $link,
          '#weight' => -110,
          '#prefix' => '<ul class="action-links">',
          '#suffix' => '</ul>',
        );
      }

      // Hide unsupported elements.
      $form['source_language']['#access'] = FALSE;
      if (isset($form['actions']['delete_translation'])) {
        $form['actions']['delete_translation']['#access'] = FALSE;
      }
    }
  }
}