Skip to content

Allow for the theming of specific fields within a collection type #2806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

Burgov
Copy link
Contributor

@Burgov Burgov commented Dec 8, 2011

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes

At this moment it is not possible to theme fields in a collection form using blocks, other than:

{% _form_name_0_fieldname_widget %}

0 begin the row index.

This patch adds the name of the type within the collection type to the list of types which allows overriding:

{% _nameofrowtype_fieldname_widget %}

@fabpot
Copy link
Member

fabpot commented Mar 23, 2012

Can you also update the CHANGELOG?

foreach($view->getChildren() as $rowName => $rowView) {
foreach($rowView->getChildren() as $fieldName => $fieldView) {
$rowTypes = $form->get($rowName)->getTypes();
$rowTypeName = $rowTypes[count($rowTypes) - 1];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be move to the outer loop

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx, fixed

@Burgov
Copy link
Contributor Author

Burgov commented Mar 25, 2012

@fabpot: done

also refactored, added a test and rebased onto master

@stof
Copy link
Member

stof commented Apr 4, 2012

@Burgov Please rebase your branch. It conflicts with master because of the move of the tests

@fabpot ping

@Burgov
Copy link
Contributor Author

Burgov commented Apr 4, 2012

@stof done

@stof
Copy link
Member

stof commented Apr 4, 2012

@vicb is it mergeable as is or is there something else to change ? you know the form theming better than me.

@vicb
Copy link
Contributor

vicb commented Apr 4, 2012

I am not sure if playing with the types is the best we can do. I have to check but I won't have time before next week.

@llambeau
Copy link

Hi,

What about this patch? Is it merged anywhere? Is there any other way having custom templating for fields inside a CollectionType?

Thanks

@Burgov
Copy link
Contributor Author

Burgov commented Jul 3, 2012

Updated to be up to date with 2.1 (and it appeared to be broken as some later changes went missing)
@vicb Let me know your opinion about this one vs #4733.

I'm thinking about exactly what we want to be able to reference how.

This PR only sets an extra type name for children of collection children, e.g. $this->factory->create('listOfTexts', null, array('type' => new AuthorType)), leaving out collections consisting of simple types, e.g. $this->factory->create('listOfAuthors', null, array('type' => 'text')), which is what #4733 focuses on.

Suggestions:
direct children of collections:

_collectionName_childName_widget, e.g. _listOfTexts_text_widget

children of children in collections:

_collectionName_childName_childChildName, e.g. _listOfAuthors_author_firstName_widget
and/or
_childName_childChildName, e.g. __listOfAuthors_author_firstName_widget

fabpot added a commit that referenced this pull request Jul 14, 2012
Commits
-------

69e5e58 [Form] Individual rows of CollectionType cannot be styled anymore for performance reasons

Discussion
----------

[Form] Individual rows of CollectionType cannot be styled anymore

Bug fix: no
Feature addition: no
Backwards compatibility break: **yes**
Symfony2 tests pass: yes
Fixes the following tickets: #2806, #4733
Todo: -

Individual theming of blocks in a row of a collection form is now unsupported:

```
{% block _author_tags_0_label %}
    {# ... #}
{% endblock %}

{% block _author_tags_1_label %}
    {# ... #}
{% endblock %}
```

Instead, it is now possible to define a generic template for all rows, where the word "entry" replaces the previous occurence of the row index:

```
{% block _author_tags_entry_label %}
    {# ... #}
{% endblock %}
```

The main motivation for this change is performance. Looking up whether individual styles exist for each single block within each row costs a lot of time. Because the row index is included in the block names, caching is virtually impossible.

For [this specific, heavy form](http://advancedform.gpserver.dk/app_dev.php/taxclasses/1), this PR decreases rendering time from **7.7** to **2.5 seconds** on my machine.

---------------------------------------------------------------------------

by fabpot at 2012-07-14T10:55:29Z

@bschussek Can you also create a PR on symfony docs to update the documentation?
@fabpot fabpot closed this Jul 14, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants