Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DebugHints.php
Go to the documentation of this file.
1 <?php
9 
10 use Magento\Developer\Helper\Data as DevHelper;
11 use Magento\Developer\Model\TemplateEngine\Decorator\DebugHintsFactory;
18 
20 {
24  const XML_PATH_DEBUG_TEMPLATE_HINTS_BLOCKS = 'dev/debug/template_hints_blocks';
25 
29  protected $scopeConfig;
30 
34  protected $storeManager;
35 
39  protected $devHelper;
40 
44  protected $debugHintsFactory;
45 
55  protected $debugHintsPath;
56 
64  private $debugHintsWithParam;
65 
73  private $debugHintsParameter;
74 
85  public function __construct(
88  DevHelper $devHelper,
89  DebugHintsFactory $debugHintsFactory,
91  Http $http = null,
92  $debugHintsWithParam = null,
93  $debugHintsParameter = null
94  ) {
95  $this->scopeConfig = $scopeConfig;
96  $this->storeManager = $storeManager;
97  $this->devHelper = $devHelper;
98  $this->debugHintsFactory = $debugHintsFactory;
99  $this->debugHintsPath = $debugHintsPath;
100  $this->http = $http ?: \Magento\Framework\App\ObjectManager::getInstance()->get(
101  \Magento\Framework\App\Request\Http::class
102  );
103  $this->debugHintsWithParam = $debugHintsWithParam;
104  $this->debugHintsParameter = $debugHintsParameter;
105  }
106 
116  public function afterCreate(
117  TemplateEngineFactory $subject,
118  TemplateEngineInterface $invocationResult
119  ) {
120  $storeCode = $this->storeManager->getStore()->getCode();
121  if ($this->scopeConfig->getValue($this->debugHintsPath, ScopeInterface::SCOPE_STORE, $storeCode)
122  && $this->devHelper->isDevAllowed()) {
123  $debugHintsWithParam = $this->scopeConfig->getValue(
124  $this->debugHintsWithParam,
126  $storeCode
127  );
128  $debugHintsParameter = $this->scopeConfig->getValue(
129  $this->debugHintsParameter,
131  $storeCode
132  );
133  $debugHintsParameterInUrl = $this->http->getParam('templatehints');
134 
135  $showHints = false;
136  if (!$debugHintsWithParam) {
137  $showHints = true;
138  }
139  if ($debugHintsWithParam && $debugHintsParameter == $debugHintsParameterInUrl) {
140  $showHints = true;
141  }
142 
143  if ($showHints) {
144  $showBlockHints = $this->scopeConfig->getValue(
145  self::XML_PATH_DEBUG_TEMPLATE_HINTS_BLOCKS,
147  $storeCode
148  );
149  return $this->debugHintsFactory->create([
150  'subject' => $invocationResult,
151  'showBlockHints' => $showBlockHints,
152  ]);
153  }
154  }
155  return $invocationResult;
156  }
157 }
afterCreate(TemplateEngineFactory $subject, TemplateEngineInterface $invocationResult)
Definition: DebugHints.php:116
$storeCode
Definition: indexer.php:15
__construct(ScopeConfigInterface $scopeConfig, StoreManagerInterface $storeManager, DevHelper $devHelper, DebugHintsFactory $debugHintsFactory, $debugHintsPath, Http $http=null, $debugHintsWithParam=null, $debugHintsParameter=null)
Definition: DebugHints.php:85