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