Permalink
Browse files

Added a proper TwigExtension to solve order-of-loading conflicts w/ r…

…egistering Twig global. (Fixes #6.) Changed craftcms/cms dependency to use 3.0.
  • Loading branch information...
michaelrog committed Nov 2, 2018
1 parent c326665 commit 3c719c6844201830c08cdd3d8c438c5050351c9c
Showing with 60 additions and 5 deletions.
  1. +8 −0 CHANGELOG.md
  2. +2 −2 composer.json
  3. +4 −3 src/EnvironmentLabel.php
  4. +46 −0 src/twigextensions/EnvironmentLabelTwigExtension.php
@@ -5,6 +5,14 @@ _A plugin for Craft CMS 3.x to help distinguish your Craft environments ...so yo
The format of this file is based on ["Keep a Changelog"](http://keepachangelog.com/). This project adheres to [Semantic Versioning](http://semver.org/). Version numbers follow the pattern: `MAJOR.FEATURE.BUILD`
## 3.1.5 - 2018-11-02
### Fixed
- Fixed order-of-loading conflicts that could generate an error when Environment Label tried to add a Twig global. ([#6](https://github.com/TopShelfCraft/Environment-Label/issues/6))
- Add `craftcms/cms` 3.0 as a requirement. (Required by plugin store)
## 3.1.4 - 2018-06-05
### Fixed
@@ -2,7 +2,7 @@
"name": "topshelfcraft/environment-label",
"description": "...so you don't forget where you are.",
"type": "craft-plugin",
"version": "3.1.4",
"version": "3.1.5",
"keywords": [
"craft",
"cms",
@@ -22,7 +22,7 @@
}
],
"require": {
"craftcms/cms": "^3.0.0-RC15"
"craftcms/cms": "^3.0"
},
"autoload": {
"psr-4": {
@@ -15,6 +15,7 @@
use craft\web\View;
use topshelfcraft\environmentlabel\models\Settings;
use topshelfcraft\environmentlabel\services\Label;
use topshelfcraft\environmentlabel\twigextensions\EnvironmentLabelTwigExtension;
use yii\base\Event;
@@ -55,10 +56,10 @@ class EnvironmentLabel extends Plugin
public function init()
{
parent::init();
self::$plugin = $this;
parent::init();
self::$plugin = $this;
Craft::$app->getView()->getTwig()->addGlobal('environmentLabel', EnvironmentLabel::$plugin->label);
Craft::$app->getView()->registerTwigExtension(new EnvironmentLabelTwigExtension());
Event::on(
View::class,
@@ -0,0 +1,46 @@
<?php
/**
* Environment Label
*
* @author Michael Rog <michael@michaelrog.com>
* @link https://topshelfcraft.com
* @copyright Copyright 2018, Top Shelf Craft (Michael Rog)
* @see https://github.com/topshelfcraft/Environment-Label
*/
namespace topshelfcraft\environmentlabel\twigextensions;
use topshelfcraft\environmentlabel\EnvironmentLabel;
/**
* @author Michael Rog <michael@michaelrog.com>
* @package EnvironmentLabel
* @since 3.1.5
*/
class EnvironmentLabelTwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface
{
/*
* Public methods
* ===========================================================================
*/
/**
* Returns the name of the extension.
*
* @return string The extension name
*/
public function getName()
{
return 'Environment Label';
}
/**
* @inheritdoc
*/
public function getGlobals()
{
return ['environmentLabel' => EnvironmentLabel::$plugin->label];
}
}

0 comments on commit 3c719c6

Please sign in to comment.