From 2b08f2ec29d1f1d0857ea87d70c71aa7249f7655 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Sat, 20 Jul 2013 21:20:48 +0100
Subject: [PATCH] Issue #1978928 by piyuesh23, InternetDevels, disasm: Convert
 locale_translation_manual_status() to a Controller.

---
 .../locale/Controller/LocaleController.php    | 72 +++++++++++++++++++
 core/modules/locale/locale.module             |  7 --
 core/modules/locale/locale.pages.inc          | 24 -------
 core/modules/locale/locale.routing.yml        |  7 ++
 4 files changed, 79 insertions(+), 31 deletions(-)
 create mode 100644 core/modules/locale/lib/Drupal/locale/Controller/LocaleController.php

diff --git a/core/modules/locale/lib/Drupal/locale/Controller/LocaleController.php b/core/modules/locale/lib/Drupal/locale/Controller/LocaleController.php
new file mode 100644
index 000000000000..7d95e3a85186
--- /dev/null
+++ b/core/modules/locale/lib/Drupal/locale/Controller/LocaleController.php
@@ -0,0 +1,72 @@
+<?php
+/**
+ * @file
+ * Contains \Drupal\locale\Controller\LocaleController.
+ */
+
+namespace Drupal\locale\Controller;
+
+use Drupal\Core\Controller\ControllerInterface;
+use Drupal\Core\Routing\PathBasedGeneratorInterface;
+use Drupal\Core\Extension\ModuleHandlerInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+use Symfony\Component\HttpFoundation\RedirectResponse;
+/**
+ * Return response for manual check translations.
+ */
+class LocaleController implements ControllerInterface {
+
+  /**
+   * The module handler.
+   *
+   * @var \Drupal\Core\Extension\ModuleHandlerInterface
+   */
+  protected $moduleHandler;
+
+  /**
+   * Constructs a \Drupal\locale\Controller\LocaleController object.
+   *
+   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
+   *   The module handler.
+   */
+  public function __construct(ModuleHandlerInterface $module_handler, PathBasedGeneratorInterface $url_generator) {
+    $this->moduleHandler = $module_handler;
+    $this->urlGenerator = $url_generator;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function create(ContainerInterface $container) {
+    return new static(
+      $container->get('module_handler'),
+      $container->get('url_generator')
+    );
+  }
+
+  /**
+   * Checks for translation updates and displays the translations status.
+   *
+   * Manually checks the translation status without the use of cron.
+   *
+   * @return \Symfony\Component\HttpFoundation\RedirectResponse
+   *   A redirection to translations reports page.
+   */
+  public function checkTranslation() {
+    $this->moduleHandler->loadInclude('locale', 'inc', 'locale.compare');
+
+    // Check translation status of all translatable project in all languages.
+    // First we clear the cached list of projects. Although not strictly
+    // nescessary, this is helpfull in case the project list is out of sync.
+    locale_translation_flush_projects();
+    locale_translation_check_projects();
+
+    // Execute a batch if required. A batch is only used when remote files
+    // are checked.
+    if (batch_get()) {
+      return batch_process('admin/reports/translations');
+    }
+
+    return new RedirectResponse($this->urlGenerator->generateFromPath('admin/reports/translations', array('absolute' => TRUE)));
+  }
+}
diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module
index 8d6ff20d4d31..932b2a1faf11 100644
--- a/core/modules/locale/locale.module
+++ b/core/modules/locale/locale.module
@@ -215,13 +215,6 @@ function locale_menu() {
     'access arguments' => array('translate interface'),
     'file' => 'locale.pages.inc',
   );
-  $items['admin/reports/translations/check'] = array(
-    'title' => 'Manual translation update check',
-    'page callback' => 'locale_translation_manual_status',
-    'access arguments' => array('translate interface'),
-    'type' => MENU_CALLBACK,
-    'file' => 'locale.pages.inc',
-  );
 
   return $items;
 }
diff --git a/core/modules/locale/locale.pages.inc b/core/modules/locale/locale.pages.inc
index 6326905c5100..83777b67c153 100644
--- a/core/modules/locale/locale.pages.inc
+++ b/core/modules/locale/locale.pages.inc
@@ -468,30 +468,6 @@ function locale_translate_edit_form_submit($form, &$form_state) {
 
 }
 
-/**
- * Page callback: Checks for translation updates and displays the translations status.
- *
- * Manually checks the translation status without the use of cron.
- *
- * @see locale_menu()
- */
-function locale_translation_manual_status() {
-  module_load_include('compare.inc', 'locale');
-
-  // Check translation status of all translatable project in all languages.
-  // First we clear the cached list of projects. Although not strictly
-  // nescessary, this is helpfull in case the project list is out of sync.
-  locale_translation_flush_projects();
-  locale_translation_check_projects();
-
-  // Execute a batch if required. A batch is only used when remote files
-  // are checked.
-  if (batch_get()) {
-    return batch_process('admin/reports/translations');
-  }
-  return new RedirectResponse(url('admin/reports/translations', array('absolute' => TRUE)));
-}
-
 /**
  * Page callback: Display the current translation status.
  *
diff --git a/core/modules/locale/locale.routing.yml b/core/modules/locale/locale.routing.yml
index a2a58209ad2d..204722944b51 100644
--- a/core/modules/locale/locale.routing.yml
+++ b/core/modules/locale/locale.routing.yml
@@ -4,3 +4,10 @@ locale_settings:
     _form: 'Drupal\locale\Form\LocaleSettingsForm'
   requirements:
     _permission: 'translate interface'
+
+locale_check_translation:
+  pattern: '/admin/reports/translations/check'
+  defaults:
+    _controller: 'Drupal\locale\Controller\LocaleController::checkTranslation'
+  requirements:
+    _permission: 'translate interface'
-- 
GitLab