Globals are not auto-completed
Closed this issue · 4 comments
Describe the bug
Globals are not auto-completed
To reproduce
Steps to reproduce the behaviour:
- Create a global (e.g. 'website')
- Assign field to said global.
- Try to use the autocomplete functionality
Expected behaviour
The editor should auto-complete globals.
Screenshots
Other auto-completions do work:
Global auto-completion doesn't work:
Versions
- Plugin version: 1.0.5
- Craft version: 3.7.20
Not experiencing that behavior here. It's possible you just need to regenerate the auto-complete classes, can you try deleting them from storage/runtime/compiled_templates
and see if they regenerate with your globals in there as expected?
We might consider adding an event listener to invalidate the cache whenever:
- Globals are changed via
Globals::EVENT_AFTER_SAVE_GLOBAL_SET
Globals being saved is one of the few things that will cause new variables to be introduced into Twig templates (that and installing new plugins).
cc: @bencroker
So I was correct that we should add a listener to this event so that we invalidate the generated classes when a global set is saved, because they could be adding or renaming the injected globals.
However, globals still weren't showing up. It's because as of Craft CMS 3.7.8, Craft conditionally loads the GlobalsExtension
only if it's a frontend request. So if the autocomplete classes are regenerated via a CP request (which is most likely), the globals won't be present.
Now we manually add the globals to the mix every time, which should take care of the issue.
Addressed in: 0a2169e
Released as Craft Autocomplete 1.0.6 -> https://github.com/nystudio107/craft-autocomplete/releases/tag/1.0.6
Very cool!
Very cool indeed. Thanks for the release!