Skip to content

Instantly share code, notes, and snippets.

@cedricziel
Created November 4, 2016 14:40
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cedricziel/314385cf7e7079f276005ea66e122512 to your computer and use it in GitHub Desktop.
Save cedricziel/314385cf7e7079f276005ea66e122512 to your computer and use it in GitHub Desktop.
TYPO3 CMS 7 fully loaded TSFE in EiD
<?php
namespace Project\Namespace\Hooks;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Core\Bootstrap;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
class CustomerAutocompletion {
/**
* @var TypoScriptFrontendController
*/
protected $controller;
/**
* @var Bootstrap
*/
protected $bootstrap;
public function processRequest(ServerRequestInterface $request, ResponseInterface $response)
{
$extConf = $this->getExtensionConfiguration();
$this->initializeController();
$this->boot();
$cObj = $this->getContentObjectRenderer();
// generate $output
$response = $response->withHeader('Content-Type', 'text/html; charset=utf-8');
$response->getBody()->write($output);
return $response;
}
/**
* @return array
*/
protected function getExtensionConfiguration()
{
/** @var ObjectManager $objectManager */
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$configurationUtility = $objectManager->get(ConfigurationUtility::class);
return $configurationUtility->getCurrentConfiguration(static::EXT_KEY);
}
/**
* @return ContentObjectRenderer
*/
protected function getContentObjectRenderer()
{
return GeneralUtility::makeInstance(ContentObjectRenderer::class);
}
/**
* Creates an instance of TSFE and sets it as a global variable
*
* @return void
*/
protected function initializeController()
{
$this->controller = GeneralUtility::makeInstance(
TypoScriptFrontendController::class,
$GLOBALS['TYPO3_CONF_VARS'],
GeneralUtility::_GP('id'),
GeneralUtility::_GP('type'),
GeneralUtility::_GP('no_cache'),
GeneralUtility::_GP('cHash'),
GeneralUtility::_GP('jumpurl'),
GeneralUtility::_GP('MP'),
GeneralUtility::_GP('RDCT')
);
// setting the global variable for the controller
// We have to define this as reference here, because there is code around
// which exchanges the TSFE object in the global variable. The reference ensures
// that the $controller member always works on the same object as the global variable.
// This is a dirty workaround and bypasses the protected access modifier of the controller member.
$GLOBALS['TSFE'] = &$this->controller;
}
/**
* Boot the environment
*/
protected function boot()
{
$this->bootstrap = Bootstrap::getInstance();
$this->bootstrap->loadCachedTca();
$this->controller->connectToDB();
$this->controller->initFEuser();
$this->controller->determineId();
$this->controller->initTemplate();
$this->controller->getConfigArray();
if (ExtensionManagementUtility::isLoaded('realurl')) {
$rootline = BackendUtility::BEgetRootLine(1);
$host = BackendUtility::firstDomainRecord($rootline);
$_SERVER['HTTP_HOST'] = $host;
}
}
}
<?php
if (!defined('TYPO3_MODE')) {
die('Access denied.');
}
$TYPO3_CONF_VARS['FE']['eID_include']['autocomplete'] = \Project\Namespace\Hooks\CustomerAutocompletion::class . '::processRequest';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment