[TASK] Use getAbsoluteWebPath instead of extRelPath 83/46583/5
authorBenni Mack <benni@typo3.org>
Thu, 11 Feb 2016 07:37:20 +0000 (08:37 +0100)
committerFrank Naegler <frank.naegler@typo3.org>
Fri, 12 Feb 2016 10:57:11 +0000 (11:57 +0100)
In order to be more flexible for path resolving,
a lot of occurrences in the TYPO3 Backend for
javascript and css files are replaced by
using the absoluteWebPath() option now
instead of working with extRelPath.

Target goal is to get rid of extRelPath
in the future, avoiding the gap between frontend and backend mode checks.

Resolves: #73225
Releases: master
Change-Id: Id529aae0741e67427c4806ac586bdc219d3e83b5
Reviewed-on: https://review.typo3.org/46583
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Markus Sommer <markussom@posteo.de>
Tested-by: Markus Sommer <markussom@posteo.de>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
typo3/sysext/backend/Classes/Controller/BackendController.php
typo3/sysext/backend/Classes/Template/DocumentTemplate.php
typo3/sysext/core/Classes/Page/PageRenderer.php
typo3/sysext/form/Classes/View/Wizard/WizardView.php
typo3/sysext/install/Classes/Controller/BackendModuleController.php
typo3/sysext/rtehtmlarea/Classes/SelectImage.php
typo3/sysext/taskcenter/Classes/Controller/TaskModuleController.php
typo3/sysext/workspaces/Classes/Controller/AbstractController.php

index 4f35182..ca81398 100644 (file)
@@ -24,6 +24,7 @@ use TYPO3\CMS\Core\Page\PageRenderer;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 use TYPO3\CMS\Fluid\View\StandaloneView;
 use TYPO3\CMS\Rsaauth\RsaEncryptionEncoder;
 
@@ -182,16 +183,16 @@ class BackendController
             foreach ($GLOBALS['TBE_MODULES']['_configuration'] as $moduleConfig) {
                 if (is_array($moduleConfig['cssFiles'])) {
                     foreach ($moduleConfig['cssFiles'] as $cssFileName => $cssFile) {
-                        $files = array(\TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($cssFile));
-                        $files = \TYPO3\CMS\Core\Utility\GeneralUtility::removePrefixPathFromList($files, PATH_site);
-                        $TYPO3backend->addCssFile($cssFileName, '../' . $files[0]);
+                        $cssFile = GeneralUtility::getFileAbsFileName($cssFile);
+                        $cssFile = PathUtility::getAbsoluteWebPath($cssFile);
+                        $TYPO3backend->addCssFile($cssFileName, $cssFile);
                     }
                 }
                 if (is_array($moduleConfig['jsFiles'])) {
                     foreach ($moduleConfig['jsFiles'] as $jsFile) {
-                        $files = array(\TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($jsFile));
-                        $files = \TYPO3\CMS\Core\Utility\GeneralUtility::removePrefixPathFromList($files, PATH_site);
-                        $TYPO3backend->addJavascriptFile('../' . $files[0]);
+                        $jsFile = GeneralUtility::getFileAbsFileName($jsFile);
+                        $jsFile = PathUtility::getAbsoluteWebPath($jsFile);
+                        $TYPO3backend->addJavascriptFile($jsFile);
                     }
                 }
             }
index 75806ed..de49fc0 100644 (file)
@@ -23,6 +23,7 @@ use TYPO3\CMS\Core\Page\PageRenderer;
 use TYPO3\CMS\Core\Service\MarkerBasedTemplateService;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 
 /**
  * TYPO3 Backend Template Class
@@ -300,7 +301,7 @@ function jumpToUrl(URL) {
         }
         // include all stylesheets
         foreach ($this->getSkinStylesheetDirectories() as $stylesheetDirectory) {
-            $this->addStylesheetDirectory($stylesheetDirectory);
+            $this->addStyleSheetDirectory($stylesheetDirectory);
         }
     }
 
@@ -901,15 +902,11 @@ function jumpToUrl(URL) {
      */
     public function addStyleSheetDirectory($path)
     {
-        // Calculation needed, when TYPO3 source is used via a symlink
-        // absolute path to the stylesheets
-        $filePath = GeneralUtility::getFileAbsFileName($path, false, true);
-        // Clean the path
-        $resolvedPath = GeneralUtility::resolveBackPath($filePath);
+        $path = GeneralUtility::getFileAbsFileName($path);
         // Read all files in directory and sort them alphabetically
-        $files = GeneralUtility::getFilesInDir($resolvedPath, 'css', false, 1);
-        foreach ($files as $file) {
-            $this->pageRenderer->addCssFile($path . $file, 'stylesheet', 'all');
+        $cssFiles = GeneralUtility::getFilesInDir($path, 'css');
+        foreach ($cssFiles as $cssFile) {
+            $this->pageRenderer->addCssFile(PathUtility::getAbsoluteWebPath($path . $cssFile));
         }
     }
 
@@ -956,11 +953,11 @@ function jumpToUrl(URL) {
                     if (substr($stylesheetDir, 0, 4) === 'EXT:') {
                         list($extKey, $path) = explode('/', substr($stylesheetDir, 4), 2);
                         if (!empty($extKey) && ExtensionManagementUtility::isLoaded($extKey) && !empty($path)) {
-                            $stylesheetDirectories[] = ExtensionManagementUtility::extRelPath($extKey) . $path;
+                            $stylesheetDirectories[] = ExtensionManagementUtility::extPath($extKey) . $path;
                         }
                     } else {
                         // For relative paths
-                        $stylesheetDirectories[] = ExtensionManagementUtility::extRelPath($skinExtKey) . $stylesheetDir;
+                        $stylesheetDirectories[] = ExtensionManagementUtility::extPath($skinExtKey) . $stylesheetDir;
                     }
                 }
             }
@@ -1497,6 +1494,6 @@ function jumpToUrl(URL) {
     */
     protected function getBackendFavicon()
     {
-        return $GLOBALS['TBE_STYLES']['favicon'] ?: ExtensionManagementUtility::extRelPath('backend') . 'Resources/Public/Icons/favicon.ico';
+        return PathUtility::getAbsoluteWebPath($GLOBALS['TBE_STYLES']['favicon'] ?: ExtensionManagementUtility::extPath('backend') . 'Resources/Public/Icons/favicon.ico');
     }
 }
index 12c10d9..30aef24 100644 (file)
@@ -21,6 +21,7 @@ use TYPO3\CMS\Core\Localization\LocalizationFactory;
 use TYPO3\CMS\Core\Service\MarkerBasedTemplateService;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
 
 /**
@@ -1561,31 +1562,32 @@ class PageRenderer implements \TYPO3\CMS\Core\SingletonInterface
             } else {
                 $this->requireJsConfig['urlArgs'] = 'bust=' . GeneralUtility::hmac(TYPO3_version . PATH_site);
             }
-            $coreRelPath = ExtensionManagementUtility::extRelPath('core');
+            $corePath = ExtensionManagementUtility::extPath('core', 'Resources/Public/JavaScript/Contrib/');
+            $corePath = PathUtility::getAbsoluteWebPath($corePath);
             // first, load all paths for the namespaces, and configure contrib libs.
             $this->requireJsConfig['paths'] = array(
-                'jquery-ui' => $this->backPath . $coreRelPath . 'Resources/Public/JavaScript/Contrib/jquery-ui',
-                'datatables' => $this->backPath . $coreRelPath . 'Resources/Public/JavaScript/Contrib/jquery.dataTables',
-                'nprogress' => $this->backPath . $coreRelPath . 'Resources/Public/JavaScript/Contrib/nprogress',
-                'moment' => $this->backPath . $coreRelPath . 'Resources/Public/JavaScript/Contrib/moment',
-                'cropper' => $this->backPath . $coreRelPath . 'Resources/Public/JavaScript/Contrib/cropper.min',
-                'imagesloaded' => $this->backPath . $coreRelPath . 'Resources/Public/JavaScript/Contrib/imagesloaded.pkgd.min',
-                'bootstrap' => $this->backPath . $coreRelPath . 'Resources/Public/JavaScript/Contrib/bootstrap/bootstrap',
-                'twbs/bootstrap-datetimepicker' => $this->backPath . $coreRelPath . 'Resources/Public/JavaScript/Contrib/bootstrap-datetimepicker',
-                'autosize' => $this->backPath . $coreRelPath . 'Resources/Public/JavaScript/Contrib/autosize',
-                'taboverride' => $this->backPath . $coreRelPath . 'Resources/Public/JavaScript/Contrib/taboverride.min',
-                'twbs/bootstrap-slider' => $this->backPath . $coreRelPath . 'Resources/Public/JavaScript/Contrib/bootstrap-slider.min',
-                'jquery/autocomplete' => $this->backPath . $coreRelPath . 'Resources/Public/JavaScript/Contrib/jquery.autocomplete',
+                'jquery-ui' => $corePath . 'jquery-ui',
+                'datatables' => $corePath . 'jquery.dataTables',
+                'nprogress' => $corePath . 'nprogress',
+                'moment' => $corePath . 'moment',
+                'cropper' => $corePath . 'cropper.min',
+                'imagesloaded' => $corePath . 'imagesloaded.pkgd.min',
+                'bootstrap' => $corePath . 'bootstrap/bootstrap',
+                'twbs/bootstrap-datetimepicker' => $corePath . 'bootstrap-datetimepicker',
+                'autosize' => $corePath . 'autosize',
+                'taboverride' => $corePath . 'taboverride.min',
+                'twbs/bootstrap-slider' => $corePath . 'bootstrap-slider.min',
+                'jquery/autocomplete' => $corePath . 'jquery.autocomplete',
             );
             // get all extensions that are loaded
-            $loadedExtensions = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getLoadedExtensionListArray();
+            $loadedExtensions = ExtensionManagementUtility::getLoadedExtensionListArray();
             foreach ($loadedExtensions as $packageName) {
                 $fullJsPath = 'EXT:' . $packageName . '/Resources/Public/JavaScript/';
                 $fullJsPath = GeneralUtility::getFileAbsFileName($fullJsPath);
-                $fullJsPath = \TYPO3\CMS\Core\Utility\PathUtility::getRelativePath(PATH_typo3, $fullJsPath);
+                $fullJsPath = PathUtility::getAbsoluteWebPath($fullJsPath);
                 $fullJsPath = rtrim($fullJsPath, '/');
                 if ($fullJsPath) {
-                    $this->requireJsConfig['paths']['TYPO3/CMS/' . GeneralUtility::underscoredToUpperCamelCase($packageName)] = $this->backPath . $fullJsPath;
+                    $this->requireJsConfig['paths']['TYPO3/CMS/' . GeneralUtility::underscoredToUpperCamelCase($packageName)] = $fullJsPath;
                 }
             }
 
index 2a56f42..3de6f76 100644 (file)
@@ -21,6 +21,7 @@ use TYPO3\CMS\Core\Messaging\FlashMessage;
 use TYPO3\CMS\Core\Page\PageRenderer;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 use TYPO3\CMS\Form\Domain\Repository\ContentRepository;
 
 /**
@@ -250,16 +251,14 @@ class WizardView
      */
     protected function loadCss()
     {
-        // @todo Set to TRUE when finished
-        $compress = false;
         $cssFiles = array(
             'Wizard/Form.css',
             'Wizard/Wizard.css'
         );
-        $baseUrl = ExtensionManagementUtility::extRelPath('form') . 'Resources/Public/CSS/';
+        $baseUrl = ExtensionManagementUtility::extPath('form') . 'Resources/Public/CSS/';
         // Load the wizards css
         foreach ($cssFiles as $cssFile) {
-            $this->getPageRenderer()->addCssFile($baseUrl . $cssFile, 'stylesheet', 'all', '', $compress, false);
+            $this->getPageRenderer()->addCssFile(PathUtility::getAbsoluteWebPath($baseUrl . $cssFile));
         }
     }
 
index b905602..8337e4f 100644 (file)
@@ -21,6 +21,7 @@ use TYPO3\CMS\Core\FormProtection\AbstractFormProtection;
 use TYPO3\CMS\Core\FormProtection\FormProtectionFactory;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 use TYPO3\CMS\Fluid\View\StandaloneView;
 use TYPO3\CMS\Install\Service\EnableFileService;
 
@@ -67,16 +68,15 @@ class BackendModuleController
             /** @var StandaloneView $view */
             $view = GeneralUtility::makeInstance(StandaloneView::class);
             $view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName(
-                'EXT:install/Resources/Private/Templates/BackendModule/ShowEnableInstallToolButton.html', false)
+                'EXT:install/Resources/Private/Templates/BackendModule/ShowEnableInstallToolButton.html')
             );
             $token = $formProtection->generateToken('installTool');
             $view->assign('installToolEnableToken', $token);
             /** @var ModuleTemplate $moduleTemplate */
             $moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
-            $pageRenderer = $moduleTemplate->getPageRenderer();
-            $pageRenderer->addCssFile(
-                ExtensionManagementUtility::extRelPath('install') . 'Resources/Public/Css/BackendModule/ShowEnableInstallToolButton.css'
-            );
+            $cssFile = 'EXT:install/Resources/Public/Css/BackendModule/ShowEnableInstallToolButton.css';
+            $cssFile = GeneralUtility::getFileAbsFileName($cssFile);
+            $moduleTemplate->getPageRenderer()->addCssFile(PathUtility::getAbsoluteWebPath($cssFile));
             $moduleTemplate->setContent($view->render());
             $response->getBody()->write($moduleTemplate->renderContent());
         }
index bbdf0ae..4c8ee3e 100644 (file)
@@ -177,7 +177,6 @@ class SelectImage extends ElementBrowser
         $this->doc->bodyTagAdditions = 'onload="SelectImage.initEventListeners();"';
 
         $pageRenderer = $this->getPageRenderer();
-        $pageRenderer->addCssFile(ExtensionManagementUtility::extRelPath('t3skin') . 'rtehtmlarea/htmlarea.css');
         $pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LegacyTree', 'function(Tree) {
                        Tree.ajaxID = "sc_alt_file_navframe_expandtoggle";
                }');
index 5edbf63..950ff8f 100644 (file)
@@ -57,7 +57,8 @@ class TaskModuleController extends BaseScriptClass
     public function __construct()
     {
         $this->moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class);
-        $this->moduleTemplate->getPageRenderer()->addCssFile(ExtensionManagementUtility::extRelPath('taskcenter') . 'Resources/Public/Css/styles.css');
+        $cssFile = GeneralUtility::getFileAbsFileName('EXT:taskcenter/Resources/Public/Css/styles.css');
+        $this->moduleTemplate->getPageRenderer()->addCssFile(PathUtility::getAbsoluteWebPath($cssFile));
         $this->getLanguageService()->includeLLFile('EXT:taskcenter/Resources/Private/Language/locallang_task.xlf');
         $this->MCONF = array(
             'name' => $this->moduleName
index 36d6a62..4da6082 100644 (file)
@@ -19,6 +19,7 @@ use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Imaging\IconFactory;
 use TYPO3\CMS\Core\Page\PageRenderer;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
 
 /**
  * Abstract action controller.
@@ -73,7 +74,9 @@ class AbstractController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControl
         $this->pageRenderer->addInlineSetting('Workspaces', 'id', $this->pageId);
         $this->pageRenderer->addInlineSetting('Workspaces', 'depth', $this->pageId === 0 ? 999 : 1);
         $this->pageRenderer->addInlineSetting('Workspaces', 'language', $this->getLanguageSelection());
-        $this->pageRenderer->addCssFile(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('workspaces') . 'Resources/Public/Css/module.css');
+        $cssFile = 'EXT:workspaces/Resources/Public/Css/module.css';
+        $cssFile = GeneralUtility::getFileAbsFileName($cssFile);
+        $this->pageRenderer->addCssFile(PathUtility::getAbsoluteWebPath($cssFile));
         $this->pageRenderer->addInlineLanguageLabelArray(array(
             'title' => $GLOBALS['LANG']->getLL('title'),
             'path' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.path'),