‪TYPO3CMS  9.5
BlogController.php
Go to the documentation of this file.
1 <?php
2 
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 
21 
26 {
31  protected ‪$blogRepository;
32 
36  protected ‪$defaultViewObjectName = \TYPO3\CMS\Extbase\Mvc\View\JsonView::class;
37 
42  protected ‪$dataMapFactory;
43 
44  public function ‪listAction()
45  {
46  $blogs = $this->blogRepository->findAll();
47  $value[$this->‪getRuntimeIdentifier()] = $this->‪getStructure($blogs);
48 
49  $this->view->assign('value', $value);
50  }
51 
52  public function ‪detailsAction(‪Blog $blog=null)
53  {
54  return $blog ? $blog->getTitle() : '';
55  }
56 
60  public function ‪testFormAction()
61  {
62  return 'testFormAction';
63  }
64 
70  public function ‪testForwardAction($blogPost)
71  {
72  $this->‪forward('testForwardTarget', null, null, ['blogPost' => $blogPost]);
73  }
74 
79  public function ‪testForwardTargetAction($blogPost)
80  {
81  return 'testForwardTargetAction';
82  }
83 
89  public function ‪testRelatedObjectAction($blog, $blogPost = null)
90  {
91  return 'testRelatedObject';
92  }
93 
99  public function ‪processRequest(\‪TYPO3\CMS\‪Extbase\Mvc\RequestInterface ‪$request, \‪TYPO3\CMS\‪Extbase\Mvc\ResponseInterface ‪$response)
100  {
101  try {
102  parent::processRequest(‪$request, ‪$response);
103  } catch (\‪TYPO3\CMS\‪Extbase\Property\Exception $exception) {
104  throw new \RuntimeException(
105  $this->‪getRuntimeIdentifier() . ': ' . $exception->getMessage() . ' (' . $exception->getCode() . ')',
106  1476122222
107  );
108  }
109  }
110 
117  protected function ‪getErrorFlashMessage()
118  {
119  return false;
120  }
121 
126  protected function ‪getStructure($iterator)
127  {
128  $structure = [];
129 
130  if (!$iterator instanceof \Iterator) {
131  $iterator = [$iterator];
132  }
133 
134  foreach ($iterator as $entity) {
135  $dataMap = $this->dataMapFactory->buildDataMap(get_class($entity));
136  $tableName = $dataMap->getTableName();
137  $identifier = $tableName . ':' . $entity->getUid();
139 
140  $structureItem = [];
141  foreach ($properties as $propertyName => $propertyValue) {
142  $columnMap = $dataMap->getColumnMap($propertyName);
143  if ($columnMap !== null) {
144  $propertyName = $columnMap->getColumnName();
145  }
146  if ($propertyValue instanceof \Iterator) {
147  $structureItem[$propertyName] = $this->‪getStructure($propertyValue);
148  } else {
149  $structureItem[$propertyName] = $propertyValue;
150  }
151  }
152  $structure[$identifier] = $structureItem;
153  }
154 
155  return $structure;
156  }
157 
161  protected function ‪getRuntimeIdentifier()
162  {
163  ‪$arguments = [];
164  foreach ($this->request->getArguments() as $argumentName => $argumentValue) {
165  ‪$arguments[] = $argumentName . '=' . $argumentValue;
166  }
167  return $this->request->getControllerActionName() . '(' . implode(', ', ‪$arguments) . ')';
168  }
169 }
‪ExtbaseTeam\BlogExample\Controller\BlogController
Definition: BlogController.php:26
‪TYPO3\CMS\Extbase\Annotation\IgnoreValidation
Definition: IgnoreValidation.php:24
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪ExtbaseTeam\BlogExample\Controller\BlogController\listAction
‪listAction()
Definition: BlogController.php:41
‪ExtbaseTeam\BlogExample\Controller
Definition: BlogController.php:3
‪ExtbaseTeam\BlogExample\Controller\BlogController\$defaultViewObjectName
‪string $defaultViewObjectName
Definition: BlogController.php:34
‪TYPO3
‪ExtbaseTeam\BlogExample\Controller\BlogController\testFormAction
‪string testFormAction()
Definition: BlogController.php:57
‪ExtbaseTeam\BlogExample\Controller\BlogController\$blogRepository
‪ExtbaseTeam BlogExample Domain Repository BlogRepository $blogRepository
Definition: BlogController.php:30
‪ExtbaseTeam\BlogExample\Controller\BlogController\getRuntimeIdentifier
‪string getRuntimeIdentifier()
Definition: BlogController.php:158
‪ExtbaseTeam\BlogExample\Controller\BlogController\processRequest
‪processRequest(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request, \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response)
Definition: BlogController.php:96
‪ExtbaseTeam\BlogExample\Controller\BlogController\getStructure
‪array getStructure($iterator)
Definition: BlogController.php:123
‪ExtbaseTeam\BlogExample\Controller\BlogController\testForwardAction
‪testForwardAction($blogPost)
Definition: BlogController.php:67
‪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\BlogController\testRelatedObjectAction
‪string testRelatedObjectAction($blog, $blogPost=null)
Definition: BlogController.php:86
‪ExtbaseTeam\BlogExample\Domain\Model\Blog
Definition: Blog.php:23
‪ExtbaseTeam\BlogExample\Controller\BlogController\$dataMapFactory
‪TYPO3 CMS Extbase Persistence Generic Mapper DataMapFactory $dataMapFactory
Definition: BlogController.php:39
‪ExtbaseTeam\BlogExample\Controller\BlogController\detailsAction
‪detailsAction(Blog $blog=null)
Definition: BlogController.php:49
‪ExtbaseTeam\BlogExample\Controller\BlogController\getErrorFlashMessage
‪bool getErrorFlashMessage()
Definition: BlogController.php:114
‪ExtbaseTeam\BlogExample\Controller\BlogController\testForwardTargetAction
‪string testForwardTargetAction($blogPost)
Definition: BlogController.php:76
‪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
‪TYPO3\CMS\Extbase\Mvc\Controller\AbstractController\forward
‪forward($actionName, $controllerName=null, $extensionName=null, array $arguments=null)
Definition: AbstractController.php:247