From 26f341a62b68f381275e787cb17b6660993b9491 Mon Sep 17 00:00:00 2001 From: Robert Egginton Date: Fri, 11 May 2018 16:41:53 +0100 Subject: [PATCH] Initial commit --- C3EnvironmentBanner.php | 27 ++++ Resources/services.xml | 16 ++ .../c3EnvironmentBanner/index/header.tpl | 31 ++++ Subscriber/Backend.php | 146 ++++++++++++++++++ composer.json | 13 ++ plugin.png | Bin 0 -> 811 bytes plugin.xml | 27 ++++ readme.md | 17 ++ 8 files changed, 277 insertions(+) create mode 100644 C3EnvironmentBanner.php create mode 100644 Resources/services.xml create mode 100644 Resources/views/backend/c3EnvironmentBanner/index/header.tpl create mode 100644 Subscriber/Backend.php create mode 100644 composer.json create mode 100644 plugin.png create mode 100644 plugin.xml create mode 100644 readme.md diff --git a/C3EnvironmentBanner.php b/C3EnvironmentBanner.php new file mode 100644 index 0000000..1c312c3 --- /dev/null +++ b/C3EnvironmentBanner.php @@ -0,0 +1,27 @@ +scheduleClearCache(InstallContext::CACHE_LIST_DEFAULT); + } + +} diff --git a/Resources/services.xml b/Resources/services.xml new file mode 100644 index 0000000..194759c --- /dev/null +++ b/Resources/services.xml @@ -0,0 +1,16 @@ + + + + + + + + %c3_environment_banner.plugin_dir% + + + + + diff --git a/Resources/views/backend/c3EnvironmentBanner/index/header.tpl b/Resources/views/backend/c3EnvironmentBanner/index/header.tpl new file mode 100644 index 0000000..a9caa3e --- /dev/null +++ b/Resources/views/backend/c3EnvironmentBanner/index/header.tpl @@ -0,0 +1,31 @@ +{block name="backend/base/header/css"} + {$smarty.block.parent} + {debug} + +{/block} diff --git a/Subscriber/Backend.php b/Subscriber/Backend.php new file mode 100644 index 0000000..099478f --- /dev/null +++ b/Subscriber/Backend.php @@ -0,0 +1,146 @@ + '0,255,0', + 'staging' => '255,127,0', + 'preview' => '255,0,255', + 'production' => '255,0,0' + ]; + + /** + * Backend constructor. + * + * @param string $pluginPath + * @param Container $container + */ + public function __construct( + $pluginPath, + Container $container + ) + { + $this->pluginPath = $pluginPath; + $this->container = $container; + } + + public static function getSubscribedEvents() + { + return [ + 'Enlight_Controller_Action_PostDispatchSecure_Backend_Index' + => 'onPostDispatchSecureBackendIndex' + ]; + } + + public function onPostDispatchSecureBackendIndex(\Enlight_Event_EventArgs $args) + { + // Get environment specific values + $environment = getenv('SHOPWARE_ENV'); + if (!isset($this->colorMap[$environment])) { + return; + } + $primaryColour = $this->colorMap[$environment]; + + // Add backend template + $this->container->get('Template')->addTemplateDir( + $this->getPath() . '/Resources/views/' + ); + $view = $args->getSubject()->View(); + $view->extendsTemplate('backend/c3EnvironmentBanner/index/header.tpl'); + + // Set environment-specific values for colour and label + $view->assign('environment', ucfirst($environment)); + $colVar = $colorVariants = $this->getColorVariants($primaryColour); + $view->assign('rgbBackGrad1', $colVar['lighter1']); + $view->assign('rgbBackGrad2', $colVar['lighter2']); + $view->assign('rgbBackGrad3', $colVar['lighter3']); + $view->assign('rgbBackGrad4', $colVar['lighter4']); + $view->assign('rgbBorderTop', $colVar['mid']); + $view->assign('rgbBorderBottom', $colVar['midDarker']); + } + + /** + * Calculate variations of primary colour as strings + * + * @param string $primaryColor + * + * @return array + */ + protected function getColorVariants($primaryColor) + { + $col = explode(',', $primaryColor); + + // Minimum and maximum values for RGB 0-255 for lightening effects + $lighterCoEfficients = [ + [171, 238], + [218, 245], + [223, 246], + [198, 246], + ]; + + // Calculate lighter versions of colours based on co-efficients + $lighter = []; + for ($i=0; $i implode(',',$mid), + 'midDarker' => implode(',',$midDarker), + 'lighter1' => implode(',',$lighter[0]), + 'lighter2' => implode(',',$lighter[1]), + 'lighter3' => implode(',',$lighter[2]), + 'lighter4' => implode(',',$lighter[3]) + ]; + } + + protected function getPath() + { + return $this->pluginPath; + } +} diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..d3e9503 --- /dev/null +++ b/composer.json @@ -0,0 +1,13 @@ +{ + "name": "c3/shopware-environment-banner", + "keywords": ["shopware", "development", "plugin"], + "description": "Environment backend styling plugin for Shopware to avoid accidental live changes", + "license": "MIT", + "type": "shopware-plugin", + "extra": { + "installer-name": "C3EnvironmentBanner" + }, + "require": { + "composer/installers": "~1.0" + } +} diff --git a/plugin.png b/plugin.png new file mode 100644 index 0000000000000000000000000000000000000000..7e6c74422261bc13e3af331fa3bb2a6ac3f3517d GIT binary patch literal 811 zcmV+`1JwM9P)7%Q6vr1Xa6;lz!4(8lrCccoBsif8R3S%?E{Z|{1&o3+>8>~3PGNgF7XbbrjorQyh1{WNdhoB6+)H(JT_ywI|& z&@|2eO|;(k{SXMHC}0>J1_Ky4FpP+N_89Jt&IH?`-|J%-27ijUB%H9{hpnK^x<13^ zN|KxW!B|!CrsIr~m$|_m))X6WMq?yfV!lB~?{F&;&~-hut=stRX;yx_pJ3@3#xv|DXaMhIw{7FwpL&`IECo?^3djO(og!>?lW z9)5`6@FB)>7W-5lXMcv^NQn*Ir`c%oyZEG5s}**;FmkW6s$XEVGRuau$y%v|H~TB2 z)B%OpB&%izN^U#&^fY{3^xsF14Qn zT#>C-szfH$YPGP{-lpwcA~Spxl^3wMg6o3M#9Y=%yY3A zE4id91J0edc=?#k$@d*9RR={;CIY!!F3c5jOq)M(sI`ydz2}IVGn^F#_RDZI2l3pH zSB{uS4-9$y>42rBKIwF3B9Km}!^K>Nx$Y%i*Pi8LUSrmpBbJB5*Wld(%oYZmIAQVF z6D}{l1k3pzvi!qDAel^tvMjTul~LMhmO5E(YAWNpPNr($*Sq|6t3y`NNL}raSu{}9 zCW*widriFf^+l#Wi|uiGir5!l5<7F6si{u|pAd`v%PGD&^8xeo-%kXhUovt+T?{&R p*%1imwqQq(lH5y1bIf}W{0~&@X99CHbX5QV002ovPDHLkV1nVehw}gc literal 0 HcmV?d00001 diff --git a/plugin.xml b/plugin.xml new file mode 100644 index 0000000..ae55683 --- /dev/null +++ b/plugin.xml @@ -0,0 +1,27 @@ + + + + + + + 1.0.0 + (c) by C3 + MIT + https://github.com/c3limited/C3ShopwareEnvironmentBanner + C3 + + + + How to use +

Once installed and active, the SHOPWARE_ENV environment variable will be used to determine what colour to display in the backend. Values recognised are: dev, staging, preview and production. Other values are ignored.

+ ]]> +
+ + + Erstveröffentlichung - Farbe für das Backend einstellen + First release - color for backend + + +
diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..b30c9a5 --- /dev/null +++ b/readme.md @@ -0,0 +1,17 @@ +C3 Shopware Environment Banner +============================== + +Once installed and active, the SHOPWARE_ENV environment variable will be used to determine what colour to display in the backend. Values recognised are: dev, staging, preview and production. Other values are ignored. + +Installation +------------ + +Copy the contents of this repo to a new folder C3EnvironmentBanner in custom/plugins/ and install and activate as normal via the admin panel or command line. + +## Installing via composer + +To install via composer, add this repo to the repository area of composer.json and run the following command: + +`composer require c3/shopware-environment-banner` + +Then install and activate as normal.