‪TYPO3CMS  11.5
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 
25 class ResourceUtility
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 
58  public static function getAdditionalResourcesForModule(ResourceProviderInterface $module): array
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" 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 rel="stylesheet" href="' .
99  htmlspecialchars(
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(
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 = self::getJsTag($jsFileLocation);
133  $cssFileLocation = 'EXT:adminpanel/Resources/Public/Css/adminpanel.css';
134  $css = self::getCssTag($cssFileLocation);
135 
136  return [
137  'css' => $css . self::getAdminPanelStylesheet(),
138  'js' => $js,
139  ];
140  }
141 }
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:25
‪TYPO3\CMS\Adminpanel\Utility
Definition: MemoryUtility.php:18
‪TYPO3\CMS\Core\Utility\PathUtility\getPublicResourceWebPath
‪static string getPublicResourceWebPath(string $resourcePath, bool $prefixWithSitePath=true)
Definition: PathUtility.php:98
‪TYPO3\CMS\Adminpanel\ModuleApi\ResourceProviderInterface
Definition: ResourceProviderInterface.php:27
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Adminpanel\ModuleApi\SubmoduleProviderInterface
Definition: SubmoduleProviderInterface.php:30