/** * Support method for init() -- set up theme once current settings are known. * * @param array $themes Theme configuration information. * * @return void */ protected function setUpThemes($themes) { $templatePathStack = []; // Grab the resource manager for tracking CSS, JS, etc.: $resources = $this->serviceManager->get('VuFindTheme\\ResourceContainer'); // Set generator if necessary: if (isset($this->config->generator)) { $resources->setGenerator($this->config->generator); } $lessActive = false; // Find LESS activity foreach ($themes as $key => $currentThemeInfo) { if (isset($currentThemeInfo['less']['active'])) { $lessActive = $currentThemeInfo['less']['active']; } } // Apply the loaded theme settings in reverse for proper inheritance: foreach ($themes as $key => $currentThemeInfo) { if (isset($currentThemeInfo['helpers'])) { $this->setUpThemeViewHelpers($currentThemeInfo['helpers']); } // Add template path: $templatePathStack[] = $this->tools->getBaseDir() . "/{$key}/templates"; // Add CSS and JS dependencies: if ($lessActive && isset($currentThemeInfo['less'])) { $resources->addLessCss($currentThemeInfo['less']); } if (isset($currentThemeInfo['css'])) { $resources->addCss($currentThemeInfo['css']); } if (isset($currentThemeInfo['js'])) { $resources->addJs($currentThemeInfo['js']); } // Select encoding: if (isset($currentThemeInfo['encoding'])) { $resources->setEncoding($currentThemeInfo['encoding']); } // Select favicon: if (isset($currentThemeInfo['favicon'])) { $resources->setFavicon($currentThemeInfo['favicon']); } } // Inject the path stack generated above into the view resolver: $resolver = $this->serviceManager->get('viewmanager')->getResolver(); if (!is_a($resolver, 'Zend\\View\\Resolver\\AggregateResolver')) { throw new \Exception('Unexpected resolver: ' . get_class($resolver)); } foreach ($resolver as $current) { if (is_a($current, 'Zend\\View\\Resolver\\TemplatePathStack')) { $current->setPaths($templatePathStack); } } // Add theme specific language files for translation $this->updateTranslator($themes); }