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

g4-lisz at tonarchiv.ch g4-lisz at tonarchiv.ch
Tue Sep 9 06:30:12 CEST 2014


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



More information about the TYPO3-project-typo3v4mvc mailing list