Permalink
Browse files

Environment Label is ready for Craft 3!

  • Loading branch information...
michaelrog committed Dec 24, 2017
0 parents commit f8a3f3277c3cfe9aca8d03e2a192b4575d60d3cf
@@ -0,0 +1,11 @@
# Environment Label Changelog

_A plugin for Craft CMS 3.x to help distinguish your Craft environments ...so you don't forget where you are._

The format of this file is based on [Keep a Changelog](http://keepachangelog.com/). This project adheres to [Semantic Versioning](http://semver.org/).

## 3.0.0 - 2017-12-25

### Added

- Environment Label is ready for Craft 3!
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright (c) 2017 Michael Rog

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
138 README.md
@@ -0,0 +1,138 @@
# Environment Label

_...so you don't forget where you are._

**A [Top Shelf Craft](https://topshelfcraft.com) creation**
in collaboration with [Kind](https://madebykind.com/)

— Based on the original [LabelEnvironment](https://github.com/madebykind/craft.labelenvironment) plugin by [Tom Davies](https://github.com/tomdavies)


### TL;DR.

The _Environment Label_ plugin adds a nice coloured banner to your CraftCMS control panel so you'll never forget what environment you're using.

The colors and text of the environment label are configurable via the plugin config file.

![Screenshot](docs/dev.jpg)

* * *


## Installation

Visit the _Plugin Store_ in your Craft control panel, search for **Environment Label**, and click to _Install_ the plugin.


## Configuration

By default, the environment label will pull in the value of Craft's `CRAFT_ENVIRONMENT` constant, which is set to the current hostname unless you override it.

_(In other words, out of the box, you get a red banner with white text that alerts you to the current hostname.)_

You can use a plugin config file to tweak the appearance and text of the environment label for each installation.

Simply add an `environment-label.php` file to your `config` directory.

(There is a sample plugin config included in the plugin files - `config/environment-label.php` - which you can copy and use as a starter.

```php
<?php
return [
'showLabel' => true,
'labelText' => CRAFT_ENVIRONMENT,
'prefix' => null,
'suffix' => null,
'labelColor' => '#cc5643',
'textColor' => '#ffffff',
];
```

I suggest referencing [PHP environment variables](http://php.net/manual/en/function.getenv.php), rather than using hard-coded values, to make your configuration more consistently maintainable.

I also _highly recommend_ using the [PHP dot-env](https://github.com/vlucas/phpdotenv) package to easily set and deploy environment variables across your installations. (The [Craft starter project](https://github.com/craftcms/craft)) ships with dot-env included.)

For example, your `environment-label.php` config file might use environment variables set by the server:

```php
<?php
return [
'showLabel' => getenv('CRAFT_ENV_SHOW_LABEL'),
'labelText' => getenv('CRAFT_ENV_LABEL_TEXT'),
);
```

For added flexibility, the full text of the label will be rendered as a Twig template, so you can also include template variables if you want:

```php
<?php
return [
'suffixText' => " // {{ currentUser }}",
);
```


## Changing Settings in the Control Panel

You can also make basic changes to the text and appearance of the environment label via the plugin Settings page.

![Settings](docs/settings.jpg)

</div>

This is provided as a convenience for easily testing out the plugin, but for full customizability, you should use a plugin config file as described above.

(Settings specified in the plugin config file will override any changes made via the Settings page in the control panel.)


## Twig template globals

_Environment Label_ makes its properties available via a Twig template global variable, so you can create your own
environment label rendering in your public templates:

```twig
{{ environmentLabel.renderedText }}
{{ environmentLabel.labelColor }}
{{ environmentLabel.textColor }}
```

## JavaScript globals

_Environment Label_ also makes its properties available as JS globals on each authenticated CP page.

```js
window.CRAFT_ENVIRONMENT
window.CRAFT_ENVIRONMENT_LABEL
```

## What are the system requirements?

Craft 3.0+ and PHP 7.0+


## I've found a bug.

No you haven't.


## Yes, I believe I have.

Well, alright. Please open a [GitHub Issue](https://github.com/topshelfcraft/Environment-Label/issues), and if you're feeling ambitious, submit a PR to the `dev` branch.


* * *

### Contributors:

- Plugin development: [Michael Rog](http://michaelrog.com) / @michaelrog
- Craft 2 plugin development: [Tom Davies](https://github.com/tomdavies) / @metadaptive
- Icon: [NAS](http://nasztu.com/), via [The Noun Project](https://thenounproject.com/search/?q=label&i=28588)
@@ -0,0 +1,44 @@
{
"name": "topshelfcraft/environment-label",
"description": "...so you don't forget where you are.",
"type": "craft-plugin",
"version": "3.0.0",
"keywords": [
"craft",
"cms",
"craftcms",
"craft-plugin",
"environment label"
],
"support": {
"docs": "https://raw.githubusercontent.com/TopShelfCraft/Environment-Label",
"issues": "https://github.com/TopShelfCraft/Environment-Label/issues"
},
"license": "MIT",
"authors": [
{
"name": "Top Shelf Craft (Michael Rog)",
"homepage": "https://topshelfcraft.com"
}
],
"require": {
"craftcms/cms": "^3.0.0-RC3"
},
"autoload": {
"psr-4": {
"topshelfcraft\\environmentlabel\\": "src/"
}
},
"extra": {
"name": "Environment Label",
"handle": "environment-label",
"schemaVersion": "1.0.0",
"hasCpSettings": true,
"hasCpSection": false,
"changelogUrl": "https://raw.githubusercontent.com/TopShelfCraft/Environment-Label/master/CHANGELOG.md",
"components": {
"label": "topshelfcraft\\environmentlabel\\services\\Label"
},
"class": "topshelfcraft\\environmentlabel\\EnvironmentLabel"
}
}
@@ -0,0 +1,31 @@
<?php
/**
* Environment Label configuration
*
* This file is provided as a template.
* If you want to customize these plugin settings for your project,
* copy this `environment-label.php` file into your `config` directory,
* and un-comment the values you want to customize.
*
* I suggest using PHP environment variables, rather than hard-coded values,
* to make your configuration more consistently maintainable.
* (c.f. http://php.net/manual/en/function.getenv.php)
*
* I also suggest using the PHP dot-env package to make it easy to set and maintain
* environment variables across your installations. (The default Craft project ships with dot-env included.)
* (c.f. https://github.com/vlucas/phpdotenv)
*
* Some code examples are provided here for your reference...
*/
return [
// 'showLabel' => getenv('ENVIRONMENT_SHOW_LABEL'),
// 'labelText' => CRAFT_ENVIRONMENT,
// 'prefixText' => '',
// 'suffixText' => '',
// 'labelColor' => getenv('ENVIRONMENT_LABEL_COLOR'),
// 'textColor' => '#ffffff',
];
BIN +66.4 KB docs/dev.jpg
Binary file not shown.
BIN +64.9 KB docs/settings.jpg
Binary file not shown.
@@ -0,0 +1,101 @@
<?php
/**
* Environment Label
*
* @author Michael Rog <michael@michaelrog.com>, Tom Davies <tom@madebykind.com>
* @link https://topshelfcraft.com
* @copyright Copyright 2017, Top Shelf Craft (Michael Rog)
* @see https://github.com/topshelfcraft/Environment-Label
*/
namespace topshelfcraft\environmentlabel;
use Craft;
use craft\base\Plugin;
use topshelfcraft\environmentlabel\models\Settings;
use topshelfcraft\environmentlabel\services\Label;
use topshelfcraft\environmentlabel\twigextensions\EnvironmentLabelTwigExtension;
/**
* @author Michael Rog <michael@michaelrog.com>
* @package EnvironmentLabel
* @since 3.0.0
*
* @property Label $label
* @property Settings $settings
*
* @method Settings getSettings()
*/
class EnvironmentLabel extends Plugin
{
/*
* Static properties
*/
/**
* @var EnvironmentLabel
*/
public static $plugin;
/*
* Public methods
*/
/**
* Initializes the plugin, sets its static self-reference, registers the Twig extension,
* and adds the environment label as appropriate.
*/
public function init()
{
parent::init();
self::$plugin = $this;
Craft::$app->view->registerTwigExtension(new EnvironmentLabelTwigExtension());
EnvironmentLabel::$plugin->label->doItBaby();
}
/*
* Protected methods
*/
/**
* Creates and returns the model used to store the plugin’s settings.
*
* @return \topshelfcraft\environmentlabel\models\Settings|null
*/
protected function createSettingsModel()
{
return new Settings();
}
/**
* Returns the rendered settings HTML, which will be inserted into the content
* block on the settings page.
*
* @return string The rendered settings HTML
*
* @throws \Twig_Error_Loader
* @throws \yii\base\Exception
*/
protected function settingsHtml(): string
{
return Craft::$app->view->renderTemplate(
'environment-label/settings',
[
'settings' => $this->getSettings()
]
);
}
}
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="573.312px" height="521.277px" viewBox="17.981 61.095 573.312 521.277"
enable-background="new 17.981 61.095 573.312 521.277" xml:space="preserve">
<g>
<path d="M347.469,245.674c-13.354,0-25.881,5.196-35.318,14.633c-9.437,9.437-14.633,21.977-14.633,35.318
c0,13.348,5.196,25.894,14.633,35.318c9.431,9.437,21.971,14.639,35.318,14.639s25.888-5.202,35.319-14.639
c19.479-19.474,19.485-51.163,0-70.643C373.363,250.864,360.816,245.674,347.469,245.674z M365.67,313.821
c-4.859,4.859-11.328,7.534-18.201,7.534c-6.872,0-13.341-2.675-18.2-7.54c-4.859-4.853-7.534-11.322-7.534-18.195
c0-6.873,2.681-13.335,7.534-18.201c4.859-4.853,11.328-7.534,18.2-7.534c6.873,0,13.342,2.681,18.195,7.534
C375.707,287.462,375.707,303.79,365.67,313.821z"/>
<path d="M579.405,70.281c-6.011-6.01-13.648-9.186-22.105-9.186c-25.502,0-55.209,27.797-97.62,70.215
c-27.491,27.491-52.742,52.742-62.491,74.878l-44.364-44.364c-3.005-3.011-7.368-4.223-11.5-3.188l-68.507,17.13
c-2.13,0.532-4.076,1.634-5.63,3.188L23.127,423.008c-2.57,2.576-3.696,6.01-3.47,9.376c-2.711,4.602-2.129,10.568,1.708,14.547
c107.896,111.947,173.931,135.441,210.326,135.441c13.586,0,22.846-3.164,28.605-6.113c2.521-0.349,4.957-1.444,6.885-3.385
l196.966-196.966c1.549-1.548,2.656-3.495,3.189-5.63l17.136-68.514c1.028-4.125-0.178-8.488-3.188-11.5l-33.966-33.96
c27.552-5.489,60.924-25.63,90.655-55.355C587.832,151.09,605.256,96.138,579.405,70.281z M231.691,558.149
c-19.174,0-56.702-9.07-118.318-58.771c25.166,9.945,53.256,17.351,81.102,17.351c10.171,0,19.976-1.004,29.296-2.999
c0.306,13.005,2.767,30.569,12.216,44.266C234.659,558.095,233.227,558.149,231.691,558.149z M444.643,361.159L258.527,547.286
c-14.144-14.773-9.921-47.748-9.866-48.085c0.63-4.247-1.028-8.507-4.357-11.199c-3.341-2.705-7.858-3.445-11.86-1.934
c-11.463,4.271-24.235,6.456-37.969,6.456c-61.016,0-126.543-41.983-148.918-57.693l236.385-236.385l58.605-14.651l59.069,59.077
c1.017,1.297,2.105,2.583,3.36,3.843c1.102,1.096,2.283,2.087,3.513,3.029l52.81,52.81L444.643,361.159z M432.978,233.655
c-4.571,0-8.183-0.863-10.838-2.521l-2.987-2.986c-8.488-13.507,28.006-50.074,57.65-79.713
c26.641-26.64,63.122-63.115,80.497-63.115c2.08,0,3.476,0.587,4.981,2.093c13.274,13.274-0.208,55.19-41.438,96.415
C486.424,218.245,451.919,233.655,432.978,233.655z"/>
</g>
</svg>
Oops, something went wrong.

0 comments on commit f8a3f32

Please sign in to comment.