‪TYPO3CMS  10.4
BlogController.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
27 
32 {
37  protected ‪$blogRepository;
38 
42  protected ‪$defaultViewObjectName = JsonView::class;
43 
48  protected ‪$dataMapFactory;
49 
50  public function ‪listAction()
51  {
52  $blogs = $this->blogRepository->findAll();
53  $value = [];
54  $value[$this->‪getRuntimeIdentifier()] = $this->‪getStructure($blogs);
55 
56  $this->view->assign('value', $value);
57  }
58 
59  public function ‪detailsAction(‪Blog $blog=null)
60  {
61  return $blog ? $blog->getTitle() : '';
62  }
63 
67  public function ‪testFormAction()
68  {
69  return 'testFormAction';
70  }
71 
77  public function ‪testForwardAction($blogPost)
78  {
79  $this->‪forward('testForwardTarget', null, null, ['blogPost' => $blogPost]);
80  }
81 
86  public function ‪testForwardTargetAction($blogPost)
87  {
88  return 'testForwardTargetAction';
89  }
90 
96  public function ‪testRelatedObjectAction($blog, $blogPost = null)
97  {
98  return 'testRelatedObject';
99  }
100 
106  public function ‪processRequest(RequestInterface ‪$request, ResponseInterface ‪$response)
107  {
108  try {
109  parent::processRequest(‪$request, ‪$response);
110  } catch (Exception $exception) {
111  throw new \RuntimeException(
112  $this->‪getRuntimeIdentifier() . ': ' . $exception->getMessage() . ' (' . $exception->getCode() . ')',
113  1476122222
114  );
115  }
116  }
117 
124  protected function ‪getErrorFlashMessage()
125  {
126  return false;
127  }
128 
133  protected function ‪getStructure($iterator)
134  {
135  $structure = [];
136 
137  if (!$iterator instanceof \Iterator) {
138  $iterator = [$iterator];
139  }
140 
141  foreach ($iterator as $entity) {
142  $dataMap = $this->dataMapFactory->buildDataMap(get_class($entity));
143  $tableName = $dataMap->getTableName();
144  $identifier = $tableName . ':' . $entity->getUid();
145  $properties = ‪ObjectAccess::getGettableProperties($entity);
146 
147  $structureItem = [];
148  foreach ($properties as $propertyName => $propertyValue) {
149  $columnMap = $dataMap->getColumnMap($propertyName);
150  if ($columnMap !== null) {
151  $propertyName = $columnMap->getColumnName();
152  }
153  if ($propertyValue instanceof \Iterator) {
154  $structureItem[$propertyName] = $this->‪getStructure($propertyValue);
155  } else {
156  $structureItem[$propertyName] = $propertyValue;
157  }
158  }
159  $structure[$identifier] = $structureItem;
160  }
161 
162  return $structure;
163  }
164 
168  protected function ‪getRuntimeIdentifier()
169  {
170  ‪$arguments = [];
171  foreach ($this->request->getArguments() as $argumentName => $argumentValue) {
172  ‪$arguments[] = $argumentName . '=' . $argumentValue;
173  }
174  return $this->request->getControllerActionName() . '(' . implode(', ', ‪$arguments) . ')';
175  }
176 }
‪ExtbaseTeam\BlogExample\Controller\BlogController
Definition: BlogController.php:32
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController\forward
‪forward($actionName, $controllerName=null, $extensionName=null, array $arguments=null)
Definition: ActionController.php:815
‪TYPO3\CMS\Extbase\Property\Exception
Definition: DuplicateObjectException.php:18
‪TYPO3\CMS\Extbase\Annotation\IgnoreValidation
Definition: IgnoreValidation.php:25
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:18
‪ExtbaseTeam\BlogExample\Controller\BlogController\listAction
‪listAction()
Definition: BlogController.php:47
‪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
‪ExtbaseTeam\BlogExample\Controller\BlogController\$defaultViewObjectName
‪string $defaultViewObjectName
Definition: BlogController.php:40
‪TYPO3\CMS\Extbase\Mvc\ResponseInterface
Definition: ResponseInterface.php:22
‪ExtbaseTeam\BlogExample\Controller\BlogController\testFormAction
‪string testFormAction()
Definition: BlogController.php:64
‪ExtbaseTeam\BlogExample\Controller\BlogController\$blogRepository
‪ExtbaseTeam BlogExample Domain Repository BlogRepository $blogRepository
Definition: BlogController.php:36
‪ExtbaseTeam\BlogExample\Controller\BlogController\getRuntimeIdentifier
‪string getRuntimeIdentifier()
Definition: BlogController.php:165
‪ExtbaseTeam\BlogExample\Controller\BlogController\getStructure
‪array getStructure($iterator)
Definition: BlogController.php:130
‪TYPO3\CMS\Extbase\Reflection\ObjectAccess
Definition: ObjectAccess.php:38
‪ExtbaseTeam\BlogExample\Controller\BlogController\testForwardAction
‪testForwardAction($blogPost)
Definition: BlogController.php:74
‪TYPO3\CMS\Extbase\Mvc\Controller\ActionController\$response
‪TYPO3 CMS Extbase Mvc Response $response
Definition: ActionController.php:115
‪ExtbaseTeam\BlogExample\Controller\BlogController\testRelatedObjectAction
‪string testRelatedObjectAction($blog, $blogPost=null)
Definition: BlogController.php:93
‪TYPO3\CMS\Extbase\Reflection\ObjectAccess\getGettableProperties
‪static array getGettableProperties(object $object)
Definition: ObjectAccess.php:356
‪ExtbaseTeam\BlogExample\Domain\Model\Blog
Definition: Blog.php:27
‪ExtbaseTeam\BlogExample\Controller\BlogController\$dataMapFactory
‪TYPO3 CMS Extbase Persistence Generic Mapper DataMapFactory $dataMapFactory
Definition: BlogController.php:45
‪TYPO3\CMS\Extbase\Property\Exception
Definition: Exception.php:26
‪ExtbaseTeam\BlogExample\Controller\BlogController\detailsAction
‪detailsAction(Blog $blog=null)
Definition: BlogController.php:56
‪ExtbaseTeam\BlogExample\Controller\BlogController\getErrorFlashMessage
‪bool getErrorFlashMessage()
Definition: BlogController.php:121
‪TYPO3\CMS\Extbase\Mvc\RequestInterface
Definition: RequestInterface.php:22
‪ExtbaseTeam\BlogExample\Controller\BlogController\testForwardTargetAction
‪string testForwardTargetAction($blogPost)
Definition: BlogController.php:83
‪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
‪ExtbaseTeam\BlogExample\Controller\BlogController\processRequest
‪processRequest(RequestInterface $request, ResponseInterface $response)
Definition: BlogController.php:103
‪TYPO3\CMS\Extbase\Mvc\View\JsonView
Definition: JsonView.php:29