[FEATURE] Allow .ts file extension for static typoscript templates 64/40264/6
authorPierrick Caillon <pierrick.caillon@plan-net.fr>
Mon, 15 Jun 2015 17:20:01 +0000 (19:20 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Tue, 16 Jun 2015 09:17:38 +0000 (11:17 +0200)
Static TypoScript support alternative primary names for constants and
setup file:
* constants.ts
* setup.ts

Old names are still working:
* constants.txt
* setup.txt

Resolves: #34922
Releases: master
Change-Id: I6868c22c95337812e6946f16655f024f2ed80471
Reviewed-on: http://review.typo3.org/40264
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Classes/TypoScript/TemplateService.php
typo3/sysext/core/Documentation/Changelog/master/Feature-34922-AllowTsFileExtensionForStaticTyposcriptTemplates.rst [new file with mode: 0644]

index 1949dfa..c6adb1f 100644 (file)
@@ -788,8 +788,8 @@ class TemplateService {
                                                if (@is_dir($ISF_filePath)) {
                                                        $mExtKey = str_replace('_', '', $ISF_extKey . '/' . $ISF_localPath);
                                                        $subrow = array(
-                                                               'constants' => @file_exists(($ISF_filePath . 'constants.txt')) ? GeneralUtility::getUrl($ISF_filePath . 'constants.txt') : '',
-                                                               'config' => @file_exists(($ISF_filePath . 'setup.txt')) ? GeneralUtility::getUrl($ISF_filePath . 'setup.txt') : '',
+                                                               'constants' => $this->getTypoScriptSourceFileContent($ISF_filePath, 'constants'),
+                                                               'config' => $this->getTypoScriptSourceFileContent($ISF_filePath, 'setup'),
                                                                'include_static' => @file_exists(($ISF_filePath . 'include_static.txt')) ? implode(',', array_unique(GeneralUtility::intExplode(',', GeneralUtility::getUrl($ISF_filePath . 'include_static.txt')))) : '',
                                                                'include_static_file' => @file_exists(($ISF_filePath . 'include_static_file.txt')) ? implode(',', array_unique(explode(',', GeneralUtility::getUrl($ISF_filePath . 'include_static_file.txt')))) : '',
                                                                'title' => $ISF_file,
@@ -822,6 +822,25 @@ class TemplateService {
        }
 
        /**
+        * Retrieves the content of the first existing file by extension order.
+        * Returns the empty string if no file is found.
+        *
+        * @param string $filePath The location of the file.
+        * @param string $baseName The base file name. "constants" or "setup".
+        * @return string
+        */
+       protected function getTypoScriptSourceFileContent($filePath, $baseName) {
+               $extensions = array('.ts', '.txt');
+               foreach ($extensions as $extension) {
+                       $fileName = $filePath . $baseName . $extension;
+                       if (@file_exists($fileName)) {
+                               return GeneralUtility::getUrl($fileName);
+                       }
+               }
+               return '';
+       }
+
+       /**
         * Adds the default TypoScript files for extensions if any.
         *
         * @param string $idList A list of already processed template ids including the current; The list is on the form "[prefix]_[uid]" where [prefix] is "sys" for "sys_template" records, "static" for "static_template" records and "ext_" for static include files (from extensions). The list is used to check that the recursive inclusion of templates does not go into circles: Simply it is used to NOT include a template record/file which has already BEEN included somewhere in the recursion.
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-34922-AllowTsFileExtensionForStaticTyposcriptTemplates.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-34922-AllowTsFileExtensionForStaticTyposcriptTemplates.rst
new file mode 100644 (file)
index 0000000..fb3aa7e
--- /dev/null
@@ -0,0 +1,20 @@
+==========================================================================
+Feature: #34922 - Allow .ts file extension for static TypoScript templates
+==========================================================================
+
+Description
+===========
+
+Only these TypoScript file names were allowed:
+- constants.txt
+- setup.txt
+- include_static.txt
+- include_static_files.txt
+
+The ts file extension has been allowed for constants and setup and is prioritised over txt.
+
+
+Impact
+======
+
+There is a little performance impact when loading the TypoScript from scratch like in the backend and frontend without cache as the new extension is always tested.