mardi 14 avril 2015

Symfony Form customize array for entity type

In my Symfony2.6.6 project I have a category entity. I don't know how to say that properly but use the doctrine tree extension to create a tree with the category entity like:



  • Category 1

    • Child Category 1

    • Child Category 2



  • Category 2

    • Child Category 3 ...




Now when creating the form type for creating a new Category I want to customize the array of the parent field.


The code I use



$builder->add('parent', 'entity', array('class' => 'AcmeBlogBundle:Category', 'property' => 'title'));


generates just an array with all the title as expected. But I want the array values to append a '-' for every level of the tree. Category 1 for example would be '- Category 1' and Child Category 1 would be '-- Child Category 1'. How can I do that?


Sorry if this has been asked before, I don't know how to search for that.


Aucun commentaire:

Enregistrer un commentaire