[BUGFIX] Ensure ext:form select value is properly set 78/43578/6
authorRalf Zimmermann <ralf.zimmermann@tritum.de>
Mon, 28 Sep 2015 10:56:42 +0000 (12:56 +0200)
committerOliver Hader <oliver.hader@typo3.org>
Mon, 28 Sep 2015 17:03:38 +0000 (19:03 +0200)
Change-Id: I80393a754626bbafdd2e32836741f97125892604
Resolves: #70122
Releases: master
Reviewed-on: http://review.typo3.org/43578
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
Tested-by: Oliver Hader <oliver.hader@typo3.org>
typo3/sysext/form/Classes/Hooks/HandleIncomingFormValues.php
typo3/sysext/form/Classes/ViewHelpers/AggregateSelectOptionsViewHelper.php
typo3/sysext/form/Resources/Private/Partials/Compatibility/Confirmation/FlatElements/Select.html
typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/FlatElements/Select.html
typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Plain/FlatElements/Select.html
typo3/sysext/form/Resources/Private/Partials/Compatibility/Show/FlatElements/Select.html
typo3/sysext/form/Resources/Private/Partials/Default/Confirmation/FlatElements/Select.html
typo3/sysext/form/Resources/Private/Partials/Default/PostProcessor/Mail/Html/FlatElements/Select.html
typo3/sysext/form/Resources/Private/Partials/Default/PostProcessor/Mail/Plain/FlatElements/Select.html
typo3/sysext/form/Resources/Private/Partials/Default/Show/FlatElements/Select.html

index b132fec..36a038f 100644 (file)
@@ -113,6 +113,7 @@ class HandleIncomingFormValues implements SingletonInterface {
                                $element->getParentElement()->setAdditionalArgument('atLeastOneCheckedChildElement', TRUE);
                        }
                } elseif ($element->getElementType() === 'OPTION') {
+                       $modelValue = (string)($element->getAdditionalArgument('value') ?: $element->getElementCounter());
                        if ($element->getParentElement()->getElementType() === 'OPTGROUP') {
                                $parentName = $element->getParentElement()->getParentElement()->getName();
                        } else {
@@ -121,7 +122,7 @@ class HandleIncomingFormValues implements SingletonInterface {
                        $incomingData = $formBuilder->getIncomingData()->getIncomingField($parentName);
                        /* Multiselect */
                        if (is_array($incomingData)) {
-                               if (in_array($modelValue, $incomingData)) {
+                               if (in_array($modelValue, $incomingData, TRUE)) {
                                        $element->setHtmlAttribute('selected', 'selected');
                                } else {
                                        $element->setHtmlAttribute('selected', NULL);
index bf5f251..a1f0a69 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Form\ViewHelpers;
  */
 
 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
+use TYPO3\CMS\Form\Domain\Model\Element;
 
 /**
  * Aggregator for the select options
@@ -22,11 +23,6 @@ use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
 class AggregateSelectOptionsViewHelper extends AbstractViewHelper  {
 
        /**
-        * @var \TYPO3\CMS\Form\Domain\Model\Form
-        */
-       protected $model;
-
-       /**
         * @var array
         */
        protected $options = array();
@@ -37,14 +33,14 @@ class AggregateSelectOptionsViewHelper extends AbstractViewHelper  {
        protected $selectedValues = array();
 
        /**
-        * @param \TYPO3\CMS\Form\Domain\Model\Element\AbstractElement $model
+        * @param Element $model
         * @param boolean $returnSelectedValues
         * @return array
         */
-       public function render($model, $returnSelectedValues = FALSE) {
+       public function render(Element $model, $returnSelectedValues = FALSE) {
 
                foreach ($model->getChildElements() as $element) {
-                       $this->createElement($element, array());
+                       $this->createElement($element);
                }
 
                if ($returnSelectedValues === TRUE) {
@@ -55,20 +51,20 @@ class AggregateSelectOptionsViewHelper extends AbstractViewHelper  {
        }
 
        /**
-        * @param \TYPO3\CMS\Form\Domain\Model\Element\AbstractElement $model
+        * @param Element $model
         * @param array $optGroupData
         * @return void
         */
-       public function createElement($model, $optGroupData = array()) {
+       protected function createElement(Element $model, array $optGroupData = array()) {
                $this->checkElementForOptgroup($model, $optGroupData);
        }
 
        /**
-        * @param \TYPO3\CMS\Form\Domain\Model\Element\AbstractElement $model
+        * @param Element $model
         * @param array $optGroupData
         * @return void
         */
-       protected function checkElementForOptgroup($model, $optGroupData = array()) {
+       protected function checkElementForOptgroup(Element $model, array $optGroupData = array()) {
                if ($model->getElementType() === 'OPTGROUP') {
                        $optGroupData = array(
                                'label' => $model->getAdditionalArgument('label'),
@@ -77,13 +73,13 @@ class AggregateSelectOptionsViewHelper extends AbstractViewHelper  {
                        $this->getChildElements($model, $optGroupData);
                } else {
                        $optionData = array(
-                               'value' => $model->getAdditionalArgument('value'),
+                               'value' => $model->getAdditionalArgument('value') ?: $model->getElementCounter(),
                                'label' => $model->getAdditionalArgument('text'),
                                'selected' => $model->getHtmlAttribute('selected'),
                        );
 
-                       if ($model->getHtmlAttribute('selected') == 'selected') {
-                               $this->selectedValues[] = $model->getAdditionalArgument('value');
+                       if (!empty($optionData['selected'])) {
+                               $this->selectedValues[] = $optionData['value'];
                        }
 
                        if (count($optGroupData)) {
@@ -93,18 +89,18 @@ class AggregateSelectOptionsViewHelper extends AbstractViewHelper  {
                        } else {
                                $this->options[] = $optionData;
                        }
-                       return $model;
                }
        }
 
        /**
-        * @param \TYPO3\CMS\Form\Domain\Model\Element\AbstractElement $model
+        * @param Element $model
         * @param array $optGroupData
         * @return void
         */
-       protected function getChildElements($model, $optGroupData = array()) {
+       protected function getChildElements(Element $model, array $optGroupData = array()) {
                foreach ($model->getChildElements() as $element) {
                        $this->createElement($element, $optGroupData);
                }
        }
+
 }
index ae70c1b..772230c 100644 (file)
@@ -4,16 +4,66 @@
        <f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
                <ol>
 </f:if>
-               <f:for each="<form:aggregateSelectOptions model='{model}' />" as="option">
+               <f:for each="{form:aggregateSelectOptions(model:model)}" as="option">
                        <f:if condition="{option.options}">
                                <f:then>
                                                <f:for each="{option.options}" as="optgroupOption">
-                                                       <f:if condition="{optgroupOption.selected} == 'selected'">
+                                                       <f:if condition="{optgroupOption.selected}">
                                                                <f:if condition="{model.showElement}">
                                                                        <f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
                                                                                {optgroupOption.label}
                                                                        <f:format.raw>{model.layout.elementOuterWrap.1}</f:format.raw>
                                                                </f:if>
+                                                               <f:if condition="{model.additionalArguments.multiple}">
+                                                                       <f:then>
+                                                                               <f:form.hidden
+                                                                                       class="{model.additionalArguments.class}"
+                                                                                       dir="{model.additionalArguments.dir}"
+                                                                                       id="{model.additionalArguments.id}"
+                                                                                       lang="{model.additionalArguments.lang}"
+                                                                                       style="{model.additionalArguments.style}"
+                                                                                       title="{model.additionalArguments.title}"
+                                                                                       accesskey="{model.additionalArguments.accesskey}"
+                                                                                       tabindex="{model.additionalArguments.tabindex}"
+                                                                                       onclick="{model.additionalArguments.onclick}"
+
+                                                                                       name="{model.additionalArguments.prefix}[{model.additionalArguments.name}][]"
+                                                                                       value="{option.value}"
+
+                                                                                       additionalAttributes="{model.htmlAttributes}"
+                                                                               />
+                                                                       </f:then>
+                                                                       <f:else>
+                                                                               <f:form.hidden
+                                                                                       class="{model.additionalArguments.class}"
+                                                                                       dir="{model.additionalArguments.dir}"
+                                                                                       id="{model.additionalArguments.id}"
+                                                                                       lang="{model.additionalArguments.lang}"
+                                                                                       style="{model.additionalArguments.style}"
+                                                                                       title="{model.additionalArguments.title}"
+                                                                                       accesskey="{model.additionalArguments.accesskey}"
+                                                                                       tabindex="{model.additionalArguments.tabindex}"
+                                                                                       onclick="{model.additionalArguments.onclick}"
+
+                                                                                       name="{model.additionalArguments.prefix}[{model.additionalArguments.name}]"
+                                                                                       value="{option.value}"
+
+                                                                                       additionalAttributes="{model.htmlAttributes}"
+                                                                               />
+                                                                       </f:else>
+                                                               </f:if>
+                                                       </f:if>
+                                               </f:for>
+                               </f:then>
+                               <f:else>
+                                       <f:if condition="{option.selected}">
+                                               <f:if condition="{model.showElement}">
+                                                       <f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
+                                                               {option.label}
+                                                       <f:format.raw>{model.layout.elementOuterWrap.1}</f:format.raw>
+                                               </f:if>
+                                               <f:if condition="{model.additionalArguments.multiple}">
+                                                       <f:then>
                                                                <f:form.hidden
                                                                        class="{model.additionalArguments.class}"
                                                                        dir="{model.additionalArguments.dir}"
                                                                        onclick="{model.additionalArguments.onclick}"
 
                                                                        name="{model.additionalArguments.prefix}[{model.additionalArguments.name}][]"
-                                                                       value="{optgroupOption.value}"
+                                                                       value="{option.value}"
 
                                                                        additionalAttributes="{model.htmlAttributes}"
                                                                />
-                                                       </f:if>
-                                               </f:for>
-                               </f:then>
-                               <f:else>
-                                       <f:if condition="{option.selected} == 'selected'">
-                                               <f:if condition="{model.showElement}">
-                                                       <f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
-                                                               {option.label}
-                                                       <f:format.raw>{model.layout.elementOuterWrap.1}</f:format.raw>
-                                               </f:if>
-                                               <f:form.hidden
-                                                       class="{model.additionalArguments.class}"
-                                                       dir="{model.additionalArguments.dir}"
-                                                       id="{model.additionalArguments.id}"
-                                                       lang="{model.additionalArguments.lang}"
-                                                       style="{model.additionalArguments.style}"
-                                                       title="{model.additionalArguments.title}"
-                                                       accesskey="{model.additionalArguments.accesskey}"
-                                                       tabindex="{model.additionalArguments.tabindex}"
-                                                       onclick="{model.additionalArguments.onclick}"
+                                                       </f:then>
+                                                       <f:else>
+                                                               <f:form.hidden
+                                                                       class="{model.additionalArguments.class}"
+                                                                       dir="{model.additionalArguments.dir}"
+                                                                       id="{model.additionalArguments.id}"
+                                                                       lang="{model.additionalArguments.lang}"
+                                                                       style="{model.additionalArguments.style}"
+                                                                       title="{model.additionalArguments.title}"
+                                                                       accesskey="{model.additionalArguments.accesskey}"
+                                                                       tabindex="{model.additionalArguments.tabindex}"
+                                                                       onclick="{model.additionalArguments.onclick}"
 
-                                                       name="{model.additionalArguments.prefix}[{model.additionalArguments.name}][]"
-                                                       value="{option.value}"
+                                                                       name="{model.additionalArguments.prefix}[{model.additionalArguments.name}]"
+                                                                       value="{option.value}"
 
-                                                       additionalAttributes="{model.htmlAttributes}"
-                                               />
+                                                                       additionalAttributes="{model.htmlAttributes}"
+                                                               />
+                                                       </f:else>
+                                               </f:if>
                                        </f:if>
                                </f:else>
                        </f:if>
index f8e7497..ffa5c61 100644 (file)
@@ -5,22 +5,22 @@
     <em>{model.additionalArguments.label}</em>
   </td>
   <td>
-<f:for each="<form:aggregateSelectOptions model='{model}' />" as="option">
+<f:for each="{form:aggregateSelectOptions(model:model)}" as="option">
 <f:if condition="{option.options}">
 <f:then>
 <f:for each="{option.options}" as="optgroupOption">
-<f:if condition="{optgroupOption.selected} == 'selected'">
-    <div class="csc-form-element csc-form-element-{model.elementTypeLowerCase}">{optgroupOption.value}</div>
+<f:if condition="{optgroupOption.selected}">
+    <div class="csc-form-element csc-form-element-{model.elementTypeLowerCase}">{optgroupOption.label}</div>
 </f:if>
 </f:for>
 </f:then>
 <f:else>
-<f:if condition="{option.selected} == 'selected'">
-    <div class="csc-form-element csc-form-element-{model.elementTypeLowerCase}">{option.value}</div>
+<f:if condition="{option.selected}">
+    <div class="csc-form-element csc-form-element-{model.elementTypeLowerCase}">{option.label}</div>
 </f:if>
 </f:else>
 </f:if>
 </f:for>
   </td>
 </tr>
-</f:if>
\ No newline at end of file
+</f:if>
index 1d6cba8..122c866 100644 (file)
@@ -1,3 +1,3 @@
-{namespace form=TYPO3\CMS\Form\ViewHelpers}<f:if condition="{model.showElement}"><form:plainMail labelContent="{model}" newLineAfterLabel="1" indent="4" /><f:for each="<form:aggregateSelectOptions model='{model}' />" as="option"><f:if condition="{option.options}"><f:then><f:for each="{option.options}" as="optgroupOption"><f:if condition="{optgroupOption.selected} == 'selected'"><form:plainMail content="{optgroupOption.value}" />
-</f:if></f:for></f:then><f:else><f:if condition="{option.selected} == 'selected'"><form:plainMail content="{option.value}" />
+{namespace form=TYPO3\CMS\Form\ViewHelpers}<f:if condition="{model.showElement}"><form:plainMail labelContent="{model}" newLineAfterLabel="1" indent="4" /><f:for each="{form:aggregateSelectOptions(model:model)}" as="option"><f:if condition="{option.options}"><f:then><f:for each="{option.options}" as="optgroupOption"><f:if condition="{optgroupOption.selected}"><form:plainMail content="{optgroupOption.label}" />
+</f:if></f:for></f:then><f:else><f:if condition="{option.selected}"><form:plainMail content="{option.label}" />
 </f:if></f:else></f:if></f:for><form:plainMail indent="-4"/></f:if>
\ No newline at end of file
index e3b15c5..494df69 100644 (file)
@@ -21,7 +21,7 @@
 
                        optionLabelField="label"
                        optionValueField="value"
-                       options='<form:aggregateSelectOptions model="{model}" />'
+                       options="{form:aggregateSelectOptions(model:model)}"
                        prependOptionLabel="{model.additionalArguments.prependOptionLabel}"
                        prependOptionValue="{model.additionalArguments.prependOptionValue}"
                        selectAllByDefault="{model.additionalArguments.selectAllByDefault}"
index 32e6eca..68101e5 100644 (file)
@@ -7,16 +7,66 @@
                </label>
                <ol>
 </f:if>
-<f:for each="<form:aggregateSelectOptions model='{model}' />" as="option">
+<f:for each="{form:aggregateSelectOptions(model:model)}" as="option">
        <f:if condition="{option.options}">
                <f:then>
                                <f:for each="{option.options}" as="optgroupOption">
-                                       <f:if condition="{optgroupOption.selected} == 'selected'">
+                                       <f:if condition="{optgroupOption.selected}">
                                                <f:if condition="{model.showElement}">
                                                        <li class="csc-form-element csc-form-element-{model.elementTypeLowerCase}">
                                                                {optgroupOption.label}
                                                        </li>
                                                </f:if>
+                                               <f:if condition="{model.additionalArguments.multiple}">
+                                                       <f:then>
+                                                               <f:form.hidden
+                                                                       class="{model.additionalArguments.class}"
+                                                                       dir="{model.additionalArguments.dir}"
+                                                                       id="{model.additionalArguments.id}"
+                                                                       lang="{model.additionalArguments.lang}"
+                                                                       style="{model.additionalArguments.style}"
+                                                                       title="{model.additionalArguments.title}"
+                                                                       accesskey="{model.additionalArguments.accesskey}"
+                                                                       tabindex="{model.additionalArguments.tabindex}"
+                                                                       onclick="{model.additionalArguments.onclick}"
+
+                                                                       name="{model.additionalArguments.prefix}[{model.additionalArguments.name}][]"
+                                                                       value="{optgroupOption.value}"
+
+                                                                       additionalAttributes="{model.htmlAttributes}"
+                                                               />
+                                                       </f:then>
+                                                       <f:else>
+                                                               <f:form.hidden
+                                                                       class="{model.additionalArguments.class}"
+                                                                       dir="{model.additionalArguments.dir}"
+                                                                       id="{model.additionalArguments.id}"
+                                                                       lang="{model.additionalArguments.lang}"
+                                                                       style="{model.additionalArguments.style}"
+                                                                       title="{model.additionalArguments.title}"
+                                                                       accesskey="{model.additionalArguments.accesskey}"
+                                                                       tabindex="{model.additionalArguments.tabindex}"
+                                                                       onclick="{model.additionalArguments.onclick}"
+
+                                                                       name="{model.additionalArguments.prefix}[{model.additionalArguments.name}]"
+                                                                       value="{optgroupOption.value}"
+
+                                                                       additionalAttributes="{model.htmlAttributes}"
+                                                               />
+                                                       </f:else>
+                                               </f:if>
+                                       </f:if>
+                               </f:for>
+               </f:then>
+               <f:else>
+                       <f:if condition="{option.selected}">
+                               <f:if condition="{model.showElement}">
+                                       <li class="csc-form-element csc-form-element-{model.elementTypeLowerCase}">
+                                               {option.label}
+                                       </li>
+                               </f:if>
+                               <f:if condition="{model.additionalArguments.multiple}">
+                                       <f:then>
                                                <f:form.hidden
                                                        class="{model.additionalArguments.class}"
                                                        dir="{model.additionalArguments.dir}"
                                                        onclick="{model.additionalArguments.onclick}"
 
                                                        name="{model.additionalArguments.prefix}[{model.additionalArguments.name}][]"
-                                                       value="{optgroupOption.value}"
+                                                       value="{option.value}"
 
                                                        additionalAttributes="{model.htmlAttributes}"
                                                />
-                                       </f:if>
-                               </f:for>
-               </f:then>
-               <f:else>
-                       <f:if condition="{option.selected} == 'selected'">
-                               <f:if condition="{model.showElement}">
-                                       <li class="csc-form-element csc-form-element-{model.elementTypeLowerCase}">
-                                               {option.label}
-                                       </li>
-                               </f:if>
-                               <f:form.hidden
-                                       class="{model.additionalArguments.class}"
-                                       dir="{model.additionalArguments.dir}"
-                                       id="{model.additionalArguments.id}"
-                                       lang="{model.additionalArguments.lang}"
-                                       style="{model.additionalArguments.style}"
-                                       title="{model.additionalArguments.title}"
-                                       accesskey="{model.additionalArguments.accesskey}"
-                                       tabindex="{model.additionalArguments.tabindex}"
-                                       onclick="{model.additionalArguments.onclick}"
+                                       </f:then>
+                                       <f:else>
+                                               <f:form.hidden
+                                                       class="{model.additionalArguments.class}"
+                                                       dir="{model.additionalArguments.dir}"
+                                                       id="{model.additionalArguments.id}"
+                                                       lang="{model.additionalArguments.lang}"
+                                                       style="{model.additionalArguments.style}"
+                                                       title="{model.additionalArguments.title}"
+                                                       accesskey="{model.additionalArguments.accesskey}"
+                                                       tabindex="{model.additionalArguments.tabindex}"
+                                                       onclick="{model.additionalArguments.onclick}"
 
-                                       name="{model.additionalArguments.prefix}[{model.additionalArguments.name}][]"
-                                       value="{option.value}"
+                                                       name="{model.additionalArguments.prefix}[{model.additionalArguments.name}]"
+                                                       value="{option.value}"
 
-                                       additionalAttributes="{model.htmlAttributes}"
-                               />
+                                                       additionalAttributes="{model.htmlAttributes}"
+                                               />
+                                       </f:else>
+                               </f:if>
                        </f:if>
                </f:else>
        </f:if>
index f8e7497..b37519f 100644 (file)
@@ -5,18 +5,18 @@
     <em>{model.additionalArguments.label}</em>
   </td>
   <td>
-<f:for each="<form:aggregateSelectOptions model='{model}' />" as="option">
+<f:for each="{form:aggregateSelectOptions(model:model)}" as="option">
 <f:if condition="{option.options}">
 <f:then>
 <f:for each="{option.options}" as="optgroupOption">
-<f:if condition="{optgroupOption.selected} == 'selected'">
-    <div class="csc-form-element csc-form-element-{model.elementTypeLowerCase}">{optgroupOption.value}</div>
+<f:if condition="{optgroupOption.selected}">
+    <div class="csc-form-element csc-form-element-{model.elementTypeLowerCase}">{optgroupOption.label}</div>
 </f:if>
 </f:for>
 </f:then>
 <f:else>
-<f:if condition="{option.selected} == 'selected'">
-    <div class="csc-form-element csc-form-element-{model.elementTypeLowerCase}">{option.value}</div>
+<f:if condition="{option.selected}">
+    <div class="csc-form-element csc-form-element-{model.elementTypeLowerCase}">{option.label}</div>
 </f:if>
 </f:else>
 </f:if>
index 1d6cba8..122c866 100644 (file)
@@ -1,3 +1,3 @@
-{namespace form=TYPO3\CMS\Form\ViewHelpers}<f:if condition="{model.showElement}"><form:plainMail labelContent="{model}" newLineAfterLabel="1" indent="4" /><f:for each="<form:aggregateSelectOptions model='{model}' />" as="option"><f:if condition="{option.options}"><f:then><f:for each="{option.options}" as="optgroupOption"><f:if condition="{optgroupOption.selected} == 'selected'"><form:plainMail content="{optgroupOption.value}" />
-</f:if></f:for></f:then><f:else><f:if condition="{option.selected} == 'selected'"><form:plainMail content="{option.value}" />
+{namespace form=TYPO3\CMS\Form\ViewHelpers}<f:if condition="{model.showElement}"><form:plainMail labelContent="{model}" newLineAfterLabel="1" indent="4" /><f:for each="{form:aggregateSelectOptions(model:model)}" as="option"><f:if condition="{option.options}"><f:then><f:for each="{option.options}" as="optgroupOption"><f:if condition="{optgroupOption.selected}"><form:plainMail content="{optgroupOption.label}" />
+</f:if></f:for></f:then><f:else><f:if condition="{option.selected}"><form:plainMail content="{option.label}" />
 </f:if></f:else></f:if></f:for><form:plainMail indent="-4"/></f:if>
\ No newline at end of file
index ff3382b..3dd57d0 100644 (file)
@@ -31,7 +31,7 @@
 
                        optionLabelField="label"
                        optionValueField="value"
-                       options='<form:aggregateSelectOptions model="{model}" />'
+                       options="{form:aggregateSelectOptions(model:model)}"
                        prependOptionLabel="{model.additionalArguments.prependOptionLabel}"
                        prependOptionValue="{model.additionalArguments.prependOptionValue}"
                        selectAllByDefault="{model.additionalArguments.selectAllByDefault}"