‪TYPO3CMS  9.5
ContentController.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
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 
20 
25 {
30  protected ‪$contentRepository;
31 
35  protected ‪$defaultViewObjectName = \TYPO3\CMS\Extbase\Mvc\View\JsonView::class;
36 
41  protected ‪$dataMapFactory;
42 
46  public function ‪listAction()
47  {
48  $content = $this->contentRepository->findAll();
49  $value[$this->‪getRuntimeIdentifier()] = $this->‪getStructure($content);
50  // this is required so we don't try to json_encode content of the image
51  $this->view->setConfiguration(['value' => [
52  '_descendAll' => [
53  '_descendAll' => [
54  '_descendAll' => [
55  '_descendAll' => [
56  '_descendAll' => [
57  '_exclude' => ['contents']
58  ]
59  ]
60  ]
61  ]
62  ]
63  ]]);
64  $this->view->assign('value', $value);
65  }
66 
72  public function ‪processRequest(\‪TYPO3\CMS\‪Extbase\Mvc\RequestInterface ‪$request, \‪TYPO3\CMS\‪Extbase\Mvc\ResponseInterface ‪$response)
73  {
74  try {
75  parent::processRequest(‪$request, ‪$response);
76  } catch (\‪TYPO3\CMS\‪Extbase\Property\Exception $exception) {
77  throw new \RuntimeException(
78  $this->‪getRuntimeIdentifier() . ': ' . $exception->getMessage() . ' (' . $exception->getCode() . ')',
79  1476122223
80  );
81  }
82  }
83 
88  protected function ‪getStructure($iterator)
89  {
90  $structure = [];
91 
92  if (!$iterator instanceof \Iterator) {
93  $iterator = [$iterator];
94  }
95 
96  foreach ($iterator as $entity) {
97  $dataMap = $this->dataMapFactory->buildDataMap(get_class($entity));
98  $tableName = $dataMap->getTableName();
99  $identifier = $tableName . ':' . $entity->getUid();
101 
102  $structureItem = [];
103  foreach ($properties as $propertyName => $propertyValue) {
104  $columnMap = $dataMap->getColumnMap($propertyName);
105  if ($columnMap !== null) {
106  $propertyName = $columnMap->getColumnName();
107  }
108  if ($propertyValue instanceof \Iterator) {
109  $structureItem[$propertyName] = $this->‪getStructure($propertyValue);
110  } else {
111  $structureItem[$propertyName] = $propertyValue;
112  }
113  }
114  //let's flatten the structure and put file reference properties level up, so we can use StructureHasRecordConstraint
115  if ($entity instanceof \‪TYPO3\CMS\‪Extbase\Domain\Model\FileReference
116  && isset($structureItem['originalResource'])
117  && $structureItem['originalResource'] instanceof \‪TYPO3\CMS\Core\Resource\FileReference
118  ) {
119  $structureItem = $structureItem['originalResource']->getProperties();
120  }
121  $structure[$identifier] = $structureItem;
122  }
123 
124  return $structure;
125  }
126 
130  protected function ‪getRuntimeIdentifier()
131  {
132  ‪$arguments = [];
133  foreach ($this->request->getArguments() as $argumentName => $argumentValue) {
134  ‪$arguments[] = $argumentName . '=' . $argumentValue;
135  }
136  return $this->request->getControllerActionName() . '(' . implode(', ', ‪$arguments) . ')';
137  }
138 }
‪ExtbaseTeam\BlogExample\Controller\ContentController\getStructure
‪array getStructure($iterator)
Definition: ContentController.php:85
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪ExtbaseTeam\BlogExample\Controller
Definition: BlogController.php:3
‪TYPO3
‪ExtbaseTeam\BlogExample\Controller\ContentController
Definition: ContentController.php:25
‪ExtbaseTeam\BlogExample\Controller\ContentController\$defaultViewObjectName
‪string $defaultViewObjectName
Definition: ContentController.php:33
‪ExtbaseTeam\BlogExample\Controller\ContentController\$contentRepository
‪ExtbaseTeam BlogExample Domain Repository TtContentRepository $contentRepository
Definition: ContentController.php:29
‪TYPO3\CMS\Extbase\Reflection\ObjectAccess\getGettableProperties
‪static array getGettableProperties($object)
Definition: ObjectAccess.php:372
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController\$response
‪TYPO3 CMS Extbase Mvc Response $response
Definition: ActionController.php:93
‪ExtbaseTeam\BlogExample\Controller\ContentController\getRuntimeIdentifier
‪string getRuntimeIdentifier()
Definition: ContentController.php:127
‪ExtbaseTeam\BlogExample\Controller\ContentController\processRequest
‪processRequest(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request, \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response)
Definition: ContentController.php:69
‪ExtbaseTeam\BlogExample\Controller\ContentController\listAction
‪array listAction()
Definition: ContentController.php:43
‪ExtbaseTeam\BlogExample\Controller\ContentController\$dataMapFactory
‪TYPO3 CMS Extbase Persistence Generic Mapper DataMapFactory $dataMapFactory
Definition: ContentController.php:38
‪TYPO3\CMS\Extbase\Mvc\Controller\AbstractController\$arguments
‪TYPO3 CMS Extbase Mvc Controller Arguments $arguments
Definition: AbstractController.php:67
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController\$request
‪TYPO3 CMS Extbase Mvc Request $request
Definition: ActionController.php:87
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController
Definition: ActionController.php:31