[TASK] Add functional tests for rendering translated tt_content with FAL
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Functional / Fixtures / Extensions / blog_example / Classes / Controller / ContentController.php
1 <?php
2 declare(strict_types=1);
3
4 namespace ExtbaseTeam\BlogExample\Controller;
5
6 /*
7 * This file is part of the TYPO3 CMS project.
8 *
9 * It is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, either version 2
11 * of the License, or any later version.
12 *
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
15 *
16 * The TYPO3 project - inspiring people to share!
17 */
18
19 /**
20 * ContentController
21 */
22 class ContentController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
23 {
24 /**
25 * @inject
26 * @var \ExtbaseTeam\BlogExample\Domain\Repository\TtContentRepository
27 */
28 protected $contentRepository;
29
30 /**
31 * @var string
32 */
33 protected $defaultViewObjectName = \TYPO3\CMS\Extbase\Mvc\View\JsonView::class;
34
35 /**
36 * @inject
37 * @var \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory
38 */
39 protected $dataMapFactory;
40
41 /**
42 * @return array
43 */
44 public function listAction()
45 {
46 $content = $this->contentRepository->findAll();
47 $value[$this->getRuntimeIdentifier()] = $this->getStructure($content);
48 // this is required so we don't try to json_encode content of the image
49 $this->view->setConfiguration(['value' => [
50 '_descendAll' => [
51 '_descendAll' => [
52 '_descendAll' => [
53 '_descendAll' => [
54 '_descendAll' => [
55 '_exclude' => ['contents']
56 ]
57 ]
58 ]
59 ]
60 ]
61 ]]);
62 $this->view->assign('value', $value);
63 }
64
65 /**
66 * @param \TYPO3\CMS\Extbase\Mvc\RequestInterface $request
67 * @param \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response
68 * @throws \RuntimeException
69 */
70 public function processRequest(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request, \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response)
71 {
72 try {
73 parent::processRequest($request, $response);
74 } catch (\TYPO3\CMS\Extbase\Property\Exception $exception) {
75 throw new \RuntimeException(
76 $this->getRuntimeIdentifier() . ': ' . $exception->getMessage() . ' (' . $exception->getCode() . ')',
77 1476122223
78 );
79 }
80 }
81
82 /**
83 * @param \Iterator|\TYPO3\CMS\Extbase\DomainObject\AbstractEntity[] $iterator
84 * @return array
85 */
86 protected function getStructure($iterator)
87 {
88 $structure = [];
89
90 if (!$iterator instanceof \Iterator) {
91 $iterator = [$iterator];
92 }
93
94 foreach ($iterator as $entity) {
95 $dataMap = $this->dataMapFactory->buildDataMap(get_class($entity));
96 $tableName = $dataMap->getTableName();
97 $identifier = $tableName . ':' . $entity->getUid();
98 $properties = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getGettableProperties($entity);
99
100 $structureItem = [];
101 foreach ($properties as $propertyName => $propertyValue) {
102 $columnMap = $dataMap->getColumnMap($propertyName);
103 if ($columnMap !== null) {
104 $propertyName = $columnMap->getColumnName();
105 }
106 if ($propertyValue instanceof \Iterator) {
107 $structureItem[$propertyName] = $this->getStructure($propertyValue);
108 } else {
109 $structureItem[$propertyName] = $propertyValue;
110 }
111 }
112 $structure[$identifier] = $structureItem;
113 }
114
115 return $structure;
116 }
117
118 /**
119 * @return string
120 */
121 protected function getRuntimeIdentifier()
122 {
123 $arguments = [];
124 foreach ($this->request->getArguments() as $argumentName => $argumentValue) {
125 $arguments[] = $argumentName . '=' . $argumentValue;
126 }
127 return $this->request->getControllerActionName() . '(' . implode(', ', $arguments) . ')';
128 }
129 }