Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[WIP][Form] Add theming support for collections #4733

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 1 commit into from

Conversation

vicb
Copy link
Contributor

@vicb vicb commented Jul 3, 2012

This is a work in progress

This is an attempt to allow form collection theming.

Before this PR, it was not possible to apply a theme to all the children of a collection, you would have needed to cretate one block per child:

{% block _form_collection_0_label %}
    {# ... #}
{% endblock %}

You can now create a single theme that will be applied to all the children:

{% block _form_collection_children_label %}
    {# ... #}
{% endblock %}

@Burgov, @bschussek, everybody, any feedback ?

Todo:

  • Apply the theme to the prototype,
  • Add tests,
  • Restore BC (i.e. ability to theme a single children which must take precedence over the new theme),
  • Changelog,
  • Doc.

fix: #2806

@vicb
Copy link
Contributor Author

vicb commented Jul 3, 2012

hum... this would not work for nested collections, need some more work

@Burgov
Copy link
Contributor

Burgov commented Jul 3, 2012

I don't think the FormType should be cluttered with logic to theme collections. It's an evaluation that would have to be tested for every form field rendered, even though it would evaluate to true only rarely. What's your motivation for writing a new PR over #2806?

@vicb
Copy link
Contributor Author

vicb commented Jul 3, 2012

I don't think the FormType should be cluttered with logic to theme collections.

Kind of agree but changing $view->types is not ideal either.

With this PR you can (or you will be able to) theme any form under the collection: _collection_children_car_color_label.

It needs some more work so let's keep on discussing this tomorrow.

@vicb
Copy link
Contributor Author

vicb commented Jul 4, 2012

I have push a new implementation in some other branch.

In works in the same way as the current theming works:

  • you have to create a block named after the id of the element you want to theme,
  • replace any collection indexes by _children (ie _form_products_children_categories_children_label).

It also works with nested collections and prototypes.

Internals:

  • a theme_id variable has been added to all the view - its is basically the same as the id except that all numeric keys have been replaced by 'children`,
  • collection views have an added variable is_collection which is used to append children to the theme_id of their children,
  • I think the theme_id must be built at the same time as the views are created in order to be able to support nested collections.

If we can agree on this, I'll finish the PR based on this code.

@stof
Copy link
Member

stof commented Jul 4, 2012

@vicb does your alternate implementation supports theming a particular child of a collection ?

@vicb
Copy link
Contributor Author

vicb commented Jul 4, 2012

@stof the current code does not but this is a topic I would like to discuss before finalizing the code - implementing it would be very easy the question is to know if this is useful, only the extension (/helper) code would need to be modified.

If you ask the question, you should have a use case, right ?

@stof
Copy link
Member

stof commented Jul 4, 2012

@vicb I don't have a use case. It was simply to be sure as you talked about this possibility in the todo-list of the current PR.

@webmozart
Copy link
Contributor

This measure actually brings a huge performance boost, since now the templating engine doesn't have to check for every block in a row if it has been overridden for that specific row. For this specific form, this measure decreases rendering time from 7.7 to 2.5 seconds on my machine.

The conclusion is that overriding blocks per row certainly won't be supported.

@stof
Copy link
Member

stof commented Jul 14, 2012

@vicb Do you have time to continue this work ?

@webmozart
Copy link
Contributor

@stof I implemented it now, although slightly differently.

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants