Skip to content

Commit

Permalink
[TASK] Clean up usages of ContentObjectRenderer request attribute
Browse files Browse the repository at this point in the history
ContentObjectRenderer is now added as request attribute in
certain cases. But since the signature of obtaining an attribute
from a request correctly states, that the attribute can be null,
consuming code should account for that and defensively
fall back to defaults, when the object can not be obtained.

Releases: 12.4, main
Resolves: #101201
Change-Id: I3b3145794cafd8f5a8c1081e97599f9862be8b99
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/80921
Tested-by: Stefan Bürk <[email protected]>
Reviewed-by: Stefan Bürk <[email protected]>
Tested-by: core-ci <[email protected]>
  • Loading branch information
helhum authored and sbuerk committed Sep 7, 2023
1 parent e139e07 commit 397851d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Classes/Controller/FormFrontendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function renderAction(): ResponseInterface
$formDefinition['persistenceIdentifier'] = $this->settings['persistenceIdentifier'];
$formDefinition = $this->overrideByFlexFormSettings($formDefinition);
$formDefinition = ArrayUtility::setValueByPath($formDefinition, 'renderingOptions._originalIdentifier', $formDefinition['identifier'], '.');
$formDefinition['identifier'] .= '-' . $this->request->getAttribute('currentContentObject')->data['uid'];
$formDefinition['identifier'] .= '-' . ($this->request->getAttribute('currentContentObject')?->data['uid'] ?? '');
}
$this->view->assign('formConfiguration', $formDefinition);

Expand All @@ -93,7 +93,7 @@ public function performAction(): ResponseInterface
*/
protected function overrideByFlexFormSettings(array $formDefinition): array
{
$flexFormData = GeneralUtility::xml2array($this->request->getAttribute('currentContentObject')->data['pi_flexform'] ?? '');
$flexFormData = GeneralUtility::xml2array($this->request->getAttribute('currentContentObject')?->data['pi_flexform'] ?? '');

if (!is_array($flexFormData)) {
return $formDefinition;
Expand Down
17 changes: 7 additions & 10 deletions Classes/Domain/Runtime/FormRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,16 +499,16 @@ protected function isPostRequest(): bool
* If no surrounding content object can be found (which would be strange)
* we assume a cached request for safety which means that an empty form
* will be rendered.
*
* @todo: this should be checked against https://forge.typo3.org/issues/91625 as this was fixed differently for UriBuilder
*/
protected function isRenderedCached(): bool
{
$contentObject = $this->request->getAttribute('currentContentObject');
return $contentObject === null
? true
// @todo this does not work when rendering a cached `FLUIDTEMPLATE` (not nested in `COA_INT`)
: $contentObject->getUserObjectType() === ContentObjectRenderer::OBJECTTYPE_USER;
// @todo: this does not work when rendering a cached `FLUIDTEMPLATE` (not nested in `COA_INT`)
// Rendering the form other than with the controller, will never work out cleanly.
// This likely can only be resolved by deprecating using the form render view helper
// other than in a template for the form plugin and covering the use cases the VH was introduced
// with a different concept
return $contentObject === null || $contentObject->getUserObjectType() === ContentObjectRenderer::OBJECTTYPE_USER;
}

/**
Expand Down Expand Up @@ -1078,10 +1078,7 @@ protected function getConditionResolver(): Resolver
}
}

$contentObjectData = [];
if ($this->request->getAttribute('currentContentObject') instanceof ContentObjectRenderer) {
$contentObjectData = $this->request->getAttribute('currentContentObject')->data;
}
$contentObjectData = $this->request->getAttribute('currentContentObject')?->data ?? [];

return GeneralUtility::makeInstance(
Resolver::class,
Expand Down

0 comments on commit 397851d

Please sign in to comment.