diff --git a/core/modules/translation_entity/lib/Drupal/translation_entity/EntityTranslationOverviewController.php b/core/modules/translation_entity/lib/Drupal/translation_entity/EntityTranslationOverviewController.php
new file mode 100644
index 0000000..3257744
--- /dev/null
+++ b/core/modules/translation_entity/lib/Drupal/translation_entity/EntityTranslationOverviewController.php
@@ -0,0 +1,230 @@
+manager = $manager;
+ $this->moduleHandler = $module_handler;
+ }
+
+ /**
+ * {inheritdoc}
+ */
+ public static function create(ContainerInterface $container) {
+ return new static(
+ $container->get('plugin.manager.entity'),
+ $container->get('module_handler')
+ );
+ }
+
+ /**
+ * @param EntityInterface $entity
+ */
+ public function translationEntityOverview(EntityInterface $entity) {
+ $this->moduleHandler->loadInclude('translation_entity', 'inc', 'translation_entity.pages');
+
+ $controller = translation_entity_controller($entity->entityType());
+ $entity_manager = $this->manager;
+ $languages = language_list();
+ $original = $entity->language()->langcode;
+ $translations = $entity->getTranslationLanguages();
+ $field_ui = module_exists('field_ui') && user_access('administer ' . $entity->entityType() . ' fields');
+
+ $path = $controller->getViewPath($entity);
+ $base_path = $controller->getBasePath($entity);
+ $edit_path = $controller->getEditPath($entity);
+
+ $header = array(
+ t('Language'),
+ t('Translation'),
+ t('Source language'),
+ t('Status'),
+ t('Operations'),
+ );
+ $rows = array();
+
+ if (language_multilingual()) {
+ // If we have a view path defined for the current entity get the switch
+ // links based on it.
+ if ($path) {
+ $links = _translation_entity_get_switch_links($path);
+ }
+
+ // Determine whether the current entity is translatable.
+ $translatable = FALSE;
+ foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) {
+ $field_name = $instance['field_name'];
+ $field = field_info_field($field_name);
+ if ($field['translatable']) {
+ $translatable = TRUE;
+ break;
+ }
+ }
+
+ foreach ($languages as $language) {
+ $language_name = $language->name;
+ $langcode = $language->langcode;
+ $add_path = $base_path . '/translations/add/' . $original . '/' . $langcode;
+ $translate_path = $base_path . '/translations/edit/' . $langcode;
+ $delete_path = $base_path . '/translations/delete/' . $langcode;
+
+ if ($base_path) {
+ $add_links = _translation_entity_get_switch_links($add_path);
+ $edit_links = _translation_entity_get_switch_links($edit_path);
+ $translate_links = _translation_entity_get_switch_links($translate_path);
+ $delete_links = _translation_entity_get_switch_links($delete_path);
+ }
+
+ $operations = array(
+ 'data' => array(
+ '#type' => 'operations',
+ '#links' => array(),
+ ),
+ );
+ $links = &$operations['data']['#links'];
+
+ if (isset($translations[$langcode])) {
+ // Existing translation in the translation set: display status.
+ $source = isset($entity->translation[$langcode]['source']) ? $entity->translation[$langcode]['source'] : '';
+ $is_original = $langcode == $original;
+ $translation = $translations[$langcode];
+ $label = $entity->label($langcode);
+ $link = isset($links->links[$langcode]['href']) ? $links->links[$langcode] : array(
+ 'href' => $path,
+ 'language' => $language,
+ );
+ $row_title = l($label, $link['href'], $link);
+
+ if (empty($link['href'])) {
+ $row_title = $is_original ? $label : t('n/a');
+ }
+
+ // If the user is allowed to edit the entity we point the edit link to
+ // the entity form, otherwise if we are not dealing with the original
+ // language we point the link to the translation form.
+ if ($edit_path && $controller->getAccess($entity, 'update')) {
+ $links['edit'] = isset($edit_links->links[$langcode]['href']) ? $edit_links->links[$langcode] : array(
+ 'href' => $edit_path,
+ 'language' => $language,
+ );
+ }
+ elseif (!$is_original && $controller->getTranslationAccess($entity, 'update')) {
+ $links['edit'] = isset($translate_links->links[$langcode]['href']) ? $translate_links->links[$langcode] : array(
+ 'href' => $translate_path,
+ 'language' => $language,
+ );
+ }
+
+ if (isset($links['edit'])) {
+ $links['edit']['title'] = t('Edit');
+ }
+
+ $translation = $entity->translation[$langcode];
+ $status = !empty($translation['status']) ? t('Published') : t('Not published');
+ // @todo Add a theming function here.
+ $status = '' . $status . '' . (!empty($translation['outdated']) ? ' ' . t('outdated') . '' : '');
+
+ if ($is_original) {
+ $language_name = t('@language_name (Original language)', array('@language_name' => $language_name));
+ $source_name = t('n/a');
+ }
+ else {
+ $source_name = isset($languages[$source]) ? $languages[$source]->name : t('n/a');
+ if ($controller->getTranslationAccess($entity, 'delete')) {
+ $links['delete'] = isset($delete_links->links[$langcode]['href']) ? $delete_links->links[$langcode] : array(
+ 'href' => $delete_links,
+ 'language' => $language,
+ );
+ $links['delete']['title'] = t('Delete');
+ }
+ }
+ }
+ else {
+ // No such translation in the set yet: help user to create it.
+ $row_title = $source_name = t('n/a');
+ $source = $entity->language()->langcode;
+
+ if ($source != $langcode && $controller->getTranslationAccess($entity, 'create')) {
+ if ($translatable) {
+ $links['add'] = isset($add_links->links[$langcode]['href']) ? $add_links->links[$langcode] : array(
+ 'href' => $add_path,
+ 'language' => $language,
+ );
+ $links['add']['title'] = t('Add');
+ }
+ elseif ($field_ui) {
+ $entity_path = $entity_manager->getAdminPath($entity->entityType(), $entity->bundle());
+ // Link directly to the fields tab to make it easier to find the
+ // setting to enable translation on fields.
+ $path = $entity_path . '/fields';
+ $links['nofields'] = array(
+ 'title' => t('No translatable fields'),
+ 'href' => $path,
+ 'language' => $language,
+ );
+ }
+ }
+
+ $status = t('Not translated');
+ }
+
+ $rows[] = array(
+ $language_name,
+ $row_title,
+ $source_name,
+ $status,
+ $operations,
+ );
+ }
+ }
+
+ drupal_set_title(t('Translations of %label', array('%label' => $entity->label())), PASS_THROUGH);
+
+ // Add metadata to the build render array to let other modules know about
+ // which entity this is.
+ $build['#entity'] = $entity;
+
+ $build['translation_entity_overview'] = array(
+ '#theme' => 'table',
+ '#header' => $header,
+ '#rows' => $rows,
+ );
+
+ return $build;
+
+ }
+}
diff --git a/core/modules/translation_entity/lib/Drupal/translation_entity/Routing/RouteSubscriber.php b/core/modules/translation_entity/lib/Drupal/translation_entity/Routing/RouteSubscriber.php
new file mode 100644
index 0000000..5e9d4db
--- /dev/null
+++ b/core/modules/translation_entity/lib/Drupal/translation_entity/Routing/RouteSubscriber.php
@@ -0,0 +1,64 @@
+manager = $manager;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getSubscribedEvents() {
+ $events[RoutingEvents::DYNAMIC] = 'routes';
+ return $events;
+ }
+
+ /**
+ * Adds routes for entity translations.
+ */
+ public function routes(RouteBuildEvent $event) {
+ $collection = $event->getRouteCollection();
+ foreach ($this->manager->getDefinitions() as $entity_type => $entity_info) {
+ if ($entity_info['translatable'] && isset($entity_info['translation'])) {
+ $route = new Route(
+ $entity_type . "/{entity}/translations",
+ array('_content' => '\Drupal\translation_entity\EntityTranslationOverviewController::translationEntityOverview'),
+ array('_permission' => 'translate ' . $entity_type),
+ array('converters' => array('entity' => $entity_type))
+ );
+
+ $collection->add("translation_entity.translation_display.$entity_type", $route);
+ }
+ }
+ }
+}
diff --git a/core/modules/translation_entity/translation_entity.module b/core/modules/translation_entity/translation_entity.module
index f51c2cb..e74f285 100644
--- a/core/modules/translation_entity/translation_entity.module
+++ b/core/modules/translation_entity/translation_entity.module
@@ -147,12 +147,10 @@ function translation_entity_menu() {
$items["$path/translations"] = array(
'title' => 'Translations',
- 'page callback' => 'translation_entity_overview',
- 'page arguments' => array($entity_position),
'type' => MENU_LOCAL_TASK,
- 'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
'weight' => 2,
- ) + $item;
+ 'route_name' => "translation_entity.translation_display.$entity_type",
+ );
$items["$path/translations/overview"] = array(
'title' => 'Overview',
diff --git a/core/modules/translation_entity/translation_entity.pages.inc b/core/modules/translation_entity/translation_entity.pages.inc
index c7de9e2..b90ab57 100644
--- a/core/modules/translation_entity/translation_entity.pages.inc
+++ b/core/modules/translation_entity/translation_entity.pages.inc
@@ -10,152 +10,6 @@
use Drupal\Core\Entity\EntityNG;
/**
- * Translations overview page callback.
- *
- * @param \Drupal\Core\Entity\EntityInterface $entity
- * The entity whose translation overview should be displayed.
- */
-function translation_entity_overview(EntityInterface $entity) {
- $controller = translation_entity_controller($entity->entityType());
- $entity_manager = Drupal::entityManager();
- $languages = language_list();
- $original = $entity->language()->langcode;
- $translations = $entity->getTranslationLanguages();
- $field_ui = module_exists('field_ui') && user_access('administer ' . $entity->entityType() . ' fields');
-
- $path = $controller->getViewPath($entity);
- $base_path = $controller->getBasePath($entity);
- $edit_path = $controller->getEditPath($entity);
-
- $header = array(t('Language'), t('Translation'), t('Source language'), t('Status'), t('Operations'));
- $rows = array();
-
- if (language_multilingual()) {
- // If we have a view path defined for the current entity get the switch
- // links based on it.
- if ($path) {
- $links = _translation_entity_get_switch_links($path);
- }
-
- // Determine whether the current entity is translatable.
- $translatable = FALSE;
- foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) {
- $field_name = $instance['field_name'];
- $field = field_info_field($field_name);
- if ($field['translatable']) {
- $translatable = TRUE;
- break;
- }
- }
-
- foreach ($languages as $language) {
- $language_name = $language->name;
- $langcode = $language->langcode;
- $add_path = $base_path . '/translations/add/' . $original . '/' . $langcode;
- $translate_path = $base_path . '/translations/edit/' . $langcode;
- $delete_path = $base_path . '/translations/delete/' . $langcode;
-
- if ($base_path) {
- $add_links = _translation_entity_get_switch_links($add_path);
- $edit_links = _translation_entity_get_switch_links($edit_path);
- $translate_links = _translation_entity_get_switch_links($translate_path);
- $delete_links = _translation_entity_get_switch_links($delete_path);
- }
-
- $operations = array(
- 'data' => array(
- '#type' => 'operations',
- '#links' => array(),
- ),
- );
- $links = &$operations['data']['#links'];
-
- if (isset($translations[$langcode])) {
- // Existing translation in the translation set: display status.
- $source = isset($entity->translation[$langcode]['source']) ? $entity->translation[$langcode]['source'] : '';
- $is_original = $langcode == $original;
- $translation = $translations[$langcode];
- $label = $entity->label($langcode);
- $link = isset($links->links[$langcode]['href']) ? $links->links[$langcode] : array('href' => $path, 'language' => $language);
- $row_title = l($label, $link['href'], $link);
-
- if (empty($link['href'])) {
- $row_title = $is_original ? $label : t('n/a');
- }
-
- // If the user is allowed to edit the entity we point the edit link to
- // the entity form, otherwise if we are not dealing with the original
- // language we point the link to the translation form.
- if ($edit_path && $controller->getAccess($entity, 'update')) {
- $links['edit'] = isset($edit_links->links[$langcode]['href']) ? $edit_links->links[$langcode] : array('href' => $edit_path, 'language' => $language);
- }
- elseif (!$is_original && $controller->getTranslationAccess($entity, 'update')) {
- $links['edit'] = isset($translate_links->links[$langcode]['href']) ? $translate_links->links[$langcode] : array('href' => $translate_path, 'language' => $language);
- }
-
- if (isset($links['edit'])) {
- $links['edit']['title'] = t('Edit');
- }
-
- $translation = $entity->translation[$langcode];
- $status = !empty($translation['status']) ? t('Published') : t('Not published');
- // @todo Add a theming function here.
- $status = '' . $status . '' . (!empty($translation['outdated']) ? ' ' . t('outdated') . '' : '');
-
- if ($is_original) {
- $language_name = t('@language_name (Original language)', array('@language_name' => $language_name));
- $source_name = t('n/a');
- }
- else {
- $source_name = isset($languages[$source]) ? $languages[$source]->name : t('n/a');
- if ($controller->getTranslationAccess($entity, 'delete')) {
- $links['delete'] = isset($delete_links->links[$langcode]['href']) ? $delete_links->links[$langcode] : array('href' => $delete_links, 'language' => $language);
- $links['delete']['title'] = t('Delete');
- }
- }
- }
- else {
- // No such translation in the set yet: help user to create it.
- $row_title = $source_name = t('n/a');
- $source = $entity->language()->langcode;
-
- if ($source != $langcode && $controller->getTranslationAccess($entity, 'create')) {
- if ($translatable) {
- $links['add'] = isset($add_links->links[$langcode]['href']) ? $add_links->links[$langcode] : array('href' => $add_path, 'language' => $language);
- $links['add']['title'] = t('Add');
- }
- elseif ($field_ui) {
- $entity_path = $entity_manager->getAdminPath($entity->entityType(), $entity->bundle());
- // Link directly to the fields tab to make it easier to find the
- // setting to enable translation on fields.
- $path = $entity_path . '/fields';
- $links['nofields'] = array('title' => t('No translatable fields'), 'href' => $path, 'language' => $language);
- }
- }
-
- $status = t('Not translated');
- }
-
- $rows[] = array($language_name, $row_title, $source_name, $status, $operations);
- }
- }
-
- drupal_set_title(t('Translations of %label', array('%label' => $entity->label())), PASS_THROUGH);
-
- // Add metadata to the build render array to let other modules know about
- // which entity this is.
- $build['#entity'] = $entity;
-
- $build['translation_entity_overview'] = array(
- '#theme' => 'table',
- '#header' => $header,
- '#rows' => $rows,
- );
-
- return $build;
-}
-
-/**
* Returns the localized links for the given path.
*
* @param string $path
diff --git a/core/modules/translation_entity/translation_entity.services.yml b/core/modules/translation_entity/translation_entity.services.yml
index 541bd3d..36aa969 100644
--- a/core/modules/translation_entity/translation_entity.services.yml
+++ b/core/modules/translation_entity/translation_entity.services.yml
@@ -2,3 +2,8 @@ services:
translation_entity.synchronizer:
class: Drupal\translation_entity\FieldTranslationSynchronizer
arguments: ['@plugin.manager.entity']
+ translation_entity.subscriber:
+ class: Drupal\translation_entity\Routing\RouteSubscriber
+ arguments: ['@plugin.manager.entity']
+ tags:
+ - { name: event_subscriber }