From ae687688221a87f73939cb9ab4f23d625ec64684 Mon Sep 17 00:00:00 2001 From: Jeroen van Leusden Date: Thu, 22 Jun 2017 11:46:12 +0200 Subject: [PATCH 1/3] [#25] Enable template hints in production when IP is in the developer IP list --- Helper/Config.php | 53 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/Helper/Config.php b/Helper/Config.php index d1621b0..a8ad420 100644 --- a/Helper/Config.php +++ b/Helper/Config.php @@ -1,39 +1,68 @@ appState = $appState; + $this->storeManager = $storeManager; + $this->developerHelper = $developerHelper; } - /** - * Check if the hints can be displayed, depends on the developer mode and if the url parameter is present. + * Check if the hints can be displayed. + * + * It will check if the url parameter is present. + * For production mode it will also check if the IP-address is in Developer Client Restrictions. * * @return bool */ public function isHintEnabled() { - $isDeveloperMode = $this->appState->getMode() === AppState::MODE_DEVELOPER; $isParamPresent = $this->_request->getParam('ath', false) === '1'; - return $isDeveloperMode && $isParamPresent; + + if ($isParamPresent) { + $applicationMode = $this->appState->getMode(); + $storeId = $this->storeManager->getStore()->getId(); + + if ($applicationMode === AppState::MODE_DEVELOPER || $this->developerHelper->isDevAllowed($storeId)) { + return true; + } + } + + return false; } } From 1007ffb0e1aa6c98f9c734f8f59943633ba02853 Mon Sep 17 00:00:00 2001 From: Jeroen van Leusden Date: Thu, 22 Jun 2017 12:27:09 +0200 Subject: [PATCH 2/3] Format code --- Block/Hints/Init.php | 30 +++++++++++------------------- Plugin/View/LayoutPlugin.php | 35 +++++++++++++++++------------------ etc/di.xml | 10 ++++------ etc/module.xml | 8 +++----- view/base/layout/default.xml | 9 ++++----- 5 files changed, 39 insertions(+), 53 deletions(-) diff --git a/Block/Hints/Init.php b/Block/Hints/Init.php index f9a9f87..0960196 100644 --- a/Block/Hints/Init.php +++ b/Block/Hints/Init.php @@ -1,6 +1,6 @@ isHintEnabled()) { $this->assetRepository = $context->getAssetRepository(); $this->assetCollection = $assetCollection; @@ -54,7 +47,6 @@ public function __construct( return parent::__construct($context, $data); } - /** * Add assets to the header required for the initialisation of the scripts * diff --git a/Plugin/View/LayoutPlugin.php b/Plugin/View/LayoutPlugin.php index efe5ced..d098915 100644 --- a/Plugin/View/LayoutPlugin.php +++ b/Plugin/View/LayoutPlugin.php @@ -1,8 +1,9 @@ hintConfig = $hintConfig; $this->directoryList = $directoryList; + $this->hintConfig = $hintConfig; $this->layout = $layout; $layoutReflection = new \ReflectionClass($this->layout); @@ -76,6 +71,7 @@ public function aroundRenderElement(Layout $layout, Closure $proceed, $name, $us if ($this->hintConfig->isHintEnabled() === false) { return $result; } + return $this->_decorateElement($result, $name); } @@ -120,8 +116,7 @@ private function _decorateElement($result, $name) */ public function decorateOuterElement($html, $attributes) { - - if (!$html) { + if (! $html) { return $html; } @@ -137,12 +132,13 @@ public function decorateOuterElement($html, $attributes) $html, 1 ); + return $html; } /** * @param string $nameInLayout - * @param [] $container + * @param array $container * * @return string */ @@ -198,8 +194,10 @@ public static function filterEscapeEncode(array $data) } /** - * Filter and escape the complete array + * Filter and escape the complete array. + * * @param $data + * * @return array */ private static function filterEscape($data) @@ -237,6 +235,7 @@ private function getBlockClass(\Magento\Framework\View\Element\AbstractBlock $bl $reflector = new \ReflectionClass($block); //@codingStandardsIgnoreLine $className = $reflector->getParentClass()->getName(); } + return $className; } } diff --git a/etc/di.xml b/etc/di.xml index 7fc7a75..14cfbf0 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -1,12 +1,10 @@ - + ~ Copyright © 2017 H&O E-commerce specialisten B.V. (http://www.h-o.nl/) + ~ See LICENSE.txt for license details. + --> + diff --git a/etc/module.xml b/etc/module.xml index 6b58580..de0e9fb 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,10 +1,8 @@ + ~ Copyright © 2017 H&O E-commerce specialisten B.V. (http://www.h-o.nl/) + ~ See LICENSE.txt for license details. + --> diff --git a/view/base/layout/default.xml b/view/base/layout/default.xml index 16c479b..df3c524 100644 --- a/view/base/layout/default.xml +++ b/view/base/layout/default.xml @@ -1,10 +1,9 @@ + ~ Copyright © 2017 H&O E-commerce specialisten B.V. (http://www.h-o.nl/) + ~ See LICENSE.txt for license details. + --> + From efef533ef955f7c3f19d83a4df220dda57a24f40 Mon Sep 17 00:00:00 2001 From: Jeroen van Leusden Date: Thu, 22 Jun 2017 12:32:47 +0200 Subject: [PATCH 3/3] Update version --- README.md | 2 +- composer.json | 6 +++++- etc/module.xml | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 63466e5..2e7ddf4 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ php bin/magento setup:upgrade ![Setting up PHPStorm](docs/phpstorm-config.png) ## Usage -1. Set your Magento 2 installation to developer mode. +1. Set your Magento 2 installation to developer mode (when in production mode make sure to add your IP-address in Developer Client Restrictions). 2. Add `?ath=1` to your URL to activate. 3. Open up your console in you Chrome/Firefox/Safari/~IE~ devtools. 4. hold (shift) diff --git a/composer.json b/composer.json index e114f27..b559615 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,6 @@ "php": "~5.5.0|~5.6.0|~7.0.0" }, "type": "magento2-module", - "version": "0.2.1", "license": "BSD-2-Clause", "autoload": { "files": [ @@ -21,5 +20,10 @@ "psr-4": { "Ho\\Templatehints\\": "" } + }, + "extra": { + "branch-alias": { + "dev-master": "0.2-dev" + } } } diff --git a/etc/module.xml b/etc/module.xml index de0e9fb..7528d5f 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -3,6 +3,7 @@ ~ Copyright © 2017 H&O E-commerce specialisten B.V. (http://www.h-o.nl/) ~ See LICENSE.txt for license details. --> + - +