Commit f3ff524d authored by Frederic Gaus's avatar Frederic Gaus Committed by Benni Mack
Browse files

[!!!][BUGFIX] Correct "required"-parameter in TextfieldViewHelper

Releases: master
Resolves: #67098
Change-Id: Ifc322aba2cf95849e1541cac4df65d30aeb56bc3
Reviewed-on: http://review.typo3.org/40645


Reviewed-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: default avatarDaniel Goerz <ervaude@gmail.com>
Tested-by: default avatarDaniel Goerz <ervaude@gmail.com>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent c00c85b0
====================================================================
Breaking: #67098 - Correct required-parameter in TextfieldViewHelper
====================================================================
Description
===========
The value comparison of the required parameter is corrected. Before, a textfield was required as soon as it had a parameter "required" set to any value. Even if this value was set to FALSE, the textfield was still required.
Impact
======
Textfelds with required="FALSE" are not required any longer.
Affected Installations
======================
Every installation that uses the textfield viewhelper with the required attribute.
Migration
=========
none
\ No newline at end of file
......@@ -59,7 +59,7 @@ class TextfieldViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractForm
* @return string
* @api
*/
public function render($required = NULL, $type = 'text') {
public function render($required = FALSE, $type = 'text') {
$name = $this->getName();
$this->registerFieldNameForFormTokenGeneration($name);
$this->setRespectSubmittedDataValue(TRUE);
......@@ -73,7 +73,7 @@ class TextfieldViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractForm
$this->tag->addAttribute('value', $value);
}
if ($required !== NULL) {
if ($required !== FALSE) {
$this->tag->addAttribute('required', 'required');
}
......
......@@ -95,4 +95,27 @@ class TextfieldViewHelperTest extends \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Fo
$this->viewHelper->render();
}
/**
* @test
*/
public function renderCorrectlySetsRequiredAttribute() {
$mockTagBuilder = $this->getMock(\TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder::class, array('addAttribute', 'setContent', 'render'), array(), '', FALSE);
$mockTagBuilder->expects($this->at(0))->method('addAttribute')->with('type', 'text');
$mockTagBuilder->expects($this->at(1))->method('addAttribute')->with('name', 'NameOfTextfield');
$this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('NameOfTextfield');
$mockTagBuilder->expects($this->at(2))->method('addAttribute')->with('value', 'Current value');
$mockTagBuilder->expects($this->at(3))->method('addAttribute')->with('required', 'required');
$mockTagBuilder->expects($this->once())->method('render');
$this->viewHelper->_set('tag', $mockTagBuilder);
$arguments = array(
'name' => 'NameOfTextfield',
'value' => 'Current value'
);
$this->viewHelper->setArguments($arguments);
$this->viewHelper->setViewHelperNode(new \TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Form\Fixtures\EmptySyntaxTreeNode());
$this->viewHelper->initialize();
$this->viewHelper->render(TRUE);
}
}
Supports Markdown
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