Skip to content

Commit

Permalink
Merge branch 'release/1.0.6' into v1
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Nov 17, 2021
2 parents fe944c2 + 1a41835 commit 52c9746
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
18 changes: 11 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
];
}
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/Autocomplete.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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__);
}
Expand Down
19 changes: 19 additions & 0 deletions src/generators/AutocompleteTwigExtensionGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

use Craft;
use craft\base\Element;
use craft\web\twig\GlobalsExtension;

use yii\base\Event;

Expand Down Expand Up @@ -110,6 +111,7 @@ private static function generateInternal()
$values = array_merge(
$values,
static::elementRouteVariables(),
static::globalVariables(),
static::overrideValues()
);

Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit 52c9746

Please sign in to comment.