From 80c6cf2106ee043de927f0c790806fd58600446b Mon Sep 17 00:00:00 2001 From: Marcus Schwemer <ms@schwemer.de> Date: Sun, 22 Jan 2017 22:24:39 +0100 Subject: [PATCH] [BUGFIX] Render prepended option tag always in first place Currently the prepend option is rendered together with the options argument from select viewhelper. Using the option "optionsAfterContent" renders also the prepend option after the children. The preprend option is now rendered always in the first place. Resolves: #79584 Releases: master, 8.7 Change-Id: Ia58c3b7d9b26d00cbda4d7ebce2a881a7129b331 Reviewed-on: https://review.typo3.org/51501 Reviewed-by: Jan Helke <typo3@helke.de> Tested-by: Jan Helke <typo3@helke.de> Tested-by: TYPO3com <no-reply@typo3.com> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> --- .../ViewHelpers/Form/SelectViewHelper.php | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Form/SelectViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Form/SelectViewHelper.php index a172eb2bb3ad..670b2c0ebaee 100644 --- a/typo3/sysext/fluid/Classes/ViewHelpers/Form/SelectViewHelper.php +++ b/typo3/sysext/fluid/Classes/ViewHelpers/Form/SelectViewHelper.php @@ -149,6 +149,7 @@ class SelectViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFie } $this->viewHelperVariableContainer->addOrUpdate(static::class, 'selectedValue', $this->getSelectedValue()); + $prependContent = $this->renderPrependOptionTag(); $tagContent = $this->renderOptionTags($options); $childContent = $this->renderChildren(); $this->viewHelperVariableContainer->remove(static::class, 'selectedValue'); @@ -158,6 +159,7 @@ class SelectViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFie } else { $tagContent .= $childContent; } + $tagContent = $prependContent . $tagContent; $this->tag->forceClosingTag(true); $this->tag->setContent($tagContent); @@ -165,13 +167,12 @@ class SelectViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFie return $content; } - /** - * Render the option tags. + /* + * Render prepended option tag * - * @param array $options the options for the form. - * @return string rendered tags. + * @return string rendered prepended empty option */ - protected function renderOptionTags($options) + protected function renderPrependOptionTag() { $output = ''; if ($this->hasArgument('prependOptionLabel')) { @@ -179,6 +180,18 @@ class SelectViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFie $label = $this->arguments['prependOptionLabel']; $output .= $this->renderOptionTag($value, $label, false) . LF; } + return $output; + } + + /** + * Render the option tags. + * + * @param array $options the options for the form. + * @return string rendered tags. + */ + protected function renderOptionTags($options) + { + $output = ''; foreach ($options as $value => $label) { $isSelected = $this->isSelected($value); $output .= $this->renderOptionTag($value, $label, $isSelected) . LF; -- GitLab