‪TYPO3CMS  10.4
ContentController.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
28 
33 {
38  protected ‪$contentRepository;
39 
43  protected ‪$defaultViewObjectName = JsonView::class;
44 
49  protected ‪$dataMapFactory;
50 
54  public function ‪listAction()
55  {
56  $content = $this->contentRepository->findAll();
57  $value = [];
58  $value[$this->‪getRuntimeIdentifier()] = $this->‪getStructure($content);
59  // this is required so we don't try to json_encode content of the image
60  $this->view->setConfiguration(['value' => [
61  '_descendAll' => [
62  '_descendAll' => [
63  '_descendAll' => [
64  '_descendAll' => [
65  '_descendAll' => [
66  '_exclude' => ['contents']
67  ]
68  ]
69  ]
70  ]
71  ]
72  ]]);
73  $this->view->assign('value', $value);
74  }
75 
82  {
83  try {
84  parent::processRequest(‪$request, ‪$response);
85  } catch (‪Exception $exception) {
86  throw new \RuntimeException(
87  $this->‪getRuntimeIdentifier() . ': ' . $exception->getMessage() . ' (' . $exception->getCode() . ')',
88  1476122223
89  );
90  }
91  }
92 
97  protected function ‪getStructure($iterator)
98  {
99  $structure = [];
100 
101  if (!$iterator instanceof \Iterator) {
102  $iterator = [$iterator];
103  }
104 
105  foreach ($iterator as $entity) {
106  $dataMap = $this->dataMapFactory->buildDataMap(get_class($entity));
107  $tableName = $dataMap->getTableName();
108  $identifier = $tableName . ':' . $entity->getUid();
109  $properties = ‪ObjectAccess::getGettableProperties($entity);
110 
111  $structureItem = [];
112  foreach ($properties as $propertyName => $propertyValue) {
113  $columnMap = $dataMap->getColumnMap($propertyName);
114  if ($columnMap !== null) {
115  $propertyName = $columnMap->getColumnName();
116  }
117  if ($propertyValue instanceof \Iterator) {
118  $structureItem[$propertyName] = $this->‪getStructure($propertyValue);
119  } else {
120  $structureItem[$propertyName] = $propertyValue;
121  }
122  }
123  //let's flatten the structure and put file reference properties level up, so we can use StructureHasRecordConstraint
124  if ($entity instanceof ‪FileReference
125  && isset($structureItem['originalResource'])
126  && $structureItem['originalResource'] instanceof \‪TYPO3\CMS\Core\Resource\‪FileReference
127  ) {
128  $structureItem = $structureItem['originalResource']->getProperties();
129  }
130  $structure[$identifier] = $structureItem;
131  }
132 
133  return $structure;
134  }
135 
139  protected function ‪getRuntimeIdentifier()
140  {
141  ‪$arguments = [];
142  foreach ($this->request->getArguments() as $argumentName => $argumentValue) {
143  ‪$arguments[] = $argumentName . '=' . $argumentValue;
144  }
145  return $this->request->getControllerActionName() . '(' . implode(', ', ‪$arguments) . ')';
146  }
147 }
‪TYPO3\CMS\Extbase\Property\Exception
Definition: DuplicateObjectException.php:18
‪ExtbaseTeam\BlogExample\Controller\ContentController\processRequest
‪processRequest(RequestInterface $request, ResponseInterface $response)
Definition: ContentController.php:78
‪ExtbaseTeam\BlogExample\Controller\ContentController\getStructure
‪array getStructure($iterator)
Definition: ContentController.php:94
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:18
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController\$arguments
‪TYPO3 CMS Extbase Mvc Controller Arguments $arguments
Definition: ActionController.php:141
‪ExtbaseTeam\BlogExample\Controller
Definition: BlogController.php:16
‪TYPO3\CMS\Extbase\Mvc\ResponseInterface
Definition: ResponseInterface.php:22
‪TYPO3
‪ExtbaseTeam\BlogExample\Controller\ContentController
Definition: ContentController.php:33
‪ExtbaseTeam\BlogExample\Controller\ContentController\$defaultViewObjectName
‪string $defaultViewObjectName
Definition: ContentController.php:41
‪TYPO3\CMS\Extbase\Reflection\ObjectAccess
Definition: ObjectAccess.php:38
‪ExtbaseTeam\BlogExample\Controller\ContentController\$contentRepository
‪ExtbaseTeam BlogExample Domain Repository TtContentRepository $contentRepository
Definition: ContentController.php:37
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController\$response
‪TYPO3 CMS Extbase Mvc Response $response
Definition: ActionController.php:115
‪ExtbaseTeam\BlogExample\Controller\ContentController\getRuntimeIdentifier
‪string getRuntimeIdentifier()
Definition: ContentController.php:136
‪TYPO3\CMS\Extbase\Reflection\ObjectAccess\getGettableProperties
‪static array getGettableProperties(object $object)
Definition: ObjectAccess.php:356
‪ExtbaseTeam\BlogExample\Controller\ContentController\listAction
‪array listAction()
Definition: ContentController.php:51
‪TYPO3\CMS\Extbase\Property\Exception
Definition: Exception.php:26
‪TYPO3\CMS\Extbase\Domain\Model\FileReference
Definition: FileReference.php:28
‪ExtbaseTeam\BlogExample\Controller\ContentController\$dataMapFactory
‪TYPO3 CMS Extbase Persistence Generic Mapper DataMapFactory $dataMapFactory
Definition: ContentController.php:46
‪TYPO3\CMS\Extbase\Mvc\RequestInterface
Definition: RequestInterface.php:22
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController\$request
‪TYPO3 CMS Extbase Mvc Request $request
Definition: ActionController.php:109
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController
Definition: ActionController.php:55
‪TYPO3\CMS\Extbase\Mvc\View\JsonView
Definition: JsonView.php:29