/** * helper function allowing you to generate the HTML script tag * * @param string $fileName the path to the js file * @param array $attributes the attributes of the tag * @param array $filters an array of assets processing filters (cofeescript, compress, etc.) * * @return string the script tag */ public function addJS($fileName, $attributes = array(), $filters = []) { $tag = ""; $url = $this->assetsResolver->resolveAssetURL($this->module->getCode(), $fileName, "js", $this->parser, $filters); if ("" !== $url) { $tags = array(); $tags[] = '<script type="text/javascript" '; $tags[] = ' src="' . $url . '" '; foreach ($attributes as $name => $val) { if (is_string($name) && !in_array($name, ["src", "type"])) { $tags[] = $name . '="' . $val . '" '; } } $tags[] = "></script>"; $tag = implode($tags); } return $tag; }
/** * Resolve the file path. * * A system of fallback enables file overriding. It will look for the template : * - in the current template in directory /modules/{module code}/ * - in the module in the current template if it exists * - in the module in the default template * * @param $fileName the filename * * @return mixed the path to directory containing the file if exists */ protected function resolveSourcePath($fileName) { $fileDir = null; $found = false; // retrieve the template $smartyParser = $this->parser; // First look into the current template in the right scope : frontOffice, backOffice, ... // template should be overrided in : {template_path}/modules/{module_code}/{template_name} /** @var \Thelia\Core\Template\Smarty\SmartyParser $templateDefinition */ $templateDefinition = $smartyParser->getTemplateDefinition(false); $templateDirectories = $smartyParser->getTemplateDirectories($templateDefinition->getType()); if (isset($templateDirectories[$templateDefinition->getName()]["0"])) { $fileDir = $templateDirectories[$templateDefinition->getName()]["0"] . DS . TemplateDefinition::HOOK_OVERRIDE_SUBDIR . DS . $this->module->getCode(); if (file_exists($fileDir . DS . $fileName)) { $found = true; } } // If the smarty template doesn't exist, we try to see if there is an // implementation for the template used in the module directory if (!$found) { if (isset($templateDirectories[$templateDefinition->getName()][$this->module->getCode()])) { $fileDir = $templateDirectories[$templateDefinition->getName()][$this->module->getCode()]; if (file_exists($fileDir . DS . $fileName)) { $found = true; } } } // Not here, we finally try to fallback on the default theme in the module if (!$found && $templateDefinition->getName() !== TemplateDefinition::HOOK_DEFAULT_THEME) { if ($templateDirectories[TemplateDefinition::HOOK_DEFAULT_THEME] && isset($templateDirectories[TemplateDefinition::HOOK_DEFAULT_THEME][$this->module->getCode()])) { $fileDir = $templateDirectories[TemplateDefinition::HOOK_DEFAULT_THEME][$this->module->getCode()]; if (file_exists($fileDir . DS . $fileName)) { $found = true; } } } return $fileDir; }