Example #1
0
 /**
  * Get a view helper from the manager.
  *
  * @param string $name
  * @return TranslatorInterface
  */
 protected function getViewHelper($name)
 {
     if (!$this->viewHelperManager instanceof HelperPluginManager) {
         $this->viewHelperManager = $this->getServiceLocator()->get('ViewHelperManager');
     }
     return $this->viewHelperManager->get($name);
 }
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get(ConfigHelper::class);
     $viewManager = $serviceLocator->get('ViewHelperManager');
     $managerConfigs = $config->get('twig.helper_manager.configs');
     $twigManager = new HelperPluginManager(new Config($config->get('twig.view_helpers')));
     $twigManager->setServiceLocator($serviceLocator);
     $twigManager->addPeeringServiceManager($viewManager);
     foreach ($managerConfigs as $configClass) {
         if (is_string($configClass) && class_exists($configClass)) {
             $config = new $configClass();
             if (!$config instanceof ConfigInterface) {
                 throw new RuntimeException(sprintf('Invalid service manager configuration class provided; received "%s",
                     expected class implementing %s', $configClass, 'Zend\\ServiceManager\\ConfigInterface'));
             }
             $config->configureServiceManager($twigManager);
         }
     }
     return $twigManager;
 }
 /**
  * @param HelperPluginManager $helperPluginManager
  * @return TwigRenderer
  */
 public function setHelperPluginManager(HelperPluginManager $helperPluginManager)
 {
     $helperPluginManager->setRenderer($this);
     $this->helperPluginManager = $helperPluginManager;
     return $this;
 }