Projet

Général

Profil

Paste
Télécharger (2,15 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / media / includes / MediaEntityTranslationHandler.inc @ e4215af7

1
<?php
2

    
3
/**
4
 * @file
5
 * Media translation handler for the entity translation module.
6
 */
7

    
8

    
9
/**
10
 * Media translation handler.
11
 */
12
class MediaEntityTranslationHandler extends EntityTranslationDefaultHandler {
13

    
14
  /**
15
   * Constructor function.
16
   */
17
  public function __construct($entity_type, $entity_info, $entity) {
18
    parent::__construct('file', $entity_info, $entity);
19
  }
20

    
21
  /**
22
   * Entity form handler.
23
   *
24
   * @see EntityTranslationDefaultHandler::entityForm()
25
   */
26
  public function entityForm(&$form, &$form_state) {
27
    parent::entityForm($form, $form_state);
28

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

    
33
    // The "Source language" element is unsupported on modal forms.
34
    if (!empty($form_state['ajax'])) {
35
      $form['source_language']['#access'] = FALSE;
36
    }
37

    
38
    if ($this->getPathScheme() == 'media') {
39
      $language = $GLOBALS[LANGUAGE_TYPE_CONTENT];
40
      $form_langcode = $this->getActiveLanguage();
41
      $source_langcode = $this->getSourceLanguage();
42
      $translations = $this->getTranslations();
43

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

    
61
      // Hide unsupported elements.
62
      $form['source_language']['#access'] = FALSE;
63
      if (isset($form['actions']['delete_translation'])) {
64
        $form['actions']['delete_translation']['#access'] = FALSE;
65
      }
66
    }
67
  }
68
}