Skip to content
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

made session flashes closeable with configuration #840

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

made session flashes closeable with configuration #840

wants to merge 5 commits into from

Conversation

lsv
Copy link
Contributor

@lsv lsv commented Apr 8, 2014

With the following configuration

mopa:
    flash:
        closeable: true

Session flashes are now closeable, meaning it adds the X to flash message

@isometriks
Copy link
Collaborator

Couple things.. You should probably just pass the parameter to the twig extension instead of passing the whole container, and I'm not sure about adding another global variable to Twig, I wonder if it makes more sense to make it a function and then call it when you want the value? I'm not really sure what the best option is for doing something like that.

@isometriks
Copy link
Collaborator

Also, we don't need the initRuntime / environment variable.

@lsv
Copy link
Contributor Author

lsv commented Apr 9, 2014

I dont know how to only pass the argument in the service, in Symfony 2.4 it would be something like this

<argument type="expression">@=container.hasParameter('mopa_bootstrap.flash.closeable') ? parameter('mopa_bootstrap.flash.closeable') : false</argument>

But in <2.4 I have no idea - I have tried with

<argument type="string">@=container.getParameter('mopa_bootstrap.flash.closeable')</argument>

But this obvious does not work - anybody knows which argument type it should be?

@isometriks
Copy link
Collaborator

%path.to.parameter%

You don't need expression language at all
On Apr 9, 2014 11:14 AM, "Martin Århof" [email protected] wrote:

I dont know how to only pass the argument in the service, in Symfony 2.4
it would be something like this

@=container.hasParameter('mopa_bootstrap.flash.closeable') ? parameter('mopa_bootstrap.flash.closeable') : false

But in <2.4 I have no idea - I have tried with

@=container.getParameter('mopa_bootstrap.flash.closeable')

But this obvious does not work - anybody knows which argument type it
should be?

Reply to this email directly or view it on GitHubhttps://github.com//pull/840#issuecomment-39975896
.

@isometriks
Copy link
Collaborator

And you'll either need to set the parameter regardless or do:

if (isset($config['flash']) {
    // ...
} else {
    $container->removeDefinition('mopa_bootstrap.twig.extension.bootstrap_flash');
}

@lsv
Copy link
Contributor Author

lsv commented Apr 9, 2014

Now if session_flash(true) is called, the X is always showed regardless of the config

If session_flash() is called, and no config is set, it will not show the X.

If the config

mopa_bootstrap:
    flash:
        closeable: true

is set, it will show the X

@isometriks
Copy link
Collaborator

Why are you using setting injection? Just add it to the constructor

@lsv
Copy link
Contributor Author

lsv commented Apr 9, 2014

Well, mostly Im fan of getters and setters, and not passing everything to the contructor - but well its a personal reference :)

@isometriks
Copy link
Collaborator

I mean, there's really no use for a setter here, the twig extension is pretty specific. I would just change the global variable to a function just like the mappings. No need to add global variables for this to be inserted into every single template render.

@phiamo
Copy link
Owner

phiamo commented Apr 28, 2014

@lsv any news?

@isometriks
Copy link
Collaborator

He made the changes. Only thing I'm not crazy about is the $close === null part, I think this could be done in twig with a |default()

@lsv
Copy link
Contributor Author

lsv commented Apr 30, 2014

Remember $this->closeable is always set as either true or false (false is standard)

Im pretty sure |default only gets called when the return value is null

@isometriks
Copy link
Collaborator

Yeah I get that, it just seems like an unnecessary thing to put in a getter. Could change it to just be like this:

close is null ? mopa_bootstrap_flash_closeable() : close

or

close|default(mopa_bootstrap_flash_closeable())

That should be fine too if you don't pass in a close argument.

@lsv
Copy link
Contributor Author

lsv commented Apr 30, 2014

So in the twig you want

{% if close is null %}
   {% set close %}{{ mopa_bootstrap_flash_closeable() }}{% endset %}
{% endif %}
{{ flash_messages.flash(mapping[type], message, close, use_raw, class, domain) }}

@isometriks
Copy link
Collaborator

{{ flash_messages.flash(mapping[type], message, close|default(mopa_bootstrap_flash_closeable()), use_raw, class, domain) }}

or

{% set close = close is null ? mopa_bootstrap_flash_closeable() : close %}
{{ flash_messages.flash(mapping[type], message, close, use_raw, class, domain) }}

I think the first is better

@lsv
Copy link
Contributor Author

lsv commented Apr 30, 2014

The second is so much more readable - the first is really hard to see what its actually does imo

@phiamo
Copy link
Owner

phiamo commented Sep 26, 2014

@lsv is this ready to merge ?

@isometriks
Copy link
Collaborator

I'd still like the weird getter to be fixed and needs a blank line before the return statement to be PSR.

@phiamo
Copy link
Owner

phiamo commented Jan 12, 2015

@lsv can you update the PR, then we could merge it asap..

@phiamo
Copy link
Owner

phiamo commented May 29, 2015

@isometriks what should we do with this?

@isometriks
Copy link
Collaborator

Eh, I don't like that variable passthrough though, I'd rather use |default like I suggested above. Plus needs to be rebased anyway so just leave it for now.

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.

3 participants