sonata-project/SonataAdminBundle — Issue #443: Collection rendering
Author: andrewtch
Created: 2011-12-07 14:15:17+00:00
State: open

Hi everyone,

I'm talking about native 'collection' (not 'sonata_type_collection') in your bundle.

The question is following - I've 'array' type field in doctrine, and if I do

```php
->add('dimensions', 'collection')
```

it works pretty good, displaying all array members as separate text inputs. But, 'collection' supports two more keys - allow_delete and allow_add, like following:

```php
->add('dimensions', 'collection', array('allow_add' => true, 'allow_delete' => true))
```

and, as an admin generator user I expect to see "delete" button next to each field and "add" button in the end. This is not happening, since a 'collection' in rendered via default template called by `form_rest` function:

```twig
{% block collection_widget %}
{% spaceless %}
{% if prototype is defined %}
{% set attr = attr|merge({'data-prototype': form_row(prototype) }) %}
{% endif %}
{{ block('form_widget') }}
{% endspaceless %}
{% endblock collection_widget %}
```

javascript hooks in admin generator is not a good idea, I'd like to have a more flexible approach, and the only one available seems to rewrite `block collection_widget` (since FormExtension doesn't use blocks like 'collection_row_widget` or `collection_field_rows`). I've done it in local sandbox, but is seems not as pretty and customizable.

Is there another way to enable this behavior for all 'collection' elements? And if not, should this behavior be implemented in silex_form_div_layout?