Snoop an argument from another action in TYPO3 plugin

Often times we have several plugins on a page that need to know the value of an action submitted to that page. The issue is that the message can only be directed to one plugin at a time. A common case would be a search field that is reused across the site, posting to a result list plugin. Now you want that searched value to be present in every search field – for example you have duplicates because of an output in a mobile menu.

Here is a nice and clean way without destroying the clean structure of your plugin action to retrieve the value of a foreign plugin action for your own action.

public function initialize<myActionName>Action()
{
if(!$this->request->hasArgument('<myActionArgument>')){
$foreignPluginArguments = \TYPO3\CMS\Core\Utility\GeneralUtility::_POST('<otherActionPluginName>');
if(!empty($foreignPluginArguments['<otherActionPluginName>'])){
$this->request->setArgument('<myActionArgument>', $post['<otherActionPluginName>']);
}
}
}

Here in this example we’ve used a POST action, but the same can be done for GET, just replace _POST with _GET. If you want to be more flexible how you retrieve the value you can also be bold an use _GP.

As long as your own action uses an argument of the same type, the TYPO3 framework will handle objects and validate them as usual. Your own action stay untouched by the interception.

Leave a Comment

Your email address will not be published. Required fields are marked *