Projet

Général

Profil

Paste
Télécharger (1,98 ko) Statistiques
| Branche: | Révision:

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

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
    if ($this->getPathScheme() == 'media') {
34
      $language = $GLOBALS[LANGUAGE_TYPE_CONTENT];
35
      $form_langcode = $this->getFormLanguage();
36
      $source_langcode = $this->getSourceLanguage();
37
      $translations = $this->getTranslations();
38

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

    
56
      // Hide unsupported elements.
57
      $form['source_language']['#access'] = FALSE;
58
      if (isset($form['actions']['delete_translation'])) {
59
        $form['actions']['delete_translation']['#access'] = FALSE;
60
      }
61
    }
62
  }
63
}