Commit d20c2f56 authored by Kevin Ditscheid's avatar Kevin Ditscheid

[BUGFIX] Fix the ViewHelper argument registration

parent 3bb24ea2
......@@ -34,14 +34,22 @@ namespace SGalinski\SgRoutes\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 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,29 +26,41 @@ namespace SGalinski\SgRoutes\ViewHelpers\Backend;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use\TYPO3\CMS\Backend\Clipboard\Clipboard;
use TYPO3\CMS\Backend\Clipboard\Clipboard;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList;
/**
* Class ControlViewHelper
**/
class ControlViewHelper extends AbstractViewHelper {
/**
* Initialize the ViewHelper arguments
*/
public function initializeArguments() {
parent::initializeArguments();
$this->registerArgument('table', 'string', 'The table to control', TRUE);
$this->registerArgument('row', 'mixed', 'The row of the record', TRUE);
$this->registerArgument('sortingData', 'array', 'The sorting data', FALSE, []);
$this->registerArgument('clipboard', 'bool', 'Use the clipboard', FALSE, FALSE);
}
/**
* Renders the control buttons for the specified record
*
* @param string $table
* @param mixed $row
* @param array $sortingData
* @param boolean $clipboard
* @return string
* @throws \InvalidArgumentException
* @throws \UnexpectedValueException
*/
public function render($table, $row, $sortingData = [], $clipboard = FALSE) {
public function render() {
$table = $this->arguments['table'];
$row = $this->arguments['row'];
$sortingData = $this->arguments['sortingData'];
$clipboard = $this->arguments['clipboard'];
if (!is_array($row)) {
$row = BackendUtility::getRecord($table, $row->getUid());
}
......
......@@ -27,21 +27,28 @@ namespace SGalinski\SgRoutes\ViewHelpers\Backend;
***************************************************************/
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
* Class EditOnClickViewHelper
**/
class EditLinkViewHelper extends AbstractViewHelper {
public function initializeArguments() {
parent::initializeArguments();
$this->registerArgument('table', 'string', 'The table of the edit link', TRUE);
$this->registerArgument('uid', 'int', 'The uid of the record', TRUE);
$this->registerArgument('new', 'bool', 'Wether the record is new or not', FALSE, FALSE);
}
/**
* Renders the onclick script for editing a record
*
* @param string $table
* @param int $uid
* @param boolean $new
* @return string
*/
public function render($table, $uid, $new = FALSE) {
return BackendUtility::getModuleUrl('record_edit') . '&edit[' . $table . '][' . $uid . ']=' . ($new ? 'new' : 'edit');
public function render() {
return BackendUtility::getModuleUrl(
'record_edit'
) . '&edit[' . $this->arguments['table'] . '][' . $this->arguments['uid'] . ']=' . ($this->arguments['new'] ? 'new' : 'edit');
}
}
......@@ -27,21 +27,31 @@ namespace SGalinski\SgRoutes\ViewHelpers\Backend;
***************************************************************/
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
* Class EditOnClickViewHelper
**/
class EditOnClickViewHelper extends AbstractViewHelper {
/**
* Register the ViewHelper arguments
*/
public function initializeArguments() {
parent::initializeArguments();
$this->registerArgument('table', 'string', 'The table for the clickenlarge link', TRUE);
$this->registerArgument('uid', 'int', 'The uid of the record to clickenlarge', TRUE);
$this->registerArgument('new', 'bool', 'Open a new record in the popup', FALSE, FALSE);
}
/**
* Renders the onclick script for editing a record
*
* @param string $table
* @param int $uid
* @param boolean $new
* @return string
*/
public function render($table, $uid, $new = FALSE) {
return BackendUtility::editOnClick('&edit[' . $table . '][' . $uid . ']=' . ($new ? 'new' : 'edit'), '', -1);
public function render() {
return BackendUtility::editOnClick(
'&edit[' . $this->arguments['table'] . '][' . $this->arguments['uid'] . ']=' . ($this->arguments['new'] ? 'new' : 'edit'),
'', -1
);
}
}
......@@ -30,22 +30,33 @@ use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
* Class IconViewHelper
**/
class IconViewHelper extends AbstractViewHelper {
/**
* Register the ViewHelper arguments
*/
public function initializeArguments() {
parent::initializeArguments();
$this->registerArgument('table', 'string', 'The table for the icon', TRUE);
$this->registerArgument('row', 'mixed', 'The row of the record', TRUE);
$this->registerArgument('clickMenu', 'bool', 'Render a clickMenu around the icon', FALSE, TRUE);
}
/**
* Renders the icon for the specified record
*
* @param string $table
* @param mixed $row
* @param boolean $clickMenu
* @return string
* @throws \InvalidArgumentException
*/
public function render($table, $row, $clickMenu = TRUE) {
public function render() {
$row = $this->arguments['row'];
$table = $this->arguments['table'];
$clickMenu = $this->arguments['clickMenu'];
if (!is_array($row)) {
$row = BackendUtility::getRecord($table, $row->getUid());
}
......
<?php
namespace SGalinski\SgRoutes\ViewHelpers\Backend\Widget;
/***************************************************************
......@@ -24,6 +25,7 @@ namespace SGalinski\SgRoutes\ViewHelpers\Backend\Widget;
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use SGalinski\SgRoutes\ViewHelpers\Backend\Widget\Controller\PaginateController;
use TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetViewHelper;
......@@ -47,18 +49,33 @@ class PaginateViewHelper extends AbstractWidgetViewHelper {
$this->controller = $controller;
}
/**
* Initialize the ViewHelper arguments
*/
public function initializeArguments() {
parent::initializeArguments();
$this->registerArgument('objects', 'mixed', 'The objects to paginate', TRUE);
$this->registerArgument('as', 'string', 'The name of the variable inside the pagination', TRUE);
$this->registerArgument(
'configuration',
'array',
'The configuration of the pagination',
FALSE,
[
'itemsPerPage' => 10,
'insertAbove' => FALSE,
'insertBelow' => TRUE,
'recordsLabel' => ''
]
);
}
/**
* Renders the paginator
*
* @param mixed $objects
* @param string $as
* @param array $configuration
* @return string
*/
public function render(
$objects, $as,
array $configuration = ['itemsPerPage' => 10, 'insertAbove' => FALSE, 'insertBelow' => TRUE, 'recordsLabel' => '']
) {
public function render() {
return $this->initiateSubRequest();
}
}
......@@ -40,14 +40,24 @@ use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
* <rs:inlineLanguageLabels labels="label01,label02" />
*/
class InlineLanguageLabelsViewHelper extends AbstractViewHelper {
/**
* Register the ViewHelper arguments
*/
public function initializeArguments() {
parent::initializeArguments();
$this->registerArgument('labels', 'string', 'The labels to include', FALSE, '');
$this->registerArgument('htmlEscape', 'bool', 'Escape the output', FALSE, FALSE);
}
/**
* Renders the required javascript to make the language labels available
*
* @param string $labels Comma separated list of label keys to include
* @param boolean $htmlEscape
* @return string
*/
public function render($labels = '', $htmlEscape = FALSE) {
public function render() {
$labels = $this->arguments['labels'];
$htmlEscape = $this->arguments['htmlEscape'];
$extensionName = $this->controllerContext->getRequest()->getControllerExtensionName();
$labels = GeneralUtility::trimExplode(',', $labels, TRUE);
$languageArray = [];
......
......@@ -27,22 +27,31 @@ namespace SGalinski\SgRoutes\ViewHelpers;
***************************************************************/
use TYPO3\CMS\Extbase\Reflection\ObjectAccess;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
* Class SetViewHelper
**/
class SetViewHelper extends AbstractViewHelper {
/**
* Register the ViewHelper arguments
*/
public function initializeArguments() {
parent::initializeArguments();
$this->registerArgument('name', 'string', 'The name of the variable', TRUE);
$this->registerArgument('value', 'mixed', 'The value of the variable', FALSE, NULL);
}
/**
* Set (override) the variable in $name.
*
* @param string $name
* @param mixed $value
* @return void
* @throws \TYPO3\CMS\Fluid\Core\ViewHelper\Exception\InvalidVariableException
*/
public function render($name, $value = NULL) {
public function render() {
$name = $this->arguments['name'];
$value = $this->arguments['value'];
if (NULL === $value) {
$value = $this->renderChildren();
}
......
......@@ -27,6 +27,7 @@ namespace SGalinski\SgRoutes\ViewHelpers\Widget;
***************************************************************/
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
/**
* Class UriViewHelper
......@@ -36,19 +37,15 @@ class UriViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Widget\UriViewHelper {
/**
* Get the URI for a non-AJAX Request.
*
* @param RenderingContextInterface $renderingContext
* @param array $arguments
* @return string the Widget URI
*/
protected function getWidgetUri() {
$uriBuilder = $this->controllerContext->getUriBuilder();
$argumentPrefix = $this->controllerContext->getRequest()->getArgumentPrefix();
$arguments = $this->hasArgument('arguments') ? $this->arguments['arguments'] : [];
if ($this->hasArgument('action')) {
$arguments['action'] = $this->arguments['action'];
}
if ($this->arguments['format'] !== '' && $this->hasArgument('format')) {
$arguments['format'] = $this->arguments['format'];
}
$parentNamespace = $this->controllerContext->getRequest()->getWidgetContext()->getParentPluginNamespace();
protected static function getWidgetUri(RenderingContextInterface $renderingContext, array $arguments) {
$controllerContext = $renderingContext->getControllerContext();
$uriBuilder = $controllerContext->getUriBuilder();
$argumentPrefix = $controllerContext->getRequest()->getArgumentPrefix();
$parentNamespace = $controllerContext->getRequest()->getWidgetContext()->getParentPluginNamespace();
$parentArguments = GeneralUtility::_GP($parentNamespace);
$allArguments = [$argumentPrefix => $arguments];
if ($parentArguments && isset($parentArguments['filters'])) {
......@@ -56,11 +53,11 @@ class UriViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Widget\UriViewHelper {
}
return $uriBuilder->reset()
->setArguments($allArguments)
->setSection($this->arguments['section'])
->setSection($arguments['section'])
->setAddQueryString(TRUE)
->setAddQueryStringMethod($this->arguments['addQueryStringMethod'])
->setAddQueryStringMethod($arguments['addQueryStringMethod'])
->setArgumentsToBeExcludedFromQueryString([$argumentPrefix, 'cHash'])
->setFormat($this->arguments['format'])
->setFormat($arguments['format'])
->build();
}
}
......@@ -11,7 +11,7 @@
"issues": "https://gitlab.sgalinski.de/typo3/sg_routes"
},
"require": {
"typo3/cms-core": "^7.6.0 || ^8.7.0 || ^9.5.1"
"typo3/cms-core": "^8.7.0 || ^9.5.1"
},
"replace": {
"sg_routes": "self.version"
......
......@@ -14,7 +14,7 @@ $EM_CONF[$_EXTKEY] = [
'author_company' => 'sgalinski Internet Services (https://www.sgalinski.de)',
'constraints' => [
'depends' => [
'typo3' => '7.6.0-9.5.99',
'typo3' => '8.7.0-9.5.99',
'php' => '7.0.0-7.3.99',
],
'conflicts' => [
......
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