Skip to content

Commit

Permalink
Merge pull request #26 from ho-nl/develop
Browse files Browse the repository at this point in the history
Release v0.2.2
  • Loading branch information
Jeroen authored Jun 22, 2017
2 parents ff5c8c0 + efef533 commit f7ddfc2
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 68 deletions.
30 changes: 11 additions & 19 deletions Block/Hints/Init.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright (c) 2016 H&O E-commerce specialisten B.V. (http://www.h-o.nl/)
* Copyright © 2017 H&O E-commerce specialisten B.V. (http://www.h-o.nl/)
* See LICENSE.txt for license details.
*/

Expand All @@ -12,39 +12,32 @@
use Magento\Framework\View\Element\Context;

/**
*
*
* @package Ho\Templatehints\Block\Hints
*/
class Init extends AbstractBlock
{
/**
* A repository service for view assets
* @var \Magento\Framework\View\Asset\Repository
* A repository service for view assets.
*
* @var \Magento\Framework\View\Asset\Repository $assetRepository
*/
protected $assetRepository;
private $assetRepository;

/**
* List of page assets that combines into groups ones having the same properties
* @var AssetCollection
* List of page assets that combines into groups ones having the same properties.
*
* @var AssetCollection $assetCollection
*/
protected $assetCollection;

private $assetCollection;

/**
* Constructor
*
* @param Context $context
* @param AssetCollection $assetCollection
* @param Config $config
* @param array $data
*/
public function __construct(
Context $context,
AssetCollection $assetCollection,
Config $config,
array $data = []
) {
public function __construct(Context $context, AssetCollection $assetCollection, Config $config, array $data = [])
{
if ($config->isHintEnabled()) {
$this->assetRepository = $context->getAssetRepository();
$this->assetCollection = $assetCollection;
Expand All @@ -54,7 +47,6 @@ public function __construct(
return parent::__construct($context, $data);
}


/**
* Add assets to the header required for the initialisation of the scripts
*
Expand Down
53 changes: 41 additions & 12 deletions Helper/Config.php
Original file line number Diff line number Diff line change
@@ -1,39 +1,68 @@
<?php
/**
* Copyright (c) 2016 H&O E-commerce specialisten B.V. (http://www.h-o.nl/)
* Copyright © 2017 H&O E-commerce specialisten B.V. (http://www.h-o.nl/)
* See LICENSE.txt for license details.
*/

namespace Ho\Templatehints\Helper;

use Magento\Developer\Helper\Data as DeveloperHelper;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Magento\Framework\App\State as AppState;
use Magento\Store\Model\StoreManagerInterface;

class Config extends AbstractHelper {

/**
* @var AppState
*/
class Config extends AbstractHelper
{
/** @var AppState $appState */
private $appState;

/** @var StoreManagerInterface $storeManager */
private $storeManager;

public function __construct(Context $context, AppState $appState)
{
/** @var DeveloperHelper $developerHelper */
private $developerHelper;

/**
* @param Context $context
* @param AppState $appState
* @param StoreManagerInterface $storeManager
* @param DeveloperHelper $developerHelper
*/
public function __construct(
Context $context,
AppState $appState,
StoreManagerInterface $storeManager,
DeveloperHelper $developerHelper
) {
parent::__construct($context);

$this->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;
}
}
35 changes: 17 additions & 18 deletions Plugin/View/LayoutPlugin.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php
/**
* Copyright (c) 2016 H&O E-commerce specialisten B.V. (http://www.h-o.nl/)
* Copyright © 2017 H&O E-commerce specialisten B.V. (http://www.h-o.nl/)
* See LICENSE.txt for license details.
*/

namespace Ho\Templatehints\Plugin\View;

use Closure;
Expand All @@ -12,36 +13,30 @@
use Magento\Framework\View\Layout\Data\Structure;

/**
* When a block is rendered
* When a block is rendered.
*
* Class LayoutPlugin
* @package Ho\Templatehints\Plugin\View
*/
class LayoutPlugin
{

/**
* Layout model
* Layout model.
*
* @var Layout
* @var Layout $layout
*/
private $layout;

/**
* Magento directory listing
* Magento directory listing.
*
* @var DirectoryList
* @var DirectoryList $directoryList
*/
private $directoryList;

/**
* @var Structure
*/
/** @var Structure $structure */
private $structure;

/**
* LayoutPlugin constructor.
*
* @param DirectoryList $directoryList
* @param HintConfig $hintConfig
* @param Layout $layout
Expand All @@ -51,8 +46,8 @@ public function __construct(
HintConfig $hintConfig,
Layout $layout
) {
$this->hintConfig = $hintConfig;
$this->directoryList = $directoryList;
$this->hintConfig = $hintConfig;
$this->layout = $layout;

$layoutReflection = new \ReflectionClass($this->layout);
Expand All @@ -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);
}

Expand Down Expand Up @@ -120,8 +116,7 @@ private function _decorateElement($result, $name)
*/
public function decorateOuterElement($html, $attributes)
{

if (!$html) {
if (! $html) {
return $html;
}

Expand All @@ -137,12 +132,13 @@ public function decorateOuterElement($html, $attributes)
$html,
1
);

return $html;
}

/**
* @param string $nameInLayout
* @param [] $container
* @param array $container
*
* @return string
*/
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -237,6 +235,7 @@ private function getBlockClass(\Magento\Framework\View\Element\AbstractBlock $bl
$reflector = new \ReflectionClass($block); //@codingStandardsIgnoreLine
$className = $reflector->getParentClass()->getName();
}

return $className;
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,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 <kbd>⇧</kbd> (shift)
Expand Down
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"php": "~5.5.0|~5.6.0|~7.0.0"
},
"type": "magento2-module",
"version": "0.2.1",
"license": "BSD-2-Clause",
"autoload": {
"files": [
Expand All @@ -24,5 +23,10 @@
"psr-4": {
"Ho\\Templatehints\\": ""
}
},
"extra": {
"branch-alias": {
"dev-master": "0.2-dev"
}
}
}
10 changes: 4 additions & 6 deletions etc/di.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<?xml version="1.0"?>
<!--
/**
* Copyright (c) 2016 H&O E-commerce specialisten B.V. (http://www.h-o.nl/)
* See LICENSE.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
~ Copyright © 2017 H&O E-commerce specialisten B.V. (http://www.h-o.nl/)
~ See LICENSE.txt for license details.
-->

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Framework\View\Layout">
<plugin sortOrder="1" name="hoTemplatehintsLayout" type="Ho\Templatehints\Plugin\View\LayoutPlugin" />
</type>
Expand Down
11 changes: 5 additions & 6 deletions etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?xml version="1.0"?>
<!--
/**
* Copyright (c) 2016 H&O E-commerce specialisten B.V. (http://www.h-o.nl/)
* See LICENSE.txt for license details.
*/
-->
~ Copyright © 2017 H&O E-commerce specialisten B.V. (http://www.h-o.nl/)
~ See LICENSE.txt for license details.
-->

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Ho_Templatehints" setup_version="0.2.1" />
<module name="Ho_Templatehints" setup_version="0.2.2"/>
</config>
9 changes: 4 additions & 5 deletions view/base/layout/default.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?xml version="1.0"?>
<!--
/**
* Copyright (c) 2016 H&O E-commerce specialisten B.V. (http://www.h-o.nl/)
* See LICENSE.txt for license details.
*/
-->
~ Copyright © 2017 H&O E-commerce specialisten B.V. (http://www.h-o.nl/)
~ See LICENSE.txt for license details.
-->

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name='root'>
Expand Down

0 comments on commit f7ddfc2

Please sign in to comment.