‪TYPO3CMS  10.4
WidgetRequestBuilder.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 
23 
28 {
33 
38  {
39  $this->ajaxWidgetContextHolder = ‪$ajaxWidgetContextHolder;
40  }
41 
47  public function ‪build(): ‪RequestInterface
48  {
49  $baseUri = GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
50  if ($this->environmentService->isEnvironmentInBackendMode()) {
51  $baseUri .= TYPO3_mainDir;
52  }
53 
54  $rawGetArguments = GeneralUtility::_GET();
55  if (!isset($rawGetArguments['fluid-widget-id'])) {
56  // Low level test, WidgetRequestHandler returns false in canHandleRequest () if this is not set
57  throw new \InvalidArgumentException(
58  'No Fluid Widget ID was given.',
59  1521190675
60  );
61  }
62  $widgetContext = $this->ajaxWidgetContextHolder->get($rawGetArguments['fluid-widget-id']);
63 
64  $request = $this->objectManager->get(WidgetRequest::class, $widgetContext->getControllerObjectName());
65  $request->setRequestUri(GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'));
66  $request->setBaseUri($baseUri);
67  $request->setMethod($_SERVER['REQUEST_METHOD'] ?? null);
68  if (strtolower($_SERVER['REQUEST_METHOD']) === 'post') {
69  $request->setArguments(GeneralUtility::_POST());
70  } else {
71  $request->setArguments(GeneralUtility::_GET());
72  }
73  if (isset($rawGetArguments['action'])) {
74  $request->setControllerActionName($rawGetArguments['action']);
75  }
76  $request->setWidgetContext($widgetContext);
77  return $request;
78  }
79 }
‪TYPO3\CMS\Fluid\Core\Widget
Definition: AbstractWidgetController.php:16
‪TYPO3\CMS\Fluid\Core\Widget\WidgetRequestBuilder\injectAjaxWidgetContextHolder
‪injectAjaxWidgetContextHolder(AjaxWidgetContextHolder $ajaxWidgetContextHolder)
Definition: WidgetRequestBuilder.php:36
‪TYPO3\CMS\Fluid\Core\Widget\WidgetRequestBuilder
Definition: WidgetRequestBuilder.php:28
‪TYPO3\CMS\Fluid\Core\Widget\WidgetRequestBuilder\build
‪RequestInterface build()
Definition: WidgetRequestBuilder.php:46
‪TYPO3\CMS\Extbase\Mvc\RequestInterface
Definition: RequestInterface.php:22
‪TYPO3\CMS\Fluid\Core\Widget\AjaxWidgetContextHolder
Definition: AjaxWidgetContextHolder.php:33
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Fluid\Core\Widget\WidgetRequestBuilder\$ajaxWidgetContextHolder
‪AjaxWidgetContextHolder $ajaxWidgetContextHolder
Definition: WidgetRequestBuilder.php:31
‪TYPO3\CMS\Extbase\Mvc\Web\RequestBuilder
Definition: RequestBuilder.php:38