Пример #1
0
 /**
  * Add all module's standard templates to the parser environment
  *
  * @param ParserInterface $parser the parser
  * @param Module          $module the Module.
  */
 protected function addStandardModuleTemplatesToParserEnvironment($parser, $module)
 {
     $stdTpls = TemplateDefinition::getStandardTemplatesSubdirsIterator();
     foreach ($stdTpls as $templateType => $templateSubdirName) {
         $this->addModuleTemplateToParserEnvironment($parser, $module, $templateType, $templateSubdirName);
     }
 }
Пример #2
0
 public function registerHooks()
 {
     $moduleHooks = $this->getHooks();
     if (is_array($moduleHooks) && !empty($moduleHooks)) {
         $allowedTypes = (array) TemplateDefinition::getStandardTemplatesSubdirsIterator();
         $defaultLang = Lang::getDefaultLanguage();
         $defaultLocale = $defaultLang->getLocale();
         $dispatcher = $this->container->get("event_dispatcher");
         foreach ($moduleHooks as $hook) {
             $isValid = is_array($hook) && isset($hook["type"]) && array_key_exists($hook["type"], $allowedTypes) && isset($hook["code"]) && is_string($hook["code"]) && !empty($hook["code"]);
             if (!$isValid) {
                 Tlog::getInstance()->notice("The module " . $this->getCode() . " tried to register an invalid hook");
                 continue;
             }
             /**
              * Create or update hook db entry.
              */
             list($hookModel, $updateData) = $this->createOrUpdateHook($hook, $dispatcher, $defaultLocale);
             /**
              * Update translations
              */
             $event = new HookUpdateEvent($hookModel->getId());
             foreach ($updateData as $locale => $data) {
                 $event->setCode($hookModel->getCode())->setNative($hookModel->getNative())->setByModule($hookModel->getByModule())->setActive($hookModel->getActivate())->setBlock($hookModel->getBlock())->setNative($hookModel->getNative())->setType($hookModel->getType())->setLocale($locale)->setChapo($data["chapo"])->setTitle($data["title"])->setDescription($data["description"]);
                 $dispatcher->dispatch(TheliaEvents::HOOK_UPDATE, $event);
             }
         }
     }
 }
Пример #3
0
 /**
  * Return a list of existing templates for a given template type
  *
  * @param  int                  $templateType the template type
  * @param string the template base (module or core, default to core).
  * @return TemplateDefinition[] of \Thelia\Core\Template\TemplateDefinition
  */
 public function getList($templateType, $base = THELIA_TEMPLATE_DIR)
 {
     $list = $exclude = array();
     $tplIterator = TemplateDefinition::getStandardTemplatesSubdirsIterator();
     foreach ($tplIterator as $type => $subdir) {
         if ($templateType == $type) {
             $baseDir = rtrim($base, DS) . DS . $subdir;
             try {
                 // Every subdir of the basedir is supposed to be a template.
                 $di = new \DirectoryIterator($baseDir);
                 /** @var \DirectoryIterator $file */
                 foreach ($di as $file) {
                     // Ignore 'dot' elements
                     if ($file->isDot() || !$file->isDir()) {
                         continue;
                     }
                     // Ignore reserved directory names
                     if (in_array($file->getFilename(), $exclude)) {
                         continue;
                     }
                     $list[] = new TemplateDefinition($file->getFilename(), $templateType);
                 }
             } catch (\UnexpectedValueException $ex) {
                 // Ignore the exception and continue
             }
         }
     }
     return $list;
 }