Project

General

Profile

Bug #23874 ยป 16173_fluidtemplate_refactoring.patch

Administrator Admin, 2010-10-29 18:08

View differences:

typo3/sysext/cms/tslib/content/class.tslib_content_fluidtemplate.php (working copy)
* $Id: class.tslib_content.php 7905 2010-06-13 14:42:33Z ohader $
* @author Xavier Perseguers <typo3@perseguers.ch>
* @author Steffen Kamper <steffen@typo3.org>
* @author Bastian Waidelich <bastian@typo3.org>
*/
class tslib_content_FluidTemplate extends tslib_content_Abstract {
/**
* Rendering the cObject, TEMPLATE
*
* @param array array of TypoScript properties
* @return string Output
* @see substituteMarkerArrayCached()
*/
function TEMPLATE($conf) {
return $this->getContentObject('TEMPLATE')->render($conf);
}
/**
* Rendering the cObject, FLUIDTEMPLATE
* configuration properties are:
* - file string+stdWrap the FLUID template file
......
*
* @param array array of TypoScript properties
* @return string the HTML output
* @author Steffen Ritter <info@steffen-ritter.net>
* @author Benjamin Mack <benni@typo3.org>
* @author Steffen Ritter <info@steffen-ritter.net>
* @author Benjamin Mack <benni@typo3.org>
* @author Bastian Waidelich <bastian@typo3.org>
*/
public function render($conf = array()) {
// check if the needed extensions are installed
if (!t3lib_extMgm::isLoaded('fluid')) {
return 'You need to install "Fluid" in order to use the FLUIDTEMPLATE content element';
}
if (!t3lib_extMgm::isLoaded('extbase')) {
return 'You need to install "Extbase" in order to use the FLUIDTEMPLATE content element';
}
// initialize the extbase autoloader,
// see Extbase_Dispatcher->initializeClassLoader
if (!class_exists('Tx_Extbase_Utility_ClassLoader')) {
require(t3lib_extmgm::extPath('extbase') . 'Classes/Utility/ClassLoader.php');
$classLoader = new Tx_Extbase_Utility_ClassLoader();
spl_autoload_register(array($classLoader, 'loadClass'));
}
/**
* 1. initializing configuration parameters
* 1. initializing Fluid StandaloneView and setting configuration parameters
**/
$view = t3lib_div::makeInstance('Tx_Fluid_View_StandaloneView');
// fetch the Fluid template
$templatePathAndFilename = $GLOBALS['TSFE']->tmpl->getFileName($this->cObj->stdWrap($conf['file'], $conf['file.']));
$view->setTemplatePathAndFilename($templatePathAndFilename);
// fetch the FLUID file
$templateFile = $GLOBALS['TSFE']->tmpl->getFileName($this->cObj->stdWrap($conf['file'], $conf['file.']));
$templatePath = dirname($templateFile) . '/';
$layoutRootPath = $templatePath . 'Layouts';
$partialRootPath = $templatePath . 'Partials';
// override the default layout path via typoscript
if (isset($conf['layoutRootPath']) || isset($conf['layoutRootPath.'])) {
// override the default layout base path via typoscript
if (isset($conf['layoutRootPath'])) {
$layoutRootPath = $this->cObj->stdWrap($conf['layoutRootPath'], $conf['layoutRootPath.']);
$layoutRootPath = t3lib_div::getFileAbsFileName($layoutRootPath);
$view->setLayoutRootPath($layoutRootPath);
}
// override the default partials path via typoscript
if (isset($conf['partialRootPath']) || isset($conf['partialRootPath.'])) {
// override the default partial base path via typoscript
if (isset($conf['partialRootPath'])) {
$partialRootPath = $this->cObj->stdWrap($conf['partialRootPath'], $conf['partialRootPath.']);
$partialRootPath = t3lib_div::getFileAbsFileName($partialRootPath);
$view->setPartialRootPath($partialRootPath);
}
// override the default format
if (isset($conf['format'])) {
$view->setFormat($conf['format']);
}
// set some default variables for initializing Extbase
// set some default variables for Extbase dependant view helpers (e.g. link.action)
if (isset($conf['extbase.']['pluginName'])) {
$requestPluginName = $conf['extbase.']['pluginName'];
} else {
$requestPluginName = 'pi1';
$view->getRequest()->setPluginName($conf['extbase.']['pluginName']);
}
if (isset($conf['extbase.']['controllerExtensionName'])) {
$requestControllerExtensionName = $conf['extbase.']['controllerExtensionName'];
} else {
$requestControllerExtensionName = 'cms';
$view->getRequest()->setControllerExtensionName($conf['extbase.']['controllerExtensionName']);
}
if (isset($conf['extbase.']['controllerName'])) {
$requestControllerName = $conf['extbase.']['controllerName'];
} else {
$requestControllerName = 'cms';
$view->getRequest()->setControllerName($conf['extbase.']['controllerName']);
}
if (isset($conf['extbase.']['controllerActionName'])) {
$requestControllerActionName = $conf['extbase.']['controllerActionName'];
} else {
$requestControllerActionName = 'index';
$view->getRequest()->setControllerActionName($conf['extbase.']['controllerActionName']);
}
/**
* 2. initializing Fluid classes,
* first, the controller context needs to be created
**/
$objectManager = t3lib_div::makeInstance('Tx_Fluid_Compatibility_ObjectManager');
// creating a request object
$controllerContext = $objectManager->create('Tx_Extbase_MVC_Controller_ControllerContext');
/**
* @var $request Tx_Extbase_MVC_Web_Request
*/
$request = t3lib_div::makeInstance('Tx_Extbase_MVC_Web_Request');
$request->setPluginName($requestPluginName);
$request->setControllerExtensionName($requestControllerExtensionName);
$request->setControllerName($requestControllerName);
$request->setControllerActionName($requestControllerActionName);
$request->setRequestURI(t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'));
$request->setBaseURI(t3lib_div::getIndpEnv('TYPO3_SITE_URL'));
/**
* @var $uriBuilder Tx_Extbase_MVC_Web_Routing_UriBuilder
*/
$uriBuilder = t3lib_div::makeInstance('Tx_Extbase_MVC_Web_Routing_UriBuilder');
$uriBuilder->setRequest($request);
$controllerContext->setRequest($request);
$controllerContext->setUriBuilder($uriBuilder);
/**
* @var $view Tx_Fluid_View_TemplateView
*/
$view = t3lib_div::makeInstance('Tx_Fluid_View_TemplateView');
$view->setControllerContext($controllerContext);
// setting the paths for the template and the layouts/partials
$view->setTemplatePathAndFilename($templateFile);
$view->setLayoutRootPath($layoutRootPath);
$view->setPartialRootPath($partialRootPath);
// In FLOW3, solved through Object Lifecycle methods,
// v4 needs to call it explicitely
$view->initializeView();
/**
* 3. variable replacement
*/
* 2. variable assignment
*/
$reservedVariables = array('data', 'current');
// accumulate the variables to be replaced
// and loop them through cObjGetSingle
$variables = (array) $conf['variables.'];
foreach ($variables as $variableName => $cObjType) {
if (is_array($cObjType)) {
continue;
}
if(!in_array($variableName, $reservedVariables)) {
if (!is_array($cObjType)) {
$view->assign($variableName, $this->cObj->cObjGetSingle($cObjType, $variables[$variableName . '.']));
}
$view->assign($variableName, $this->cObj->cObjGetSingle($cObjType, $variables[$variableName . '.']));
} else {
throw new InvalidArgumentException('Cannot use reserved name "' . $variableName . '" as variable name in FLUIDTEMPLATE');
throw new InvalidArgumentException('Cannot use reserved name "' . $variableName . '" as variable name in FLUIDTEMPLATE.', 1288095720);
}
}
$view->assign('data', $this->cObj->data);
$view->assign('current', $this->cObj->data[$this->cObj->currentValKey]);
/**
* 4. render the content
* 3. render the content
*/
$content = $view->render();
return $this->cObj->stdWrap($content, $conf['stdWrap.']);
    (1-1/1)