diff --git a/CHANGELOG.md b/CHANGELOG.md index ce1b835..7fed7bd 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,29 +2,33 @@ All notable changes to this project will be documented in this file. +## 1.0.6 - 2021.11.17 +### Fixed +* Fixed an issue that prevented Globals from being included in the generated autocomplete class ([#8](https://github.com/nystudio107/craft-autocomplete/issues/8)) + ## 1.0.5 - 2021.10.30 ### Added -* feat: Added the `beforeGenerate` event to the base `Generator` class ([#7](https://github.com/nystudio107/craft-autocomplete/issues/7)). +* Added the `beforeGenerate` event to the base `Generator` class ([#7](https://github.com/nystudio107/craft-autocomplete/issues/7)). ## 1.0.4 - 2021.10.21 ### Added -* feat: Added support for plugins like Craft Commerce that add to the Craft variable via behaviors ([#6](https://github.com/nystudio107/craft-autocomplete/issues/6)) +* Added support for plugins like Craft Commerce that add to the Craft variable via behaviors ([#6](https://github.com/nystudio107/craft-autocomplete/issues/6)) ## 1.0.3 - 2021.09.22 ### Changed -* refactor: Clean up AutocompleteVariableGenerator to `get()` the components to load them +* Clean up AutocompleteVariableGenerator to `get()` the components to load them ### Fixed -* fix: Fixed an error that could be thrown when a plugin was uninstalled that contained references in the Twig context ([#5](https://github.com/nystudio107/craft-autocomplete/issues/5)). +* Fixed an error that could be thrown when a plugin was uninstalled that contained references in the Twig context ([#5](https://github.com/nystudio107/craft-autocomplete/issues/5)). ## 1.0.2 - 2021-09-02 ### Changed -* refactor: Code cleanup, removed vestigial code +* Code cleanup, removed vestigial code ## 1.0.1 - 2021-08-09 ### Changed -* refactor: Changed the Twig Extension Generator to only generate an autocomplete class if one does not already exist. +* Changed the Twig Extension Generator to only generate an autocomplete class if one does not already exist. ## 1.0.0 - 2021-08-08 ### Added -* feat: Initial release +* Initial release diff --git a/README.md b/README.md index faca85e..50684d5 100755 --- a/README.md +++ b/README.md @@ -162,7 +162,7 @@ class AutocompleteTwigExtension extends \Twig\Extension\AbstractExtension implem 'currentUser' => new \craft\elements\User(), // ... 'seomatic' => new \nystudio107\seomatic\variables\SeomaticVariable(), - 'sprig' => new \putyourlightson\sprigcore\variables\SprigVariable(), + 'sprig' => new \putyourlightson\sprig\variables\SprigVariable(), ]; } } diff --git a/composer.json b/composer.json index c79abf0..2508a86 100755 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "nystudio107/craft-autocomplete", "description": "Provides Twig template IDE autocomplete of Craft CMS & plugin variables", "type": "yii2-extension", - "version": "1.0.5", + "version": "1.0.6", "keywords": [ "craft", "cms", diff --git a/src/Autocomplete.php b/src/Autocomplete.php index d70417a..6eebc3a 100755 --- a/src/Autocomplete.php +++ b/src/Autocomplete.php @@ -20,6 +20,7 @@ use Craft; use craft\console\Application as CraftConsoleApp; use craft\events\RegisterComponentTypesEvent; +use craft\services\Globals; use craft\services\Plugins; use craft\web\Application as CraftWebApp; @@ -113,6 +114,7 @@ public function registerEventHandlers() { Event::on(Plugins::class,Plugins::EVENT_AFTER_INSTALL_PLUGIN, [$this, 'regenerateAutocompleteClasses']); Event::on(Plugins::class,Plugins::EVENT_AFTER_UNINSTALL_PLUGIN, [$this, 'deleteAutocompleteClasses']); + Event::on(Globals::class,Globals::EVENT_AFTER_SAVE_GLOBAL_SET, [$this, 'deleteAutocompleteClasses']); Event::on(Plugins::class,Plugins::EVENT_AFTER_LOAD_PLUGINS, [$this, 'generateAutocompleteClasses']); Craft::info('Event Handlers installed',__METHOD__); } diff --git a/src/generators/AutocompleteTwigExtensionGenerator.php b/src/generators/AutocompleteTwigExtensionGenerator.php index 0404a98..64e5f14 100644 --- a/src/generators/AutocompleteTwigExtensionGenerator.php +++ b/src/generators/AutocompleteTwigExtensionGenerator.php @@ -17,6 +17,7 @@ use Craft; use craft\base\Element; +use craft\web\twig\GlobalsExtension; use yii\base\Event; @@ -110,6 +111,7 @@ private static function generateInternal() $values = array_merge( $values, static::elementRouteVariables(), + static::globalVariables(), static::overrideValues() ); @@ -151,6 +153,23 @@ private static function elementRouteVariables(): array return $routeVariables; } + /** + * Add in the global variables manually, because Craft conditionally loads the GlobalsExtension as of + * Craft CMS 3.7.8 only for frontend routes + * + * @return array + */ + private static function globalVariables(): array + { + $globalVariables = []; + $globalsExtension = new GlobalsExtension(); + foreach ($globalsExtension->getGlobals() as $key => $value) { + $globalVariables[$key] = 'new \\' . get_class($value) . '()'; + } + + return $globalVariables; + } + /** * Override certain values that we always want hard-coded *