Bug #91625
closedUriBuilder: inconsistent behaviour between application contexts Development + Production
100%
Description
I have a class method that gets called by a hook of felogin.
In this method I use the uriFor() method of UriBuilder to build a redirect URL. This works without a problem in my development environment, which runs in application context Development.
After installing the extension in the live environment (running in application context Production), I ran into constant problems. Building the redirect URL works maybe once in ten attempts. For the rest of the time it fails with "Call to a member function typoLink_URL() on null"
, which seems to be caused by $this->contentObject not being set in buildFrontendUri(). I haven't found out yet, why it works sometimes. I tried clearing caches and reloading and what not. I then switched the live environment to application context Development and everything works again without a problem.
This raises several questions:
1) What's going on? Why does it occasionally work? I know there can be issues when UriBuilder is called in special situations (eg. scheduler tasks, command controllers), but here we are in FE mode, so what's the problem? (According to the API docs this "Works in Frontend and Backend mode of TYPO3".)
2) Why can code, which was written in application context Development, not safely be used in Production? That seems to defy the whole point of application contexts. Why should I even bother to develop in application context Development, if I can't be sure that it will later work in the live environment?
Updated by Christian Eßl over 4 years ago
Which TYPO3 9 version was used? Does updating to the latest version (9.5.19) fix the problem?
I just happened to stumble upon the same problem in 8.7.32 and I'm curious if this problem is related to recent problems with the Extbase ReflectionService that were fixed in the last minor patches. AFAIK this problem should be relatively new.
As a "hotfix" you could also do the following to manually set up the ContentObject:
/** @var ConfigurationManager $configurationManager */
$configurationManager = $this->objectManager->get(ConfigurationManager::class);
/** @var ContentObjectRenderer $contentObjectRenderer */
$contentObjectRenderer = $this->objectManager->get(ContentObjectRenderer::class);
$configurationManager->setContentObject($contentObjectRenderer);
$uriBuilder = $this->objectManager->get(UriBuilder::class);
$uriBuilder->injectConfigurationManager($configurationManager);
// now use UriBuilder
Updated by Christopher Kaster over 4 years ago
Christian Eßl wrote:
Which TYPO3 9 version was used? Does updating to the latest version (9.5.19) fix the problem?
I just happened to stumble upon the same problem in 8.7.32 and I'm curious if this problem is related to recent problems with the Extbase ReflectionService that were fixed in the last minor patches. AFAIK this problem should be relatively new.As a "hotfix" you could also do the following to manually set up the ContentObject:
[...]
I can confirm we have this issue with TYPO3 v9.5.19 as well, I'll try the workaround in a bit.
Edit: Workaround works :)
Updated by Michael Stopp over 4 years ago
@Christian Eßl: sorry, I somehow missed your comment...
Yes, this was done with the latest V9 version.
As for your workaround: can't test this easily right now, because I had rewritten the code without UriBuilder, using something like this:
$additionalParams = HttpUtility::buildQueryString($arguments, '&');
$conf = [
'parameter' => $this->settings['targetPage'],
'additionalParams' => $additionalParams
];
$uri = $GLOBALS['TSFE']->cObj->typoLink_URL($conf);
Updated by Gerrit Code Review over 3 years ago
- Status changed from New to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/69132
Updated by Gerrit Code Review over 3 years ago
Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/69132
Updated by Gerrit Code Review over 3 years ago
Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/69132
Updated by Gerrit Code Review over 3 years ago
Patch set 1 for branch 10.4 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/69133
Updated by Gerrit Code Review over 3 years ago
Patch set 2 for branch 10.4 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/69133
Updated by Benni Mack over 3 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset b5eab03e52b14344178a88981063597af30e46da.
Updated by Torben Hansen about 3 years ago
- Related to Bug #95118: Unable to use UriBuilder outside Extbase added
Updated by Benni Mack about 3 years ago
- Related to Bug #95265: Revert injection of ContentObjectRenderer in UriBuilder added