[TASK] Use fully qualified name resolution in PHP 5.5
[Packages/TYPO3.CMS.git] / typo3 / sysext / lang / Classes / Controller / LanguageController.php
1 <?php
2 namespace TYPO3\CMS\Lang\Controller;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Language controller handling the selection of available languages and update of extension translations
19 *
20 * @author Sebastian Fischer <typo3@evoweb.de>
21 * @author Kai Vogel <kai.vogel@speedprogs.de>
22 */
23 class LanguageController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
24
25 /**
26 * @var \TYPO3\CMS\Lang\Domain\Repository\LanguageRepository
27 * @inject
28 */
29 protected $languageRepository;
30
31 /**
32 * @var \TYPO3\CMS\Lang\Domain\Repository\ExtensionRepository
33 * @inject
34 */
35 protected $extensionRepository;
36
37 /**
38 * @var \TYPO3\CMS\Lang\Service\UpdateTranslationService
39 * @inject
40 */
41 protected $updateTranslationService;
42
43 /**
44 * JSON actions
45 * @var array
46 */
47 protected $jsonActions = array('updateTranslation');
48
49 /**
50 * Force JSON output for defined actions
51 *
52 * @param \TYPO3\CMS\Extbase\Mvc\View\ViewInterface $view The view to be initialized
53 * @return void
54 */
55 protected function initializeView(\TYPO3\CMS\Extbase\Mvc\View\ViewInterface $view) {
56 $actionName = $this->request->getControllerActionName();
57 if (in_array($actionName, $this->jsonActions)) {
58 $viewObjectName = 'TYPO3\\CMS\\Lang\\View\\Language\\' . ucfirst($actionName) . 'Json';
59 $this->view = $this->objectManager->get($viewObjectName);
60 $this->view->setControllerContext($this->controllerContext);
61 $this->view->initializeView();
62 }
63 }
64
65 /**
66 * Index action
67 *
68 * @param \TYPO3\CMS\Lang\Domain\Model\LanguageSelectionForm $languageSelectionForm
69 * @param mixed $extensions Extensions to show in form
70 * @return void
71 * @dontvalidate $languageSelectionForm
72 * @dontvalidate $extensions
73 */
74 public function indexAction(\TYPO3\CMS\Lang\Domain\Model\LanguageSelectionForm $languageSelectionForm = NULL, $extensions = NULL) {
75 if ($languageSelectionForm === NULL) {
76 $languageSelectionForm = $this->objectManager->get(\TYPO3\CMS\Lang\Domain\Model\LanguageSelectionForm::class);
77 $languageSelectionForm->setLanguages($this->languageRepository->findAll());
78 $languageSelectionForm->setSelectedLanguages($this->languageRepository->findSelected());
79 }
80
81 if (empty($extensions)) {
82 $extensions = $this->extensionRepository->findAll();
83 }
84
85 $this->view->assign('languageSelectionForm', $languageSelectionForm);
86 $this->view->assign('extensions', $extensions);
87 }
88
89 /**
90 * Update the language selection form
91 *
92 * @param \TYPO3\CMS\Lang\Domain\Model\LanguageSelectionForm $languageSelectionForm
93 * @return void
94 * @dontvalidate $languageSelectionForm
95 */
96 public function updateLanguageSelectionAction(\TYPO3\CMS\Lang\Domain\Model\LanguageSelectionForm $languageSelectionForm) {
97 if ($languageSelectionForm !== NULL) {
98 $this->languageRepository->updateSelectedLanguages($languageSelectionForm->getSelectedLanguages());
99 }
100 $this->redirect('index');
101 }
102
103 /**
104 * Update translation for one extension.
105 * The view of this action returns JSON!
106 *
107 * @param string $extension The extension key
108 * @param string $locales Comma separated list of locales to update
109 * @return void
110 */
111 public function updateTranslationAction($extension, $locales) {
112 $locales = $this->updateTranslationService->updateTranslation($extension, $locales);
113 $this->view->assign('extension', $extension);
114 $this->view->assign('locales', $locales);
115 }
116
117 }