‪TYPO3CMS  10.4
ResourceViewHelper.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
20 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
21 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
22 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
23 
54 class ‪ResourceViewHelper extends AbstractViewHelper
55 {
56  use CompileWithRenderStatic;
57 
61  public function ‪initializeArguments()
62  {
63  $this->registerArgument('path', 'string', 'The path and filename of the resource (relative to Public resource directory of the extension).', true);
64  $this->registerArgument('extensionName', 'string', 'Target extension name. If not set, the current extension name will be used');
65  $this->registerArgument('absolute', 'bool', 'If set, an absolute URI is rendered', false, false);
66  }
67 
76  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
77  {
78  $path = $arguments['path'];
79  $extensionName = $arguments['extensionName'];
80  $absolute = $arguments['absolute'];
81 
82  if ($extensionName === null) {
83  $extensionName = $renderingContext->getControllerContext()->getRequest()->getControllerExtensionName();
84  }
85  $uri = 'EXT:' . ‪GeneralUtility::camelCaseToLowerCaseUnderscored($extensionName) . '/Resources/Public/' . $path;
86  $uri = GeneralUtility::getFileAbsFileName($uri);
87  if ($absolute === false && $uri !== false) {
89  }
90  if ($absolute === true) {
92  $uri = $renderingContext->getControllerContext()->getRequest()->getBaseUri() . $uri;
93  }
94  return $uri;
95  }
96 }
‪TYPO3\CMS\Core\Utility\PathUtility
Definition: PathUtility.php:24
‪TYPO3\CMS\Fluid\ViewHelpers\Uri\ResourceViewHelper
Definition: ResourceViewHelper.php:55
‪TYPO3\CMS\Core\Utility\PathUtility\stripPathSitePrefix
‪static string stripPathSitePrefix($path)
Definition: PathUtility.php:372
‪TYPO3\CMS\Core\Utility\GeneralUtility\camelCaseToLowerCaseUnderscored
‪static string camelCaseToLowerCaseUnderscored($string)
Definition: GeneralUtility.php:914
‪TYPO3\CMS\Fluid\ViewHelpers\Uri\ResourceViewHelper\initializeArguments
‪initializeArguments()
Definition: ResourceViewHelper.php:60
‪TYPO3\CMS\Fluid\ViewHelpers\Uri\ResourceViewHelper\renderStatic
‪static string renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: ResourceViewHelper.php:75
‪TYPO3\CMS\Fluid\ViewHelpers\Uri
Definition: ActionViewHelper.php:16
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Utility\PathUtility\getAbsoluteWebPath
‪static string getAbsoluteWebPath($targetPath)
Definition: PathUtility.php:43