core.posting_modify_template_vars correction

These requests for events in core phpBB have been merged into 3.1/Ascraeus and will be available with the next release.
aleha
Registered User
Posts: 143
Joined: Tue Mar 26, 2013 2:19 am

Re: core.posting_modify_template_vars correction

Post by aleha »

After the reply of PayBas, which is correct, I updated my previous post in this topic. Not sure what changing the $template means.
Hmm, couldn't you pass the $template variable to your template event handler? ...assuming you use $template as a service so there is no need for globals.

User avatar
rfdy
Registered User
Posts: 45
Joined: Wed Apr 16, 2014 2:28 pm

Re: core.posting_modify_template_vars correction

Post by rfdy »

Also, we don't want to render a template in our extension, we want to use the existing template event.

User avatar
rfdy
Registered User
Posts: 45
Joined: Wed Apr 16, 2014 2:28 pm

Re: core.posting_modify_template_vars correction

Post by rfdy »

Didn't see your reply.

$template is the template object that renders the template and to which variables/data is assigned. We just need a way to set our own variables to the template, relying on the service injecting the template also isn't ideal, because then the $template gets injected to the constructor every single time, regardless of whether or not our event fires. This event is only on the posting page, so why inject the template any other time? That just confuses things, especially since there are other core template modification events that do exactly what is advertised, so why is this one so different?

By "template event" we mean an <!-- EVENT --> being called in the template that simply includes another piece of HTML/template, not a PHP event.

The flow:
- posting page loads
- template is assigned variables (the forum name, etc..)
- core event fires with the current state of the template obj (or the array): we add additional variables to the template
- the template is rendered
- a template event fires: our template file is included making use all the variables assigned to the template

Nicofuma
3.2 Release Manager
3.2 Release Manager
Posts: 299
Joined: Sun Apr 13, 2014 1:40 am
Location: Paris

Re: core.posting_modify_template_vars correction

Post by Nicofuma »

rfdy wrote:[...], especially since there are other core template modification events that do exactly what is advertised, so why is this one so different?[...]
Can you give a concrete example please?

And for the rest, i don't understand what is the problem if you get a dependence that you don't always use?
I think that the events should give only the "special" vars and not any unique public service that everyone can retrieve through the DI.
Member of the phpBB Development-Team
No Support via PM

User avatar
PayBas
Registered User
Posts: 305
Joined: Tue Jul 29, 2008 6:08 pm
Contact:

Re: core.posting_modify_template_vars correction

Post by PayBas »

rfdy wrote:We don't want to change the $template itself. We just want to assign more variables to it, so that our template event handler has access to them. Isn't that the point of the event, to modify the assigned variables before they get assigned?
You make it sound like a contradiction, but we are basically saying the same thing ;).

User avatar
rfdy
Registered User
Posts: 45
Joined: Wed Apr 16, 2014 2:28 pm

Re: core.posting_modify_template_vars correction

Post by rfdy »

Sorry to drag on this conversation, but the point is that the changes made by adding those additional variables to the event really doesn't help anybody if the one variable they need access to needs to be passed into the constructor. Events should be constructed in a way such that you're given all the local details you need at that moment, not rely on some global functionality (the $template service is just a fancy word for a global variable). All the other core events with "modify" in their name allow you to modify the data directly without additional constructor dependencies, however in this case the variables that are being sent with the event don't affect the template at all, hence the confusion with the name of the event. It's good that you're breaking the event vars, but changing those variables doesn't affect the template, because they're already assigned (unless they're assigned by reference, which just adds more confusion and isn't a desirable effect).

For now I will add the template to the constructor, even though my eight other events in that class don't need it and clutters up the code with additional dependencies making it harder to test.

User avatar
rfdy
Registered User
Posts: 45
Joined: Wed Apr 16, 2014 2:28 pm

Re: core.posting_modify_template_vars correction

Post by rfdy »

bump, would be very interested to hear opinions on last post

User avatar
PayBas
Registered User
Posts: 305
Joined: Tue Jul 29, 2008 6:08 pm
Contact:

Re: core.posting_modify_template_vars correction

Post by PayBas »

I reread all your posts, but I think we still need a concrete example of what you are trying to do (the actual use-case). I just can't get a clear idea of what your perceived problem is.

It's late, so please excuse me if I'm ignorant or misunderstood you.

User avatar
rfdy
Registered User
Posts: 45
Joined: Wed Apr 16, 2014 2:28 pm

Re: core.posting_modify_template_vars correction

Post by rfdy »

This thread isn't actually relevant anymore since the changes we requested were eventually made some time after beta 3.

Post Reply