-
-
Notifications
You must be signed in to change notification settings - Fork 834
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
New extender for adding variables to HtmlDocument payload #1608
Conversation
@franzliedke I think that @tobscure had in mind (and mentioned a few times) is that Flarum flattens the extend.php array, so you can use the extenders in multiple files and require them (however that's done) in extend.php How would it work with the Listener, anyway? I don't see a specific method being called or anything... though that may be because of my nonexistent Laravel knowledge. |
@datitisev You mean having a separate file with a rather long extender callback instead of my proposed solution with an extra class? Not sure whether that works here, as we're just calling one more method on the |
The class would have an |
src/Extend/Frontend.php
Outdated
$callback = $container->make($this->documentCallback); | ||
} | ||
|
||
$view->addCallback($callback); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to add a new collection of "callbacks" to the HtmlDocumentFactory? That's what "content" is for. We could do this instead:
$content = new class implements ContentInterface {
public $callback;
public function populate(HtmlDocument $view, Request $request)
{
$this->callback($view, $request);
}
});
$content->callback = $callback;
$view->add($content);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, good point. What about getting rid of ContentInterface
and making those classes invokable, too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or we can keep the interface, and the existing listener class would implement that interface instead of being invokable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like your second suggestion, as per my comment in the other thread :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done this now. I changed ContentInterface
to use __invoke
instead of populate
, so that we can just drop in closures instead (we weren't type-hinting anyway).
f018574
to
1a9b9c7
Compare
1a9b9c7
to
d14afb0
Compare
d14afb0
to
4ed1d0a
Compare
All done from my side. |
flarum/statistics can now get by without implementing the |
Fixes #1602
Changes proposed in this pull request:
Add a
document()
method to theFrontend
extender as proposed in #1602.Reviewers should focus on:
The method accepts a closure as well as a class name, to allow for more complex logic to be encapsulated in a class.
Confirmed
php vendor/bin/phpunit
).Required changes: