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

CraftVariable::EVENT_INIT event not working in modules since 3.0.5 #2831

Closed
Wiejeben opened this issue May 1, 2018 · 6 comments
Closed

CraftVariable::EVENT_INIT event not working in modules since 3.0.5 #2831

Wiejeben opened this issue May 1, 2018 · 6 comments

Comments

@Wiejeben
Copy link
Contributor

Wiejeben commented May 1, 2018

Description

After updating to 3.0.5, \craft\web\twig\variables\CraftVariable::EVENT_INIT stopped working inside my module, reverting back to 3.0.4 fixes this.

I have a feeling it might be broken because of this change:

610f7ac#diff-d735858371e00b6108b199120931723f

Steps to reproduce

  1. Make sure you are running 3.0.5.
  2. Add the following inside your (__construct() or) init() method inside your module that is being loaded on bootstrap:
// Register template variables
\yii\base\Event::on(
    \craft\web\twig\variables\CraftVariable::class,
    \craft\web\twig\variables\CraftVariable::EVENT_INIT,
    function(\yii\base\Event $event) {
        die('It won\'t');
    }
);
  1. Nothing happens.

Additional info

  • Craft version: 3.0.5
  • PHP version: 7.0.10
@brandonkelly
Copy link
Member

Working on my end. Do you have any plugins installed?

@Wiejeben
Copy link
Contributor Author

Wiejeben commented May 1, 2018

Ah right, I disabled all my plugins and noticed that fixed the error. Will be looking into the plugin that is causing the CraftVariable::EVENT_INIT to break.

@Wiejeben Wiejeben closed this as completed May 1, 2018
@brandonkelly
Copy link
Member

Most likely it’s because a plugin is actually loading Twig. If you can figure out which one, I can look into a better solution on my end.

@Wiejeben
Copy link
Contributor Author

Wiejeben commented May 1, 2018

Right, I did some more debugging.

SEOmatic does some stuff right after Plugins::EVENT_AFTER_LOAD_PLUGINS is triggered. At one point \craft\web\View::renderObjectTemplate is called, which ends up initialising CraftVariable. Because Plugins::EVENT_AFTER_LOAD_PLUGINS gets triggered before the modules are bootstrapped, I never get to catch the CraftVariable initialisation.

@khalwat
Copy link
Contributor

khalwat commented May 2, 2018

Happy to make whatever changes make sense. This is something I struggled with as well, where other plugins would be doing something with Twig, and it caused all sorts of havoc. That's why I do the bulk of my initialization in Plugins::EVENT_AFTER_LOAD_PLUGINS

@brandonkelly
Copy link
Member

brandonkelly commented May 2, 2018

As of the next release, plugins will be loaded before modules once again, but in a way that maintains the fix for #2761.

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

No branches or pull requests

3 participants