‪TYPO3CMS  9.5
ResourceUtility.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
23 
25 {
33  public static function ‪getAdditionalResourcesForModules(array $modules): array
34  {
35  $result = [
36  'js' => '',
37  'css' => '',
38  ];
39  foreach ($modules as $module) {
40  if ($module instanceof ‪ResourceProviderInterface) {
41  foreach ($module->getJavaScriptFiles() as $file) {
42  $result['js'] .= static::getJsTag($file);
43  }
44  foreach ($module->getCssFiles() as $file) {
45  $result['css'] .= static::getCssTag($file);
46  }
47  }
48  if ($module instanceof ‪SubmoduleProviderInterface) {
49  $subResult = ‪self::getAdditionalResourcesForModules($module->getSubModules());
50  $result['js'] .= $subResult['js'];
51  $result['css'] .= $subResult['css'];
52  }
53  }
54  return $result;
55  }
56 
58  {
59  $result = [
60  'js' => '',
61  'css' => '',
62  ];
63  foreach ($module->‪getJavaScriptFiles() as $file) {
64  $result['js'] .= static::getJsTag($file);
65  }
66  foreach ($module->‪getCssFiles() as $file) {
67  $result['css'] .= static::getCssTag($file);
68  }
69  return $result;
70  }
71 
78  protected static function ‪getAdminPanelStylesheet(): string
79  {
80  $result = '';
81  if (!empty(‪$GLOBALS['TBE_STYLES']['stylesheets']['admPanel'])) {
82  $stylesheet = GeneralUtility::locationHeaderUrl(‪$GLOBALS['TBE_STYLES']['stylesheets']['admPanel']);
83  $result = '<link rel="stylesheet" type="text/css" href="' .
84  htmlspecialchars($stylesheet, ENT_QUOTES | ENT_HTML5) . '" />';
85  }
86  return $result;
87  }
88 
95  protected static function ‪getCssTag(string $cssFileLocation): string
96  {
97  $css = '<link type="text/css" rel="stylesheet" href="' .
98  htmlspecialchars(
99  ‪PathUtility::getAbsoluteWebPath(GeneralUtility::getFileAbsFileName($cssFileLocation)),
100  ENT_QUOTES | ENT_HTML5
101  ) .
102  '" media="all" />';
103  return $css;
104  }
105 
112  protected static function ‪getJsTag(string $jsFileLocation): string
113  {
114  $js = '<script type="text/javascript" src="' .
115  htmlspecialchars(
116  ‪PathUtility::getAbsoluteWebPath(GeneralUtility::getFileAbsFileName($jsFileLocation)),
117  ENT_QUOTES | ENT_HTML5
118  ) .
119  '"></script>';
120  return $js;
121  }
122 
128  public static function ‪getResources(): array
129  {
130  $jsFileLocation = 'EXT:adminpanel/Resources/Public/JavaScript/AdminPanel.js';
131  $js = ‪ResourceUtility::getJsTag($jsFileLocation);
132  $cssFileLocation = 'EXT:adminpanel/Resources/Public/Css/adminpanel.css';
133  $css = ‪ResourceUtility::getCssTag($cssFileLocation);
134 
135  return [
137  'js' => $js,
138  ];
139  }
140 }
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:23
‪TYPO3\CMS\Adminpanel\Utility
Definition: MemoryUtility.php:4
‪TYPO3\CMS\Adminpanel\Utility\ResourceUtility\getResources
‪static array getResources()
Definition: ResourceUtility.php:128
‪TYPO3\CMS\Adminpanel\Utility\ResourceUtility\getAdditionalResourcesForModule
‪static getAdditionalResourcesForModule(ResourceProviderInterface $module)
Definition: ResourceUtility.php:57
‪TYPO3\CMS\Adminpanel\ModuleApi\ResourceProviderInterface\getCssFiles
‪array getCssFiles()
‪TYPO3\CMS\Adminpanel\ModuleApi\ResourceProviderInterface\getJavaScriptFiles
‪array getJavaScriptFiles()
‪TYPO3\CMS\Adminpanel\Utility\ResourceUtility\getCssTag
‪static string getCssTag(string $cssFileLocation)
Definition: ResourceUtility.php:95
‪TYPO3\CMS\Adminpanel\ModuleApi\ResourceProviderInterface
Definition: ResourceProviderInterface.php:26
‪TYPO3\CMS\Adminpanel\Utility\ResourceUtility\getAdminPanelStylesheet
‪static string getAdminPanelStylesheet()
Definition: ResourceUtility.php:78
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Adminpanel\Utility\ResourceUtility\getAdditionalResourcesForModules
‪static array getAdditionalResourcesForModules(array $modules)
Definition: ResourceUtility.php:33
‪TYPO3\CMS\Adminpanel\Utility\ResourceUtility
Definition: ResourceUtility.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Utility\PathUtility\getAbsoluteWebPath
‪static string getAbsoluteWebPath($targetPath)
Definition: PathUtility.php:42
‪TYPO3\CMS\Adminpanel\ModuleApi\SubmoduleProviderInterface
Definition: SubmoduleProviderInterface.php:29
‪TYPO3\CMS\Adminpanel\Utility\ResourceUtility\getJsTag
‪static string getJsTag(string $jsFileLocation)
Definition: ResourceUtility.php:112