/** * @return void */ public function testFillByTypoScript() { $instance = new TemplatePaths(array('templateRootPaths' => array('EXT:flux/Resources/Private/Templates/'), 'layoutRootPaths' => array('EXT:flux/Resources/Private/Layouts/'), 'partialRootPaths' => array('EXT:flux/Resources/Private/Partials/'))); $this->assertEquals(array(ExtensionManagementUtility::extPath('flux', 'Resources/Private/Templates/')), $instance->getTemplateRootPaths()); $this->assertEquals(array(ExtensionManagementUtility::extPath('flux', 'Resources/Private/Layouts/')), $instance->getLayoutRootPaths()); $this->assertEquals(array(ExtensionManagementUtility::extPath('flux', 'Resources/Private/Partials/')), $instance->getPartialRootPaths()); }
/** * Gets a list of usable Page Templates from defined page template TypoScript * * @param string $format * @return array * @api */ public function getAvailablePageTemplateFiles($format = 'html') { $typoScript = $this->configurationService->getPageConfiguration(); $output = array(); if (FALSE === is_array($typoScript)) { return $output; } foreach ($typoScript as $extensionName => $group) { if (TRUE === isset($group['enable']) && 1 > $group['enable']) { continue; } $output[$extensionName] = array(); $templatePaths = new TemplatePaths($group); $templateRootPaths = $templatePaths->getTemplateRootPaths(); foreach ($templateRootPaths as $templateRootPath) { $configuredPath = $templateRootPath . 'Page/'; if (FALSE === is_dir($configuredPath)) { $this->configurationService->message('The template group "' . $extensionName . '" has been configured to use the templateRootPath "' . $configuredPath . '" but this directory does not exist.', GeneralUtility::SYSLOG_SEVERITY_FATAL); continue; } $files = scandir($configuredPath); foreach ($files as $key => $file) { $pathinfo = pathinfo($file); $extension = $pathinfo['extension']; $filename = $pathinfo['filename']; if ('.' === substr($file, 0, 1)) { unset($files[$key]); } else { if (strtolower($extension) !== strtolower($format)) { unset($files[$key]); } else { $output[$extensionName][$filename] = $filename; } } } } } return $output; }
/** * @param TemplatePaths $templatePaths * @return void */ public function setTemplatePaths(TemplatePaths $templatePaths) { $this->setTemplateRootPaths($templatePaths->getTemplateRootPaths()); $this->setLayoutRootPaths($templatePaths->getLayoutRootPaths()); $this->setPartialRootPaths($templatePaths->getPartialRootPaths()); }
/** * Gets a list of usable Page Templates from defined page template TypoScript. * Returns a list of Form instances indexed by the path ot the template file. * * @param string $format * @return Form[] * @api */ public function getAvailablePageTemplateFiles($format = 'html') { $typoScript = $this->configurationService->getPageConfiguration(); $output = []; foreach ((array) $typoScript as $extensionName => $group) { if (true === isset($group['enable']) && 1 > $group['enable']) { continue; } $output[$extensionName] = []; $templatePaths = new TemplatePaths($group); $templateRootPaths = $templatePaths->getTemplateRootPaths(); foreach ($templateRootPaths as $templateRootPath) { $configuredPath = $templateRootPath . 'Page/'; if (false === is_dir($configuredPath)) { $this->configurationService->message(sprintf('The template group "%s" has been configured to use the templateRootPath "' . '%s" but this directory does not exist.', $extensionName, $configuredPath), GeneralUtility::SYSLOG_SEVERITY_FATAL); continue; } $files = scandir($configuredPath); foreach ($files as $key => $file) { $pathinfo = pathinfo($file); $extension = $pathinfo['extension']; if ('.' === substr($file, 0, 1)) { continue; } elseif (strtolower($extension) !== strtolower($format)) { continue; } $filename = $pathinfo['filename']; if (isset($output[$extensionName][$filename])) { continue; } $viewContext = new ViewContext($configuredPath . $file, $extensionName, 'Page'); $viewContext->setSectionName('Configuration'); $viewContext->setTemplatePaths($templatePaths); $form = $this->configurationService->getFormFromTemplateFile($viewContext); $templatePathAndFilename = $form->getOption(Form::OPTION_TEMPLATEFILE); if (false === $form instanceof Form) { $this->configurationService->message('Template file ' . $viewContext . ' contains an unparsable Form definition', GeneralUtility::SYSLOG_SEVERITY_FATAL); continue; } if (false === $form->getEnabled()) { $this->configurationService->message('Template file ' . $templatePathAndFilename . ' is disabled by configuration', GeneralUtility::SYSLOG_SEVERITY_NOTICE); continue; } $form->setOption(Form::OPTION_TEMPLATEFILE, $configuredPath . $file); $output[$extensionName][$filename] = $form; } } } return $output; }