[TASK] Move ViewHelper arguments to initializeArguments() in several sysexts 71/48771/6
authorWouter Wolters <typo3@wouterwolters.nl>
Fri, 1 Jul 2016 14:25:50 +0000 (16:25 +0200)
committerNicole Cordes <typo3@cordes.co>
Sun, 24 Jul 2016 11:29:01 +0000 (13:29 +0200)
Resolves: #76916
Releases: master
Change-Id: I987925b1b99d5f6c53c181d8ac08b586e628e8f4
Reviewed-on: https://review.typo3.org/48771
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
12 files changed:
typo3/sysext/backend/Classes/ViewHelpers/AvatarViewHelper.php
typo3/sysext/core/Classes/ViewHelpers/IconViewHelper.php
typo3/sysext/core/Tests/Unit/ViewHelpers/IconViewHelperTest.php
typo3/sysext/cshmanual/Classes/ViewHelpers/FormatViewHelper.php
typo3/sysext/documentation/Classes/ViewHelpers/FormatsViewHelper.php
typo3/sysext/fluid_styled_content/Classes/ViewHelpers/Link/SectionViewHelper.php
typo3/sysext/form/Classes/ViewHelpers/AggregateSelectOptionsViewHelper.php
typo3/sysext/form/Classes/ViewHelpers/PlainMailViewHelper.php
typo3/sysext/reports/Classes/ViewHelpers/IconViewHelper.php
typo3/sysext/scheduler/Classes/ViewHelpers/ModuleLinkViewHelper.php
typo3/sysext/sys_note/Classes/ViewHelpers/DeleteLinkViewHelper.php
typo3/sysext/sys_note/Classes/ViewHelpers/EditLinkViewHelper.php

index ff043bc..af90273 100644 (file)
@@ -31,21 +31,25 @@ class AvatarViewHelper extends AbstractViewHelper
     protected $escapeOutput = false;
 
     /**
+     * Initializes the arguments
+     */
+    public function initializeArguments()
+    {
+        parent::initializeArguments();
+        $this->registerArgument('backendUser', 'int', 'Uid of the user', false, 0);
+        $this->registerArgument('size', 'int', 'width and height of the image', false, 32);
+        $this->registerArgument('showIcon', 'bool', 'show the record icon', false, false);
+    }
+
+    /**
      * Resolve user avatar from backend user id.
      *
-     * @param int $backendUser Uid of the user
-     * @param int $size width and height of the image
-     * @param bool $showIcon show the record icon
      * @return string html image tag
      */
-    public function render($backendUser = 0, $size = 32, $showIcon = false)
+    public function render()
     {
         return static::renderStatic(
-            array(
-                'backendUser' => $backendUser,
-                'size' => $size,
-                'showIcon' => $showIcon
-            ),
+            $this->arguments,
             $this->buildRenderChildrenClosure(),
             $this->renderingContext
         );
index d55db1a..cfea81f 100644 (file)
@@ -34,25 +34,27 @@ class IconViewHelper extends AbstractViewHelper
     protected $escapeOutput = false;
 
     /**
+     * Initializes the arguments
+     */
+    public function initializeArguments()
+    {
+        parent::initializeArguments();
+        $this->registerArgument('identifier', 'string', 'the table for the record icon', true);
+        $this->registerArgument('size', 'string', 'the icon size', false, Icon::SIZE_SMALL);
+        $this->registerArgument('overlay', 'string', '', false, null);
+        $this->registerArgument('state', 'string', '', false, IconState::STATE_DEFAULT);
+        $this->registerArgument('alternativeMarkupIdentifier', 'string', '', false, null);
+    }
+
+    /**
      * Prints icon html for $identifier key
      *
-     * @param string $identifier
-     * @param string $size
-     * @param string $overlay
-     * @param string $state
-     * @param string $alternativeMarkupIdentifier
      * @return string
      */
-    public function render($identifier, $size = Icon::SIZE_SMALL, $overlay = null, $state = IconState::STATE_DEFAULT, $alternativeMarkupIdentifier = null)
+    public function render()
     {
         return static::renderStatic(
-            array(
-                'identifier' => $identifier,
-                'size' => $size,
-                'overlay' => $overlay,
-                'state' => $state,
-                'alternativeMarkupIdentifier' => $alternativeMarkupIdentifier
-            ),
+            $this->arguments,
             $this->buildRenderChildrenClosure(),
             $this->renderingContext
         );
index c2a85c3..5c9950d 100644 (file)
@@ -52,7 +52,12 @@ class IconViewHelperTest extends ViewHelperBaseTestcase
         $iconFactoryProphecy->getIcon('myIdentifier', Icon::SIZE_SMALL, null, IconState::cast(IconState::STATE_DEFAULT))->shouldBeCalled()->willReturn($iconProphecy->reveal());
         $iconProphecy->render(null)->shouldBeCalled()->willReturn('htmlFoo');
 
-        $this->assertSame('htmlFoo', $this->viewHelper->render('myIdentifier'));
+        $this->viewHelper->setArguments([
+            'identifier' => 'myIdentifier',
+            'size' => Icon::SIZE_SMALL
+        ]);
+
+        $this->assertSame('htmlFoo', $this->viewHelper->render());
     }
 
     /**
@@ -67,7 +72,12 @@ class IconViewHelperTest extends ViewHelperBaseTestcase
         $iconFactoryProphecy->getIcon('myIdentifier', Icon::SIZE_LARGE, null, IconState::cast(IconState::STATE_DEFAULT))->shouldBeCalled()->willReturn($iconProphecy->reveal());
         $iconProphecy->render(null)->shouldBeCalled()->willReturn('htmlFoo');
 
-        $this->assertSame('htmlFoo', $this->viewHelper->render('myIdentifier', Icon::SIZE_LARGE));
+        $this->viewHelper->setArguments([
+            'identifier' => 'myIdentifier',
+            'size' => Icon::SIZE_LARGE
+        ]);
+
+        $this->assertSame('htmlFoo', $this->viewHelper->render());
     }
 
     /**
@@ -82,7 +92,14 @@ class IconViewHelperTest extends ViewHelperBaseTestcase
         $iconFactoryProphecy->getIcon('myIdentifier', Icon::SIZE_SMALL, null, IconState::cast(IconState::STATE_DISABLED))->shouldBeCalled()->willReturn($iconProphecy->reveal());
         $iconProphecy->render(null)->shouldBeCalled()->willReturn('htmlFoo');
 
-        $this->assertSame('htmlFoo', $this->viewHelper->render('myIdentifier', Icon::SIZE_SMALL, null, IconState::cast(IconState::STATE_DISABLED)));
+        $this->viewHelper->setArguments([
+            'identifier' => 'myIdentifier',
+            'size' => Icon::SIZE_SMALL,
+            'overlay' => null,
+            'state' => IconState::cast(IconState::STATE_DISABLED)
+        ]);
+
+        $this->assertSame('htmlFoo', $this->viewHelper->render());
     }
 
     /**
@@ -97,6 +114,11 @@ class IconViewHelperTest extends ViewHelperBaseTestcase
         $iconFactoryProphecy->getIcon('myIdentifier', Argument::any(), 'overlayString', IconState::cast(IconState::STATE_DEFAULT))->shouldBeCalled()->willReturn($iconProphecy->reveal());
         $iconProphecy->render(null)->shouldBeCalled()->willReturn('htmlFoo');
 
-        $this->assertSame('htmlFoo', $this->viewHelper->render('myIdentifier', Icon::SIZE_LARGE, 'overlayString'));
+        $this->viewHelper->setArguments([
+            'identifier' => 'myIdentifier',
+            'size' => Icon::SIZE_LARGE,
+            'overlay' => 'overlayString'
+        ]);
+        $this->assertSame('htmlFoo', $this->viewHelper->render());
     }
 }
index 1a7a9ee..6750453 100644 (file)
@@ -39,17 +39,23 @@ class FormatViewHelper extends AbstractViewHelper
     protected $escapeChildren = false;
 
     /**
+     * Initializes the arguments
+     */
+    public function initializeArguments()
+    {
+        parent::initializeArguments();
+        $this->registerArgument('content', 'string', '', false, '');
+    }
+
+    /**
      * Format the content
      *
-     * @param string $content
      * @return string
      */
-    public function render($content = '')
+    public function render()
     {
         return self::renderStatic(
-            array(
-                'content' => $content,
-            ),
+            $this->arguments,
             $this->buildRenderChildrenClosure(),
             $this->renderingContext
         );
index 88a1329..48dc62b 100644 (file)
@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Documentation\ViewHelpers;
 use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Imaging\IconFactory;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Documentation\Domain\Model\DocumentTranslation;
 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
 
@@ -37,17 +38,25 @@ class FormatsViewHelper extends AbstractViewHelper
     protected $escapeOutput = false;
 
     /**
+     * Initializes the arguments
+     *
+     * @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
+     */
+    public function initializeArguments()
+    {
+        parent::initializeArguments();
+        $this->registerArgument('documentTranslation', DocumentTranslation::class, '', true);
+    }
+
+    /**
      * Renders all format download links.
      *
-     * @param \TYPO3\CMS\Documentation\Domain\Model\DocumentTranslation $documentTranslation
      * @return string
      */
-    public function render(\TYPO3\CMS\Documentation\Domain\Model\DocumentTranslation $documentTranslation)
+    public function render()
     {
         return static::renderStatic(
-            array(
-                'documentTranslation' => $documentTranslation,
-            ),
+            $this->arguments,
             $this->buildRenderChildrenClosure(),
             $this->renderingContext
         );
index 3bbb713..20bce37 100644 (file)
@@ -47,18 +47,18 @@ class SectionViewHelper extends AbstractTagBasedViewHelper
     public function initializeArguments()
     {
         parent::initializeArguments();
+        $this->registerArgument('name', 'string', 'The section name to be used', true);
         $this->registerUniversalTagAttributes();
     }
 
     /**
      * Render the view helper
      *
-     * @param string $name The section name to be used
      * @return string
      */
-    public function render($name)
+    public function render()
     {
-        $fragment = '#' . $name;
+        $fragment = '#' . $this->arguments['name'];
 
         // Prefix with current URL path if baseUrl is used
         if (!empty($this->getTypoScriptFrontendController()->baseUrl)) {
index 558b86d..75d6914 100644 (file)
@@ -33,21 +33,28 @@ class AggregateSelectOptionsViewHelper extends AbstractViewHelper
     protected $selectedValues = array();
 
     /**
-     * @param Element $model
-     * @param bool $returnSelectedValues
+     * Initializes the arguments
+     */
+    public function initializeArguments()
+    {
+        parent::initializeArguments();
+        $this->registerArgument('model', Element::class, '', true);
+        $this->registerArgument('returnSelectedValues', 'bool', '', false, false);
+    }
+
+    /**
      * @return array
      */
-    public function render(Element $model, $returnSelectedValues = false)
+    public function render()
     {
+        /** @var Element $model */
+        $model = $this->arguments['model'];
+        /** @var Element $element */
         foreach ($model->getChildElements() as $element) {
             $this->createElement($element);
         }
 
-        if ($returnSelectedValues === true) {
-            return $this->selectedValues;
-        }
-
-        return $this->options;
+        return $this->arguments['returnSelectedValues'] ? $this->selectedValues : $this->options;
     }
 
     /**
@@ -70,7 +77,7 @@ class AggregateSelectOptionsViewHelper extends AbstractViewHelper
         if ($model->getElementType() === 'OPTGROUP') {
             $optGroupData = array(
                 'label' => $model->getAdditionalArgument('label'),
-                'disabled' => $model->getAdditionalArgument('disabled')
+                'disabled' => $model->getAdditionalArgument('disabled'),
             );
             $this->getChildElements($model, $optGroupData);
         } else {
@@ -101,6 +108,7 @@ class AggregateSelectOptionsViewHelper extends AbstractViewHelper
      */
     protected function getChildElements(Element $model, array $optGroupData = array())
     {
+        /** @var Element $element */
         foreach ($model->getChildElements() as $element) {
             $this->createElement($element, $optGroupData);
         }
index 7634efa..5026381 100644 (file)
@@ -14,77 +14,75 @@ namespace TYPO3\CMS\Form\ViewHelpers;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
+use TYPO3\CMS\Form\Domain\Model\Element;
+
 /**
  * A viewhelper for the plain mail view
  */
-class PlainMailViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
+class PlainMailViewHelper extends AbstractViewHelper
 {
     /**
+     * Initializes the arguments
+     */
+    public function initializeArguments()
+    {
+        parent::initializeArguments();
+        $this->registerArgument('labelContent', 'mixed', '');
+        $this->registerArgument('content', 'mixed', '');
+        $this->registerArgument('newLineAfterLabel', 'bool', '', false, false);
+        $this->registerArgument('indent', 'int', '', false, 0);
+    }
+
+    /**
      * Render the plain mail view
      *
-     * @param mixed $labelContent
-     * @param mixed $content
-     * @param bool $newLineAfterLabel
-     * @param int $indent
      * @return string
      */
-    public function render($labelContent = null, $content = null, $newLineAfterLabel = false, $indent = 0)
+    public function render()
     {
         $templateVariableContainer = $this->renderingContext->getViewHelperVariableContainer();
-        if (!$templateVariableContainer->exists(\TYPO3\CMS\Form\ViewHelpers\PlainMailViewHelper::class, 'spaces')) {
-            $templateVariableContainer->add(\TYPO3\CMS\Form\ViewHelpers\PlainMailViewHelper::class, 'spaces', 0);
+        if (!$templateVariableContainer->exists(__CLASS__, 'spaces')) {
+            $templateVariableContainer->add(__CLASS__, 'spaces', 0);
         }
 
-        $spaces = $templateVariableContainer->get(\TYPO3\CMS\Form\ViewHelpers\PlainMailViewHelper::class, 'spaces');
+        $spaces = $templateVariableContainer->get(__CLASS__, 'spaces');
         $output = '';
-        if ($labelContent) {
-            if ($labelContent instanceof \TYPO3\CMS\Form\Domain\Model\Element) {
-                $output = $this->getLabel($labelContent);
+        if ($this->arguments['labelContent']) {
+            if ($this->arguments['labelContent'] instanceof Element) {
+                $output = $this->getLabel($this->arguments['labelContent']);
             } else {
-                $output = $labelContent;
+                $output = $this->arguments['labelContent'];
             }
-            if ($newLineAfterLabel) {
+            if ($this->arguments['newLineAfterLabel']) {
                 if ($output !== '') {
                     $output = str_repeat(chr(32), $spaces) . $output . LF;
                 }
-                $this->setIndent($indent);
+                $this->setIndent($this->arguments['indent']);
             }
         }
 
-        if ($content) {
-            if (!$newLineAfterLabel) {
-                $this->setIndent($indent);
+        if ($this->arguments['content']) {
+            if (!$this->arguments['newLineAfterLabel']) {
+                $this->setIndent($this->arguments['indent']);
             }
-            if (
-                $labelContent
-                && !$newLineAfterLabel
-            ) {
-                $output = $output . ': ' . $this->getValue($content);
-            } elseif (
-                $labelContent
-                && $newLineAfterLabel
-            ) {
-                $output =
-                    $output .
-                    str_repeat(chr(32), ($spaces + 4)) .
-                    str_replace(LF, LF . str_repeat(chr(32), ($spaces + 4)), $this->getValue($content));
+            if ($this->arguments['labelContent'] && !$this->arguments['newLineAfterLabel']) {
+                $output = $output . ': ' . $this->getValue($this->arguments['content']);
+            } elseif ($this->arguments['labelContent'] && $this->arguments['newLineAfterLabel']) {
+                $output = $output
+                    . str_repeat(chr(32), ($spaces + 4))
+                    . str_replace(LF, LF . str_repeat(chr(32), ($spaces + 4)), $this->getValue($this->arguments['content']));
             } else {
-                $output = $this->getValue($content);
+                $output = $this->getValue($this->arguments['content']);
             }
         }
 
-        if (
-            $labelContent
-            || $content
-        ) {
-            if (
-                $output !== ''
-                && !$newLineAfterLabel
-            ) {
+        if ($this->arguments['labelContent'] || $this->arguments['content']) {
+            if ($output !== '' && !$this->arguments['newLineAfterLabel']) {
                 $output = str_repeat(chr(32), $spaces) . $output;
             }
         } else {
-            $this->setIndent($indent);
+            $this->setIndent($this->arguments['indent']);
         }
 
         return $output;
@@ -92,10 +90,10 @@ class PlainMailViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewH
 
     /**
      * Get the label
-     * @param \TYPO3\CMS\Form\Domain\Model\Element $model
+     * @param Element $model
      * @return string
      */
-    protected function getLabel(\TYPO3\CMS\Form\Domain\Model\Element $model)
+    protected function getLabel(Element $model)
     {
         $label = '';
         if ($model->getAdditionalArgument('legend')) {
@@ -108,18 +106,13 @@ class PlainMailViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewH
 
     /**
      * Get the label
-     * @param mixed $model
+     *
+     * @param string $content
      * @return string
      */
     protected function getValue($content)
     {
-        $value = '';
-        if ($content instanceof \TYPO3\CMS\Form\Domain\Model\Element) {
-            $value = $content->getAdditionalArgument('value');
-        } else {
-            $value = $content;
-        }
-        return $value;
+        return $content instanceof Element ? $content->getAdditionalArgument('value') : $content;
     }
 
     /**
@@ -131,9 +124,9 @@ class PlainMailViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewH
     public function setIndent($indent = 0)
     {
         $templateVariableContainer = $this->renderingContext->getViewHelperVariableContainer();
-        $spaces = $templateVariableContainer->get(\TYPO3\CMS\Form\ViewHelpers\PlainMailViewHelper::class, 'spaces');
+        $spaces = $templateVariableContainer->get(__CLASS__, 'spaces');
         $spaces += (int)$indent;
-        $templateVariableContainer->addOrUpdate(\TYPO3\CMS\Form\ViewHelpers\PlainMailViewHelper::class, 'indent', $indent);
-        $templateVariableContainer->addOrUpdate(\TYPO3\CMS\Form\ViewHelpers\PlainMailViewHelper::class, 'spaces', $spaces);
+        $templateVariableContainer->addOrUpdate(__CLASS__, 'indent', $indent);
+        $templateVariableContainer->addOrUpdate(__CLASS__, 'spaces', $spaces);
     }
 }
index f9b90dd..97f701a 100644 (file)
@@ -34,19 +34,24 @@ class IconViewHelper extends AbstractBackendViewHelper
     protected $escapeOutput = false;
 
     /**
+     * Initializes the arguments
+     */
+    public function initializeArguments()
+    {
+        parent::initializeArguments();
+        $this->registerArgument('icon', 'string', 'Icon to be used', true);
+        $this->registerArgument('title', 'string', 'Optional title', false, '');
+    }
+
+    /**
      * Renders the icon
      *
-     * @param string $icon Icon to be used
-     * @param string $title Optional title
      * @return string Content rendered image
      */
-    public function render($icon, $title = '')
+    public function render()
     {
         return static::renderStatic(
-            array(
-                'icon' => $icon,
-                'title' => $title,
-            ),
+            $this->arguments,
             $this->buildRenderChildrenClosure(),
             $this->renderingContext
         );
@@ -65,6 +70,8 @@ class IconViewHelper extends AbstractBackendViewHelper
         $title = $arguments['title'];
 
         $icon = GeneralUtility::getFileAbsFileName($icon ?: 'EXT:reports/ext_icon.png');
-        return '<img src="' . htmlspecialchars(PathUtility::getAbsoluteWebPath($icon)) . '" width="16" height="16" title="' . htmlspecialchars($title) . '" alt="' . htmlspecialchars($title) . '" />';
+        return '<img src="' . htmlspecialchars(PathUtility::getAbsoluteWebPath($icon))
+               . '" width="16" height="16" title="' . htmlspecialchars($title)
+               . '" alt="' . htmlspecialchars($title) . '" />';
     }
 }
index 93cb987..4c98b6b 100644 (file)
@@ -25,21 +25,25 @@ use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
 class ModuleLinkViewHelper extends AbstractViewHelper
 {
     /**
+     * Initializes the arguments
+     */
+    public function initializeArguments()
+    {
+        parent::initializeArguments();
+        $this->registerArgument('controller', 'string', 'The "controller" of scheduler. Possible values are "scheduler", "check", "info"', true);
+        $this->registerArgument('action', 'string', 'The action to be called within each controller', true);
+        $this->registerArgument('arguments', 'array', '', false, []);
+    }
+
+    /**
      * Render module link with command and arguments
      *
-     * @param string $controller The "controller" of scheduler. Possible values are "scheduler", "check", "info"
-     * @param string $action The action to be called within each controller
-     * @param array $arguments Arguments for the action
      * @return string
      */
-    public function render($controller, $action, array $arguments = array())
+    public function render()
     {
         return static::renderStatic(
-            array(
-                'controller' => $controller,
-                'action' => $action,
-                'arguments' => $arguments,
-            ),
+            $this->arguments,
             $this->buildRenderChildrenClosure(),
             $this->renderingContext
         );
index a3ab49e..0b2cdad 100644 (file)
@@ -27,17 +27,23 @@ use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
 class DeleteLinkViewHelper extends AbstractViewHelper
 {
     /**
+     * Initializes the arguments
+     */
+    public function initializeArguments()
+    {
+        parent::initializeArguments();
+        $this->registerArgument('id', 'int', 'uid of the note', true);
+    }
+
+    /**
      * Create link to delete a note
      *
-     * @param int $id uid of the note
      * @return string link
      */
-    public function render($id)
+    public function render()
     {
         return static::renderStatic(
-            array(
-                'id' => $id
-            ),
+            $this->arguments,
             $this->buildRenderChildrenClosure(),
             $this->renderingContext
         );
index d9e1a78..416406e 100644 (file)
@@ -26,15 +26,21 @@ use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
 class EditLinkViewHelper extends AbstractViewHelper
 {
     /**
-     * @param int $id
+     * Initializes the arguments
+     */
+    public function initializeArguments()
+    {
+        parent::initializeArguments();
+        $this->registerArgument('id', 'int', '', true);
+    }
+
+    /**
      * @return string
      */
-    public function render($id)
+    public function render()
     {
         return static::renderStatic(
-            array(
-                'id' => $id
-            ),
+          $this->arguments,
             $this->buildRenderChildrenClosure(),
             $this->renderingContext
         );