diff --git a/config_translation.admin.inc b/config_translation.admin.inc index f25ca07..34842e8 100644 --- a/config_translation.admin.inc +++ b/config_translation.admin.inc @@ -13,54 +13,6 @@ use Drupal\config_translation\ConfigMapperInterface; use Drupal\Core\Config\Config; /** - * Main translation overview page. - * - * Presents an index of all configuration elements that can be translated. - */ -function config_translation_main_overview_page() { - $page = array(); - $header = array(t('Name'), t('Original language'), t('Operations')); - $page['translatables'] = array( - '#type' => 'table', - '#header' => $header, - '#empty' => t('No translatable configuration found.'), - ); - - $config_groups = config_translation_get_groups(); - foreach ($config_groups as $group) { - if ($group instanceof ConfigGroupMapper && $group->hasSchema() && $group->hasTranslatable()) { - // Figure out language code and name for this configuration. Shipped - // configuration might not have an explicit language code and English - // might not be present as a configured language on the site. Unless - // the configuration has an explicit language code we assume English. - // If the configuration has an explicit language code of none, then that - // is not translatable. - $langcode = $group->getLangcode(); - if ($langcode != LANGUAGE_NOT_SPECIFIED) { - $path = $group->getBasePath(); - $language = language_load($langcode); - $language_name = (empty($language) && $langcode == 'en') ? t('Built-in English') : language_name($langcode); - - $page['translatables'][$path]['label'] = array( - '#markup' => $group->getTitle(), - ); - $page['translatables'][$path]['language'] = array( - '#markup' => $language_name, - ); - // As long there is only one operation, use the link type as in - // node.admin.inc for node administration. - $page['translatables'][$path]['operations'] = array( - '#type' => 'link', - '#title' => t('Translate'), - '#href' => $path . '/translate', - ); - } - } - } - return $page; -} - -/** * Language translations overview page for a configuration name. * * @param \Drupal\config_translation\ConfigMapperInterface $mapper diff --git a/config_translation.module b/config_translation.module index e3d20b8..5c13e9b 100644 --- a/config_translation.module +++ b/config_translation.module @@ -36,9 +36,7 @@ function config_translation_menu() { $items['admin/config/regional/config-translator'] = array( 'title' => 'Configuration translation', 'description' => 'Translate configuration across modules and themes.', - 'page callback' => 'config_translation_main_overview_page', - 'access arguments' => array('translate configuration'), - 'file' => 'config_translation.admin.inc', + 'route_name' => 'config_translation_overview' ); // Generate translation tabs for keys where a specific path can be diff --git a/config_translation.routing.yml b/config_translation.routing.yml new file mode 100644 index 0000000..30fd1a1 --- /dev/null +++ b/config_translation.routing.yml @@ -0,0 +1,6 @@ +config_translation_overview: + pattern: 'admin/config/regional/config-translator' + defaults: + _content: '\Drupal\config_translation\Controller\ConfigTranslationController::overviewPage' + requirements: + _permission: 'translate configuration' diff --git a/lib/Drupal/config_translation/controller/ConfigTranslationController.php b/lib/Drupal/config_translation/controller/ConfigTranslationController.php new file mode 100644 index 0000000..25342c6 --- /dev/null +++ b/lib/Drupal/config_translation/controller/ConfigTranslationController.php @@ -0,0 +1,74 @@ +get('database')); + } + + /** + * Main translation overview page. + * + * Presents an index of all configuration elements that can be translated. + */ + public function overviewPage() { + $page = array(); + $header = array(t('Name'), t('Original language'), t('Operations')); + $page['translatables'] = array( + '#type' => 'table', + '#header' => $header, + '#empty' => t('No translatable configuration found.'), + ); + + $config_groups = config_translation_get_groups(); + foreach ($config_groups as $group) { + if ($group instanceof ConfigGroupMapper && $group->hasSchema() && $group->hasTranslatable()) { + // Figure out language code and name for this configuration. Shipped + // configuration might not have an explicit language code and English + // might not be present as a configured language on the site. Unless + // the configuration has an explicit language code we assume English. + // If the configuration has an explicit language code of none, then that + // is not translatable. + $langcode = $group->getLangcode(); + if ($langcode != LANGUAGE_NOT_SPECIFIED) { + $path = $group->getBasePath(); + $language = language_load($langcode); + $language_name = (empty($language) && $langcode == 'en') ? t('Built-in English') : language_name($langcode); + + $page['translatables'][$path]['label'] = array( + '#markup' => $group->getTitle(), + ); + $page['translatables'][$path]['language'] = array( + '#markup' => $language_name, + ); + // As long there is only one operation, use the link type as in + // node.admin.inc for node administration. + $page['translatables'][$path]['operations'] = array( + '#type' => 'link', + '#title' => t('Translate'), + '#href' => $path . '/translate', + ); + } + } + } + return $page; + } +}