diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index e4654d0..628c4fb 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -78,31 +78,33 @@ function content_translation_language_types_info_alter(array &$language_types) { function content_translation_entity_info_alter(array &$entity_info) { // Provide defaults for translation info. foreach ($entity_info as $entity_type => &$info) { - if (empty($info['translatable'])) { - continue; - } - - // Every fieldable entity type must have a translation controller class, no - // matter if it is enabled for translation or not. As a matter of fact we - // might need it to correctly switch field translatability when a field is - // shared accross different entities. - $info['controllers'] += array('translation' => 'Drupal\content_translation\ContentTranslationController'); + if (!empty($info['translatable'])) { + // Every fieldable entity type must have a translation controller class, + // no matter if it is enabled for translation or not. As a matter of fact + // we might need it to correctly switch field translatability when a field + // is shared accross different entities. + $info['controllers'] += array('translation' => 'Drupal\content_translation\ContentTranslationController'); + + if (!isset($info['translation']['content_translation'])) { + $info['translation']['content_translation'] = array(); + } - // Provide default links for the translation paths. - $info['links'] += array( - 'drupal:content-translation-overview' => $info['links']['canonical'] . '/translations', - ); + if (!empty($info['links']['canonical'])) { + // Provide default links for the translation paths. + $info['links'] += array( + 'drupal:content-translation-overview' => $info['links']['canonical'] . '/translations', + ); - if (!isset($info['translation']['content_translation'])) { - $info['translation']['content_translation'] = array(); + $parts = explode('/', trim($info['links']['canonical'], '/')); + $entity_position = array_search("{{$entity_type}}", $parts); + if ($entity_position !== FALSE) { + $info['translation']['content_translation'] += array( + 'access_callback' => 'content_translation_translate_access', + 'access_arguments' => array($entity_position), + ); + } + } } - - $path = _content_translation_link_to_router_path($entity_type, $info['links']['canonical']); - $entity_position = count(explode('/', $path)) - 1; - $info['translation']['content_translation'] += array( - 'access_callback' => 'content_translation_translate_access', - 'access_arguments' => array($entity_position), - ); } } @@ -517,7 +519,7 @@ function content_translation_enabled($entity_type, $bundle = NULL) { */ function content_translation_supported($entity_type) { $info = entity_get_info($entity_type); - return !empty($info['translatable']) && !empty($info['links']['canonical']); + return !empty($info['translatable']) && !empty($info['links']['drupal:content-translation-overview']); } /**