简体   繁体   中英

Is there a way to redirect from one plugin to another plugin in Extbase?

Using Typo3 V11.5.15 I need a way to move from a form, where you add a new employee to a list, to another form when the given company doesn't exist yet.

I tried using redirect and the URI builder but nothing seems to work.

I do explicitly NOT want to have af:link.action in a second page where the user can check the input. I often see this recommended in older threads.


Edit1 I did check into the 4 year old work around for the old bug with redirect using AJAX. But this should be obsolete by now and the older solutions seem to not work.


Edit2

I did something similar to Stefan Bürk's answer suggests.

//added the UriBuilder first
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;

//new instance of UriBuilder and using it to ... build the Uri....
$uriBuilder = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(UriBuilder::class);
$uriBuilder->setTargetPageUid($PageUidGoesHere);
$uri = $uriBuilder->uriFor($ControllerAction, $ParametersArray, $ControllerName, $ExtensionName, $PluginName);
//redirecting to selfmade Uri
return $this->redirectToUri($uri);

You missed to mention the used TYPO3 core version. In some of the newer core versions, where extbase is request/response aware, returning a redirect response in the extbase controller action may not work. If this is the case for you, you should be able to create a redirect response and throw it as a PropagateResponseException, which leaves some places out and jumpts to an outer place in the request onion - and thus returning a proper redirect to the browser.

// build your uri with uri builder 
$redirectUri = $this->uriBuilder->uriFor(....);
$redirectResponse = new \TYPO3\CMS\Core\Http\RedirectResponse($redirectUri, 307, []);
throw new \TYPO3\CMS\Core\Http\PropagateResponseException($redirectResponse, 0);

You may also use the $this->redirect(..) or $this->rediretToUri() method to create the $redirectResponse and throw it then.

throw new \TYPO3\CMS\Core\Http\PropagateResponseException(
  $this->redirect(....), 0);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM