[TYPO3-mvc] T3 6.2: Checkbox Viewhelper and n:m Relation - Wrong field name

Jonas Eberle jonas.eberle at d-mind.de
Thu Nov 13 14:14:33 CET 2014


I am at the same point right now (managing sets of attributes that can 
be switched on or off in an n:m-property with Fluid forms).

Did you find an elegant solution?

Regards,
Jonas

Am 09.09.2014 um 06:30 schrieb g4-lisz at tonarchiv.ch:
> I wonder how checkbox viewhelper should be used for n:m properties of an
> object.
>
> Let's say we have an object Shop with property Category which is n:m
> related, i.e. each shop may have one or more categories.
>
> In T3 i used an array for this type of property, which was mapped and
> added to a object storage in the setter method (and vice versa in getter):
>
>      /**
>       * Set the categoryArray
>       *
>       * @param array $categoryArray
>       * @return void
>       */
>      public function setCategoryArray($categoryArray) {
>          $categoryRepository =
> t3lib_div::makeInstance('Tx_Myext_Domain_Repository_CategoryRepository');
>         
>          $this->categories = new Tx_Extbase_Persistence_ObjectStorage;
>             
>          foreach($categoryArray as $category_id){
>              $category = $categoryRepository->findByUid($category_id);
>              $this->addCategory($category);
>          }
>      }
>
> This was ugly, but it was the only way to have the checkboxes checked
> correctly by the viewhelper:
>
>                <f:for each="{categories}" as="category">
>                    <div class="innerRow">
>                        <label>
>                            <f:form.checkbox property="categoryArray"
> value="{category.uid}"/>
>                            {category.name}
>                        </label>
>                    </div>
>                </f:for>
>
> I.e. the appropriate checkboxes are checked when the form is loaded.
>
> With the new property mapper i get a problem: The checkbox viewhelper
> renders the Category property as a string and not as an array:
> ...
>    
> <input type="checkbox" value="1" name="tx_myext_fe_shopedit[shop][categories]">Cat
> 1
> ...
>    
> <input type="checkbox" value="2" name="tx_myext_fe_shopedit[shop][categories]">Cat
> 2
>
> I get the error: #1297759968: Exception while property mapping at
> property path "categoryArray":No converter found which can be used to
> convert from "string" to "array"
>
> So what is the right way to do this?
> Why does the viewhelper not render the property as an array?
>     i.e.
> <input type="checkbox" value="1" name="tx_myext_fe_shopedit[shop][categories][]">Cat
> 1 (like with T4.6)
>
> Cheers,
> Till
>
> _______________________________________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc


-- 
Neu: Portal Region Stuttgart - www.region-stuttgart.de
Neu: emobil-in-bw.de
Neukunde: Statistisches Landesamt BaWü
--------------------------------
d-mind bei Facebook: http://www.facebook.com/werbeagentur.internetagentur.stuttgart
--------------------------------
d-mind
Fuchs/Weiß/Strobel GbR
Mörikestraße 69
70199 Stuttgart
Tel.: +49 711 280481-1 (Durchwahl: -18)
Fax: +49 711 2804813
Inhaber: Jens Fuchs, Michael Weiß, Jens Strobel
www.d-mind.de



More information about the TYPO3-project-typo3v4mvc mailing list