Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InjectTemplateListener.php
Go to the documentation of this file.
1 <?php
8 
9 use Zend\Mvc\MvcEvent;
10 use Zend\Mvc\View\Http\InjectTemplateListener as ZendInjectTemplateListener;
11 
12 class InjectTemplateListener extends ZendInjectTemplateListener
13 {
20  protected function deriveModuleNamespace($controller)
21  {
22  if (!strstr($controller, '\\')) {
23  return '';
24  }
25 
26  // Retrieve the first two elemenents representing the vendor and module name.
27  $nsArray = explode('\\', $controller);
28  $subNsArray = array_slice($nsArray, 0, 2);
29  return implode('/', $subNsArray);
30  }
31 
36  protected function deriveControllerSubNamespace($namespace)
37  {
38  if (!strstr($namespace, '\\')) {
39  return '';
40  }
41  $nsArray = explode('\\', $namespace);
42 
43  // Remove the first three elements representing the vendor, module name and controller directory.
44  $subNsArray = array_slice($nsArray, 3);
45  if (empty($subNsArray)) {
46  return '';
47  }
48  return implode('/', $subNsArray);
49  }
50 
60  public function injectTemplate(MvcEvent $e)
61  {
62  $e->getRouteMatch()->setParam('action', null);
63  parent::injectTemplate($e);
64  }
65 }
$controller
Definition: info.phtml:14