* @owner University of Latvia * @version 2.1.0 * @since 14.08.2018 * * @package Lu\LuStudyCatalogue\ViewHelpers */ class IncludeFileViewHelper extends AbstractViewHelper implements ViewHelperInterface { use CompileWithRenderStatic; /** * Initialize arguments */ public function initializeArguments() { $this->registerArgument('path', 'string', 'Path to the CSS/JS file which should be included', true); $this->registerArgument('compress', 'bool', 'Define if file should be compressed', false, false); } /** * @param array $arguments * @param \Closure $renderChildrenClosure * @param \TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface $renderingContext * * @return mixed|string|void */ public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) { $path = $arguments['path']; $fileExists = file_exists(GeneralUtility::getFileAbsFileName($path)); $compress = (bool)$arguments['compress']; $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); if (!$fileExists) { return; } if (TYPO3_MODE === 'FE') { $sanitizer = GeneralUtility::makeInstance(FilePathSanitizer::class); $path = $sanitizer->sanitize($path); // JS if (strtolower(substr($path, -3)) === '.js') { $pageRenderer->addJsFooterFile($path, null, $compress); // CSS } else if (strtolower(substr($path, -4)) === '.css') { $pageRenderer->addCssFile($path, 'stylesheet', 'all', '', $compress); } } else { // JS if (strtolower(substr($path, -3)) === '.js') { $pageRenderer->addJsFooterFile($path, null, $compress); // CSS } else if (strtolower(substr($path, -4)) === '.css') { $pageRenderer->addCssFile($path, 'stylesheet', 'all', '', $compress); } } } }