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

PHP Extender: Rendering #1602

Closed
franzliedke opened this issue Oct 17, 2018 · 2 comments
Closed

PHP Extender: Rendering #1602

franzliedke opened this issue Oct 17, 2018 · 2 comments
Assignees
Milestone

Comments

@franzliedke
Copy link
Contributor

We need another extender that allows setting variables when rendering a HTML frontend (e.g. the forum). This will replace code like this in the statistics extension:

public function addStatisticsData(Rendering $event)
{
    if ($event->isAdmin()) {
        $event->view->setVariable('statistics', array_merge(
            $this->getStatistics(),
            ['timezoneOffset' => $this->getUserTimezone()->getOffset(new DateTime)]
        ));
    }
}

Follow-up to #851.

@franzliedke franzliedke added this to the 0.1.0-beta.8 milestone Oct 17, 2018
@tobyzerner tobyzerner self-assigned this Oct 18, 2018
@tobyzerner
Copy link
Contributor

Since any work done on the HtmlDocument is related to a frontend, I'm thinking we can just add a new method to the Frontend extender:

(new Extend\Frontend('admin'))
    ->js(__DIR__.'/js/dist/admin.js')
    ->css(__DIR__.'/less/admin.less')
    ->document(function (HtmlDocument $document) {
        $document->payload['statistics'] = 'blah';
    })

Sound good?

@franzliedke
Copy link
Contributor Author

Yep, sounds good. I made this work, PR incoming...

Just note that for flarum/statistics, due to the size of the listener, I allowed registering callbacks by name (needs to pass the name of an invokable class, which is then built by the container):

(new Extend\Frontend('admin'))
    ->js(__DIR__.'/js/dist/admin.js')
    ->css(__DIR__.'/less/admin.less')
    ->document(Listener\AddStatisticsData::class)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants