Commit f3e05989 authored by joseph.olstad's avatar joseph.olstad Committed by olstjos

Issue #2855151 by joseph.olstad, czigor, plach: Update Entity translation API usage in Media

parent c6af0cbd
......@@ -37,7 +37,7 @@ class MediaEntityTranslationHandler extends EntityTranslationDefaultHandler {
if ($this->getPathScheme() == 'media') {
$language = $GLOBALS[LANGUAGE_TYPE_CONTENT];
$form_langcode = $this->getFormLanguage();
$form_langcode = $this->getActiveLanguage();
$source_langcode = $this->getSourceLanguage();
$translations = $this->getTranslations();
......
......@@ -126,7 +126,7 @@ function media_field_widget_form(&$form, &$form_state, $field, $instance, $langc
// on the elements for further usage in media_element_process().
if (module_invoke('entity_translation', 'enabled', $element['#entity_type'], $element['#entity'])) {
$translation_handler = entity_translation_get_handler($element['#entity_type'], $element['#entity']);
$element['#media_parent_entity_form_langcode'] = $translation_handler->getFormLanguage();
$element['#media_parent_entity_form_langcode'] = $translation_handler->getActiveLanguage();
if ($source_langcode = $translation_handler->getSourceLanguage()) {
$element['#media_parent_entity_source_langcode'] = $source_langcode;
}
......
......@@ -19,7 +19,7 @@ function media_file_edit_modal($form, &$form_state, $file, $js) {
if (isset($languages[$_GET['media_parent_entity_form_langcode']])) {
$langcode = $_GET['media_parent_entity_form_langcode'];
$translation_handler = entity_translation_get_handler('file', $file);
$translation_handler->setFormLanguage($langcode);
$translation_handler->setActiveLanguage($langcode);
$translations = $translation_handler->getTranslations();
if (!isset($translations->data[$langcode])) {
if (!empty($_GET['media_parent_entity_source_langcode']) && is_string($_GET['media_parent_entity_source_langcode']) && isset($translations->data[$_GET['media_parent_entity_source_langcode']])) {
......
......@@ -122,6 +122,26 @@ function media_requirements($phase) {
}
}
if (module_exists('entity_translation')) {
if ($phase == 'update' || $phase == 'install' || $phase == 'runtime' ) {
$entity_translation_info = system_get_info('module', 'entity_translation');
$et_installed_version = $entity_translation_info['version'];
$et_installed_datestamp = $entity_translation_info['datestamp'];
$march3rd_entity_translation_timestamp = 1488530885;
if (!isset($entity_translation_info['version']) || !isset($entity_translation_info['datestamp'])) {
$et_installed_datestamp = 1488530884;
}
if ($et_installed_datestamp < $march3rd_entity_translation_timestamp) {
$description = $t('Your entity_translation installation version: %version is too old. media requires entity_translation at least beta6 from march 3 2017 or newer. Your choice is to either upgrade entity_translation or to disable it.', array('%version' => $et_installed_version));
$requirements['entity_translation']['description'] = $description;
$requirements['entity_translation']['severity'] = REQUIREMENT_ERROR;
$requirements['entity_translation']['value'] = $et_installed_version;
$requirements['entity_translation']['title'] = $t('Entity translation (when installed) with Media');
drupal_set_message($description, 'error', TRUE);
}
}
}
return $requirements;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment