Created
November 4, 2016 14:40
-
-
Save cedricziel/314385cf7e7079f276005ea66e122512 to your computer and use it in GitHub Desktop.
TYPO3 CMS 7 fully loaded TSFE in EiD
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 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; | |
} | |
} | |
} |
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 | |
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