[FEATURE] Accept template from content objects FLUIDTEMPLATE 41/16241/5
authorHelmut Hummel <helmut.hummel@typo3.org>
Tue, 6 Nov 2012 19:40:38 +0000 (20:40 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Tue, 29 Jan 2013 18:33:45 +0000 (19:33 +0100)
Add possibility to use content objects as Fluid
template source.

This adds a new property "template" to the FLUIDTEMPLATE
cObj to be in line with the TEMPLATE cObj

Resolves: #39767
Releases: 6.1

Change-Id: Iacd291f503ab88fb530f3b439e26cb755d17dee2
Reviewed-on: https://review.typo3.org/16241
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/frontend/Classes/ContentObject/FluidTemplateContentObject.php
typo3/sysext/frontend/Tests/Unit/ContentObject/FluidTemplateContentObjectTest.php

index 92c5c6a..b907205 100644 (file)
@@ -44,6 +44,9 @@ class FluidTemplateContentObject extends \TYPO3\CMS\Frontend\ContentObject\Abstr
         */
        protected $view = NULL;
 
+       /**
+        * Constructor
+        */
        public function __construct(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObjectRenderer) {
                parent::__construct($contentObjectRenderer);
        }
@@ -63,7 +66,8 @@ class FluidTemplateContentObject extends \TYPO3\CMS\Frontend\ContentObject\Abstr
         *
         * Example:
         * 10 = FLUIDTEMPLATE
-        * 10.file = fileadmin/templates/mytemplate.html
+        * 10.template = FILE
+        * 10.template.file = fileadmin/templates/mytemplate.html
         * 10.partialRootPath = fileadmin/templates/partial/
         * 10.variables {
         *   mylabel = TEXT
@@ -111,14 +115,20 @@ class FluidTemplateContentObject extends \TYPO3\CMS\Frontend\ContentObject\Abstr
         *
         * @param array $conf With possibly set file resource
         * @return void
+        * @throws \InvalidArgumentException
         */
        protected function setTemplate(array $conf) {
                // Fetch the Fluid template
-               $file = isset($conf['file.']) ? $this->cObj->stdWrap($conf['file'], $conf['file.']) : $conf['file'];
-               /** @var $templateService \TYPO3\CMS\Core\TypoScript\TemplateService */
-               $templateService = $GLOBALS['TSFE']->tmpl;
-               $templatePathAndFilename = $templateService->getFileName($file);
-               $this->view->setTemplatePathAndFilename($templatePathAndFilename);
+               if (!empty($conf['template']) && !empty($conf['template.'])) {
+                       $templateSource = $this->cObj->cObjGetSingle($conf['template'], $conf['template.']);
+                       $this->view->setTemplateSource($templateSource);
+               } else {
+                       $file = isset($conf['file.']) ? $this->cObj->stdWrap($conf['file'], $conf['file.']) : $conf['file'];
+                       /** @var $templateService \TYPO3\CMS\Core\TypoScript\TemplateService */
+                       $templateService = $GLOBALS['TSFE']->tmpl;
+                       $templatePathAndFilename = $templateService->getFileName($file);
+                       $this->view->setTemplatePathAndFilename($templatePathAndFilename);
+               }
        }
 
        /**
@@ -128,6 +138,7 @@ class FluidTemplateContentObject extends \TYPO3\CMS\Frontend\ContentObject\Abstr
         * @return void
         */
        protected function setLayoutRootPath(array $conf) {
+               // Override the default layout path via typoscript
                $layoutRootPath = isset($conf['layoutRootPath.']) ? $this->cObj->stdWrap($conf['layoutRootPath'], $conf['layoutRootPath.']) : $conf['layoutRootPath'];
                if ($layoutRootPath) {
                        $layoutRootPath = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($layoutRootPath);
@@ -252,4 +263,4 @@ class FluidTemplateContentObject extends \TYPO3\CMS\Frontend\ContentObject\Abstr
        }
 
 }
-?>
\ No newline at end of file
+?>
index 19d1916..8f1e3ed 100644 (file)
@@ -147,6 +147,31 @@ class FluidTemplateContentObjectTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
        /**
         * @test
         */
+       public function renderSetsTemplateFileByTemplateInView() {
+               $this->addMockViewToFixture();
+
+               $this->contentObjectRenderer
+                       ->expects($this->any())
+                       ->method('cObjGetSingle')
+                       ->with('FILE', array('file' => PATH_site . 'foo/bar.html'))
+                       ->will($this->returnValue('baz'));
+
+               $this->standaloneView
+                       ->expects($this->any())
+                       ->method('setTemplateSource')
+                       ->with('baz');
+
+               $this->fixture->render(array(
+                       'template' => 'FILE',
+                       'template.' => array(
+                               'file' => PATH_site . 'foo/bar.html'
+                       )
+               ));
+       }
+
+       /**
+        * @test
+        */
        public function renderSetsLayoutRootPathInView() {
                $this->addMockViewToFixture();
                $this->standaloneView
@@ -501,4 +526,4 @@ class FluidTemplateContentObjectTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
                $this->fixture->render($configuration);
        }
 }
-?>
\ No newline at end of file
+?>