Project

General

Profile

Actions

Bug #72706

closed

Manually instantiated UriBuilder is incomplete

Added by Aimeos no-lastname-given almost 9 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Must have
Assignee:
-
Category:
Backend API
Target version:
-
Start date:
2016-01-14
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
10
PHP Version:
5.5
Tags:
Complexity:
Is Regression:
Yes
Sprint Focus:

Description

When trying to instantiate the UriBuilder object in a scheduler task using the object manager, the resulting object is incomplete, esp. the ContentObjectRenderer instance is missing. This results in a fatal error when trying to generate a link.

Example code in scheduler task:

$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( \TYPO3\CMS\Extbase\Object\ObjectManager::class );
$uriBuilder = $objectManager->get( \TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder::class );

$uriBuilder->setTargetPageUid( $pageid )->setArguments( array() );
$url = $uriBuilder->buildFrontendUri();

It worked from 7.0 to at least 7.3 but seemed to vanish in 7.4 again.


Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Bug #88506: Scheduler generated URLs contain absolute unix pathsClosed2019-06-06

Actions
Actions #1

Updated by Christian Eßl over 5 years ago

  • TYPO3 Version changed from 7 to 10

This is still an issue in master and the problem is pretty well known and clear:

You need a valid frontend context for the UriBuilder to be able to correctly call UriBuilder::buildFrontendUri(). This means you can't build frontend uris in backend or cli context.

There are several workarounds available like:
  • manually setting up a TypoScriptFrontendController for "simulating" the frontend (which is really ugly)
  • using third party extensions like "typoscript_rendering"

But since TYPO3 9.5, the new Routing API is available and already used in other parts in the core (Have a look at BackendUtility::getPreviewUrl()). I wonder if the routing API could be used in the UriBuilder as well for easily building frontend uris independent of the callers context? Or are there some edge cases or other issues that could arise from that?

Actions #2

Updated by Benni Mack almost 5 years ago

  • Status changed from New to Needs Feedback

Since TYPO3 v9 / site handling you don't need TSFE or cObject anymore to generate a link to a page.

$site->getRouter->buildUri($pageId).

This works in CLI and Backend environment as well.

Actions #3

Updated by Aimeos no-lastname-given almost 5 years ago

Thanks a lot!
How do we get the $site variable? Can you post the code that is necessary for setting it up that?

Actions #4

Updated by Benni Mack almost 5 years ago

In TYPO3 v9, try out the SiteFinder class, there is a class "getSiteByPageId($pid)".

        $pageId = 13;
        $site = GeneralUtility::makeInstance(SiteFinder::class)->getSiteByPageId($pageId);
        $site->getRouter()->generateUri($pageId, ['my-argument' => 13]);
Actions #5

Updated by Benni Mack almost 5 years ago

  • Related to Bug #88506: Scheduler generated URLs contain absolute unix paths added
Actions #6

Updated by Georg Ringer almost 5 years ago

  • Status changed from Needs Feedback to Resolved

setting this as solved

Actions #7

Updated by Benni Mack over 4 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF