How to modify page contents within a package?

Permalink
In concrete5.6 we could use the "on_page_output" event or alternatively combination of "on_before_render" and "on_render_complete" to modify the page output in packages.

I believe neither of these methods no longer work. The first one would be the obvious one to use but as currently in the core code, this event does not let us modify the output. It only fires and we can do some other stuff when it hits that event. This line shows you that after the event is fired, the view class does not replace the contents with the resulting content:
https://github.com/concrete5/concrete5-5.7.0/blob/d7ac3892ffc7145189...

Is this an oversight or is there an alternative way of doing this?

Sure, we could modify the contents right there, print it out there and then exit but it feels very wrong. And would also prevent any other packages from firing up.

It also seems that this event is fired for all the views during the page request, including block views. Although, we can of course check that the event object passed to the callback has the "contents" argument set to it, I'm not sure if it's conceptually correct to fire the "on_PAGE_output" event also for block views and possibly other views as well...

EDIT:
And don't get me wrong above, I think it is very useful if we could also modify the block output but I just think the event name is not correct in that context.

Mainio
 
andrew replied on at Permalink Reply
andrew
Yeah, this is an oversight. I think what we'd want to do here is use a custom Event class, which has a $content parameter inside it. We set the content parameter to what we're going to deliver, then we make sure to retrieve the content from the event class

$ev = new PageViewEvent($c);
$ev->setContent($contents);
$ev = Events::dispatch('on_page_output', $ev);
$contents = $ev->getContent();


That way the event (and this would work with multiple) will fire and return its content properly. Something like that.

Not really on the radar at the moment but we'd totally take a pull request for it and get it into 5.7.3.
Mainio replied on at Permalink Reply
Mainio