bolt / bolt

Bolt is a simple CMS written in PHP. It is based on Silex and Symfony components, uses Twig and either SQLite, MySQL or PostgreSQL.
MIT License
4.15k stars 811 forks source link

[BUG] Custom table schema won't be called when new twig globals are registered #5380

Closed PhillippOhlandt closed 8 years ago

PhillippOhlandt commented 8 years ago

When you install my ohlandt/user-profiles extension and bodenotter/seo, then you don't get a database update notification for adding the new user table fields. The reason is that my User Schema class is never be called when the Seo extension is installed.

When you look at the SeoExtension class at line 83, you will see the following function:

public function registerServices(Application $app)
{
    $seo = new SEO($this->getContainer(), $this->getConfig(), $this->version);
    $app['twig']->addGlobal('seo', $seo);
    $app['twig']->addGlobal('seoconfig', $this->getConfig());
}

When you remove the two addGlobal() function calls, my User Schema class will be called and everything works. @bobdenotter confirmed that this must be a Bolt issue.

Details

GwendolenLynch commented 8 years ago

This is an extension bug.

The registerServices function is for registering services, not using them as using them invokes them before the request cycle.

If you need to make a function/property call to service you can use $app->extend() to push that to when the container is finally built.

i.e. it should be more like:

public function registerServices(Application $app)
{
    $app['twig'] = $app->extend(
        'twig',
        function ($twig) ($app) {
                $seo = new SEO($this->getContainer(), $this->getConfig(), $this->version);
                $twig->addGlobal('seo', $seo);
                $twig->addGlobal('seoconfig', $this->getConfig());

                return $twig;
        }
    );
}
bobdenotter commented 8 years ago

I know nothing! 🙄