Created
September 16, 2015 13:36
-
-
Save smichaelsen/3ff9ad8ddd44de430b7f to your computer and use it in GitHub Desktop.
ExtbaseViewHelper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace AppZap\Tripshop\ViewHelpers; | |
use TYPO3\CMS\Core\Utility\GeneralUtility; | |
use TYPO3\CMS\Extbase\Core\Bootstrap; | |
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper; | |
/** | |
* Renders an extbase action into your template | |
* | |
* <ts:extbase controller="Journey" action="listComingUp"/> | |
* Renders Journey->listComingUpAction of the current plugin | |
* | |
* <ts:extbase extension="News" vendor="GeorgRinger" plugin="Pi1"/> | |
* Renders the default controller/action of EXT:news | |
*/ | |
class ExtbaseViewHelper extends AbstractViewHelper { | |
/** | |
* @var \TYPO3\CMS\Extbase\Service\ExtensionService | |
* @inject | |
*/ | |
protected $extensionService; | |
/** | |
* @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception | |
*/ | |
public function initializeArguments() { | |
$this->registerArgument('extension', 'string', ''); | |
$this->registerArgument('vendor', 'string', ''); | |
$this->registerArgument('plugin', 'string', ''); | |
$this->registerArgument('controller', 'string', ''); | |
$this->registerArgument('action', 'string', ''); | |
} | |
/** | |
* @return string | |
*/ | |
public function render() { | |
$configuration = [ | |
'extensionName' => $this->arguments['extension'] ?: $this->controllerContext->getRequest()->getControllerExtensionName(), | |
'vendorName' => $this->arguments['vendor'] ?: $this->controllerContext->getRequest()->getControllerVendorName(), | |
'pluginName' => $this->arguments['plugin'] ?: $this->controllerContext->getRequest()->getPluginName(), | |
]; | |
// set controller and action via $_GET | |
if ($this->arguments['controller'] || $this->arguments['action']) { | |
$pluginNamespace = $this->extensionService->getPluginNamespace($configuration['extensionName'], $configuration['pluginName']); | |
$GLOBALS['_GET'][$pluginNamespace] = []; | |
if ($this->arguments['controller']) { | |
$GLOBALS['_GET'][$pluginNamespace]['controller'] = $this->arguments['controller']; | |
} | |
if ($this->arguments['action']) { | |
$GLOBALS['_GET'][$pluginNamespace]['action'] = $this->arguments['action']; | |
} | |
} | |
/** @var Bootstrap $bootstrap */ | |
$bootstrap = GeneralUtility::makeInstance(Bootstrap::class); | |
return $bootstrap->run('', $configuration); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment