Commit b9a195ce authored by Kevin Ditscheid's avatar Kevin Ditscheid

[TASK] Adapt ViewHelpers for TYPO3 9

parent b687566e
......@@ -27,6 +27,7 @@ namespace SGalinski\Lfeditor\ViewHelpers;
***************************************************************/
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper;
/**
......@@ -39,7 +40,7 @@ class AbstractViewHelper extends AbstractBackendViewHelper {
* @return PageRenderer
*/
public function getPageRenderer() {
return $this->objectManager->get(PageRenderer::class);
return GeneralUtility::makeInstance(PageRenderer::class);
}
/**
......@@ -58,4 +59,4 @@ class AbstractViewHelper extends AbstractBackendViewHelper {
return $baseUrl;
}
}
\ No newline at end of file
}
......@@ -2,29 +2,29 @@
namespace SGalinski\Lfeditor\ViewHelpers;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (https://www.sgalinski.de)
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (https://www.sgalinski.de)
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* View helper to add custom css files
......@@ -34,14 +34,22 @@ namespace SGalinski\Lfeditor\ViewHelpers;
* <lfe:addCssFile cssFile="{f:uri.resource(path: 'StyleSheets/Frontend.css')}" />
*/
class AddCssFileViewHelper extends AbstractViewHelper {
/**
* Register the ViewHelper arguments
*/
public function initializeArguments() {
parent::initializeArguments();
$this->registerArgument('cssFile', 'string', 'The css file to include', TRUE);
}
/**
* Adds a custom css file
*
* @param string $cssFile
* @return void
*/
public function render($cssFile) {
$cssFile = (TYPO3_MODE === 'FE' ? $this->getBaseUrl() : '') . $cssFile;
public function render() {
$cssFile = (TYPO3_MODE === 'FE' ? $this->getBaseUrl() : '') . $this->arguments['cssFile'];
$this->getPageRenderer()->addCssFile($cssFile, 'stylesheet', 'all', '', FALSE);
}
}
......@@ -2,29 +2,29 @@
namespace SGalinski\Lfeditor\ViewHelpers;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (https://www.sgalinski.de)
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (https://www.sgalinski.de)
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* View helper to add custom javascript files
......@@ -34,14 +34,22 @@ namespace SGalinski\Lfeditor\ViewHelpers;
* <lfe:addJavaScriptFile javaScriptFile="{f:uri.resource(path: 'Scripts/Frontend.js')}" />
*/
class AddJavaScriptFileViewHelper extends AbstractViewHelper {
/**
* Register the ViewHelper arguments
*/
public function initializeArguments() {
parent::initializeArguments();
$this->registerArgument('javaScriptFile', 'string', 'The JavaScript file to include', TRUE);
}
/**
* Adds a custom javascript file
*
* @param string $javaScriptFile
* @return void
*/
public function render($javaScriptFile) {
$javaScriptFile = (TYPO3_MODE === 'FE' ? $this->getBaseUrl() : '') . $javaScriptFile;
public function render() {
$javaScriptFile = (TYPO3_MODE === 'FE' ? $this->getBaseUrl() : '') . $this->arguments['javaScriptFile'];
$this->getPageRenderer()->addJsFile($javaScriptFile);
}
}
......@@ -26,7 +26,7 @@ namespace SGalinski\Lfeditor\ViewHelpers\Be\Menus;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
/**
* Class ActionMenuOptionGroupViewHelper
......
......@@ -26,8 +26,7 @@ namespace SGalinski\Lfeditor\ViewHelpers;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
/**
* ExtendedIfViewHelper
......@@ -41,14 +40,7 @@ class ExtendedIfViewHelper extends AbstractConditionViewHelper {
*/
public function initializeArguments() {
parent::initializeArguments();
$version = VersionNumberUtility::getNumericTypo3Version();
// ensure compatibility with both TYPO3 versions >= and < 8
if (VersionNumberUtility::convertVersionNumberToInteger($version) < 8000000) {
$this->registerArgument(
'condition', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, FALSE
);
}
$this->registerArgument(
'or', 'boolean', 'Condition expression conforming to Fluid boolean rules', FALSE, FALSE
);
......
......@@ -40,35 +40,52 @@ use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
* <rs:inlineLanguageLabels labels="label01,label02" />
*/
class InlineLanguageLabelsViewHelper extends AbstractViewHelper {
public function initializeArguments() {
parent::initializeArguments();
$this->registerArgument('labels', 'mixed', 'Comma separated list of label keys to include', FALSE, []);
$this->registerArgument('htmlEscape', 'bool', 'Escape the output', FALSE, FALSE);
}
/**
* Renders the required javascript to make the language labels available
*
* @param string|array $labels Comma separated list of label keys to include
* @param boolean $htmlEscape
* @return void
* @return string
*/
public function render($labels = '', $htmlEscape = FALSE) {
$extensionName = $this->controllerContext->getRequest()->getControllerExtensionName();
if (!\is_array($labels)) {
public function render(): string {
$labels = $this->arguments['labels'];
$htmlEscape = $this->arguments['htmlEscape'];
$controllerContext = $this->renderingContext->getControllerContext();
$extensionName = $controllerContext->getRequest()->getControllerExtensionName();
if (\is_string($labels)) {
$labels = GeneralUtility::trimExplode(',', $labels, TRUE);
}
if (!\is_array($labels)) {
throw new \InvalidArgumentException(
'The argument "labels" was registered with type "array|string", but is of type "' .
\gettype($labels) . '" in view helper "' . \get_class($this) . '".',
1256475113
);
}
$languageArray = [];
foreach ($labels as $key) {
$value = LocalizationUtility::translate($key, $extensionName);
$languageArray[$key] = ($htmlEscape ? htmlentities($value) : $value);
$languageArray[$key] = ($htmlEscape ? \htmlentities($value) : $value);
}
$javascriptCode = '
var AY = AY || {};
AY.lang = AY.lang || {};
AY.lang.' . $extensionName . ' = AY.lang.' . $extensionName . ' || {};
var languageLabels = ' . json_encode($languageArray) . ';
var languageLabels = ' . \json_encode($languageArray) . ';
for (label in languageLabels) {
AY.lang.' . $extensionName . '[label] = languageLabels[label];
}
';
$this->getPageRenderer()->addJsInlineCode($extensionName, $javascriptCode);
return '';
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment