-
-
Notifications
You must be signed in to change notification settings - Fork 71
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
Unable to register extension "nystudio107\seomatic\twigextensions\SeomaticTwigExtension #937
Comments
Confirmed that disabling SEOMatic resolves the issue |
Exactly how are you intercepting the request? SEOmatic doesn't do anything particularly fancy, it just registers the Twig extension here: https://github.com/nystudio107/craft-seomatic/blob/v3/src/Seomatic.php#L491 |
In a custom module to verify IP addresses to the control panel, essentially a simplified version of this: https://github.com/sjelfull/craft3-restrict |
Can you show me some code though? Are you doing it inside of an event or such? It's possible you might want to wrap it in: // Handler: Plugins::EVENT_AFTER_LOAD_PLUGINS
Event::on(
Plugins::class,
Plugins::EVENT_AFTER_LOAD_PLUGINS,
function () {
// Do stuff here
}
); ...or some other event? |
Thanks that did the trick, wrapping our security service call to check IP addresses in the above works as expected. Not working:
Working:
Is there any obvious reason why this was working previously (again I assume around the release of Craft 3.7) - it seems that SEO Matic would try and reinitialise its extensions on Craft's standard error pages (like a 403 to the admin panel). Also is the general consensus to intercept CP requests after plugins have loaded regardless if they actually affect CP requests - in this instance why do SEO templates need to be injected into the CP at all given we don't want SEO there? |
It could be a regression in 3.7, I don't know -- but SEOmatic isn't doing anything particularly fancy here. I'd imagine other plugins that register Twig extensions would cause the same issue. That said, I have not run into this error on Craft 3.7 myself yet. If you're able to reproduce it with another plugin that registers a Twig extension, you might consider filing an issue with P&T |
What's likely happening is:
So any plugin that loads after yours, and also registers a Twig extension should throw this error. In general, you shouldn't do anything that will cause Twig to render until after all plugins have loaded because of this. I've filed an issue before with P&T about formalizing the loading process to provide information on such things previously. As for not wanting SEO, SEOmatic doesn't inject any SEO information in the CP, nor does it inject SEO tags on non-200 result code pages. But it does need to load in order to facilitate previews, etc. |
Makes sense thanks, happy to close this with provided work around |
The only thing I'm unclear on is how/why the plugin loading process would continue if a frontend exception was thrown. Perhaps you need to terminate the request yourself? If you did that, you could avoid listening to the event. |
Terminating the request doesn't resolve the issue, I prefer having Craft (or any framework we use) handle the intialisation process so as long as your insights are confirmed by P&T then this looks good. Do you have a GH issue or discussion to reference (in case anyone else comes looking) |
It was so long ago, I can't remember honestly. It also might have been just a conversation with Brandon. I can't recall. |
Describe the bug
When explicitly throwing a 403 error in Craft (preventing access to the admin panel), we are seeing an internal server error that appears to be caused by the following:
Note we are only seeing this when DEV mode is disabled and logged out of the CP. This previously worked without issue (probably before Craft 3.7).
To reproduce
Steps to reproduce the behaviour:
Craft::$app->getRequest()->isCpRequest
)throw new HttpException(403, "Access to the control panel is restricted"
)Unable to register extension
Expected behaviour
Craft's standard error template should be displayed
Screenshots
This is shown on the front end
This is the error in the logs
This should shown on the front end:
Versions
The text was updated successfully, but these errors were encountered: