diff options
Diffstat (limited to 'sites/all/modules/media/includes/MediaEntityTranslationHandler.inc')
-rw-r--r-- | sites/all/modules/media/includes/MediaEntityTranslationHandler.inc | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/sites/all/modules/media/includes/MediaEntityTranslationHandler.inc b/sites/all/modules/media/includes/MediaEntityTranslationHandler.inc new file mode 100644 index 000000000..4e78ed18d --- /dev/null +++ b/sites/all/modules/media/includes/MediaEntityTranslationHandler.inc @@ -0,0 +1,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; + } + } + } +} |