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