Skip to content

[profiler] Fix conditional expression to provide a default value #16653

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
Closed

[profiler] Fix conditional expression to provide a default value #16653

wants to merge 1 commit into from

Conversation

krzysiekpiasecki
Copy link
Contributor

Fix conditional expression to provide a default value and prevent from the exception

From the cookbook:
{# the 'link' value set to 'false' means that this panel doesn't show a section in the web profiler (default is 'true'). #}

Simple conditional expression is not enough to provide a default value for the link parameter if is missed.

 {% if link %}

Custom collector

{{ include('@WebProfiler/Profiler/toolbar_item.html.twig') }}

WebProfiler/Profiler/toolbar_item.html.twig

 {% if link %}

From the cookbook:
<cite>{# the 'link' value set to 'false' means that this panel doesn't show a section in the web profiler (default is 'true'). #}</cite>

Simple conditional expression is not enough to provide a default value for the link parameter
```twig
 {% if link %}
```
@krzysiekpiasecki krzysiekpiasecki changed the title Fix conditional expression to provide a default value [profiler] Fix conditional expression to provide a default value Nov 24, 2015
@xabbuh
Copy link
Member

xabbuh commented Nov 24, 2015

Shouldn't we rather ensure that the link variable is always defined?

@krzysiekpiasecki
Copy link
Contributor Author

Not necessarily. In principle, data profiles include a larger area, so view of the details is the expected function. Otherwise documentation differs from implementation.

@fabpot
Copy link
Member

fabpot commented Nov 25, 2015

ping @javiereguiluz

@stof
Copy link
Member

stof commented Dec 5, 2015

given that this template is meant to be included by collector templates from any bundle, we cannot ensure it is always defined (except by putting a id defined check at the beginning of the template to initialize it, which would be equivalent to this PR).
So it may make sense to simplify it (but bundle supporting 2.7 and older would always have to pass it explicitly though)

@javiereguiluz
Copy link
Member

@xabbuh I think @krzysiekpiasecki is right because according to the documentation:

  • If you say nothing, we show a link
  • If you say link: true, we show a link
  • If you say link: false, we don't show the link

My only comment for @krzysiekpiasecki is this one: do you think we could replace {% if link is not defined or link %} condition by {% if link|default(true) %} ?

@krzysiekpiasecki
Copy link
Contributor Author

Yes, you could.

@javiereguiluz
Copy link
Member

@krzysiekpiasecki if you have some more time for this, please change the condition so we can merge this. Thanks a lot!

@fabpot
Copy link
Member

fabpot commented Jan 25, 2016

Closing this one, I'm going to create a new PR on 2.3 with @javiereguiluz suggestion.

@fabpot fabpot closed this Jan 25, 2016
fabpot added a commit that referenced this pull request Jan 25, 2016
This PR was merged into the 2.3 branch.

Discussion
----------

fixed undefined variable

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #16653
| License       | MIT
| Doc PR        | n/a

Commits
-------

4b21351 fixed undefined variable
fabpot added a commit that referenced this pull request Mar 1, 2016
…moving inadvertently added links (craue)

This PR was merged into the 2.3 branch.

Discussion
----------

[2.3][WebProfilerBundle] fix debug toolbar rendering by removing inadvertently added links

| Q             | A
| ------------- | ---
| Branch        | 2.3+
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

The debug toolbar was broken by #17527...

**before**
![debug-toolbar-link-a](https://cloud.githubusercontent.com/assets/800119/13433728/7c48c382-dfd3-11e5-8432-299bfa143647.png)

**and after**
![debug-toolbar-link-b](https://cloud.githubusercontent.com/assets/800119/13433732/7fd97dc0-dfd3-11e5-80c6-62c009447a2e.png)

**explanation**
If `false` is explicitly passed for `link` then `link | default(true)` would evaluate to `true`, which is not what we want. The correct expression `link is not defined or link` was suggested originally in #16653.

Commits
-------

a0ddfc4 fix debug toolbar rendering by removing inadvertently added links
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.

6 participants