Get definitions of paths for Page Templates defined in TypoScript
public getPageConfiguration ( string $extensionName = null ) : array | ||
$extensionName | string | |
return | array |
/** * @param array $row * @return array */ public function getTemplatePaths(array $row) { $extensionName = $this->getExtensionKey($row); $paths = $this->configurationService->getPageConfiguration($extensionName); if (TRUE === is_array($paths) && FALSE === empty($paths)) { $paths = PathUtility::translatePath($paths); return $paths; } return parent::getTemplatePaths($row); }
/** * 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; }
/** * 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; } if (FALSE === isset($group['templateRootPath'])) { $this->configurationService->message('The template group "' . $extensionName . '" does not define a set of template containing at least a templateRootPath' . 'paths. This indicates a problem with your TypoScript configuration - most likely a static template is not loaded', GeneralUtility::SYSLOG_SEVERITY_WARNING); continue; } $configuredPath = rtrim($group['templateRootPath'], '/') . '/Page/'; $path = GeneralUtility::getFileAbsFileName($configuredPath); if (FALSE === is_dir($path)) { $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($path); $output[$extensionName] = array(); foreach ($files as $key => $file) { $pathinfo = pathinfo($path . $file); $extension = $pathinfo['extension']; if ('.' === substr($file, 0, 1)) { unset($files[$key]); } else { if (strtolower($extension) != strtolower($format)) { unset($files[$key]); } else { try { $this->getPageTemplateLabel($extensionName, $path . $file); $output[$extensionName][] = $pathinfo['filename']; } catch (\Exception $error) { $this->configurationService->debug($error); continue; } } } } } return $output; }
/** * @param string $extension * @param string $template * @param array $parameters * @return string */ protected function renderOption($extension, $template, array $parameters) { $name = $parameters['itemFormElName']; $value = $parameters['itemFormElValue']; $onChange = 'onclick="if (confirm(TBE_EDITOR.labels.onChangeAlert) && TBE_EDITOR.checkSubmit(-1)){ TBE_EDITOR.submitForm() };"'; $selector = ''; try { $extensionName = ExtensionNamingUtility::getExtensionKey($extension); $paths = $this->configurationService->getPageConfiguration($extensionName); $templatePaths = new TemplatePaths($paths); $templatePathAndFilename = $templatePaths->resolveTemplateFileForControllerAndActionAndFormat('Page', $template); if (FALSE === file_exists($templatePathAndFilename)) { $this->configurationService->message('Missing template file: ' . $templatePathAndFilename, GeneralUtility::SYSLOG_SEVERITY_WARNING); return ''; } $viewContext = new ViewContext($templatePathAndFilename, $extensionName); $viewContext->setTemplatePaths($templatePaths); $viewContext->setSectionName('Configuration'); $form = $this->configurationService->getFormFromTemplateFile($viewContext); if (FALSE === $form instanceof Form) { $this->configurationService->message('Template file ' . $templatePathAndFilename . ' contains an unparsable Form definition', GeneralUtility::SYSLOG_SEVERITY_FATAL); return ''; } if (FALSE === $form->getEnabled()) { $this->configurationService->message('Template file ' . $templatePathAndFilename . ' is disabled by configuration', GeneralUtility::SYSLOG_SEVERITY_NOTICE); return ''; } $thumbnail = MiscellaneousUtility::getIconForTemplate($form); $label = $form->getLabel(); $optionValue = $extension . '->' . $template; $selected = $optionValue == $value ? ' checked="checked"' : ''; $option = '<label style="padding: 0.5em; border: 1px solid #CCC; display: inline-block; vertical-align: bottom; margin: 0 1em 1em 0; cursor: pointer; ' . ($selected ? 'background-color: #DDD;' : '') . '">'; $option .= '<img src="' . $thumbnail . '" alt="' . $label . '" style="margin: 0.5em 0 0.5em 0; max-width: 196px; max-height: 128px;"/><br />'; $option .= '<input type="radio" value="' . $optionValue . '"' . $selected . ' name="' . $name . '" ' . $onChange . ' /> ' . $label; $option .= '</label>'; $selector .= $option . LF; } catch (\RuntimeException $error) { $this->configurationService->debug($error); } return $selector; }
/** * 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; }
/** * Renders a Fluid Page Layout file selector * * @param array $parameters * @param mixed $pObj * @return string */ public function renderField(&$parameters, &$pObj) { $name = $parameters['itemFormElName']; $value = $parameters['itemFormElValue']; $availableTemplates = $this->pageService->getAvailablePageTemplateFiles(); if (FALSE === strpos($name, 'tx_fed_controller_action_sub')) { $onChange = 'onclick="if (confirm(TBE_EDITOR.labels.onChangeAlert) && TBE_EDITOR.checkSubmit(-1)){ TBE_EDITOR.submitForm() };"'; } $selector = '<div>'; $typoScript = $this->configurationManager->getTypoScriptSetup(); $hideInheritFieldSiteRoot = (bool) (TRUE === isset($typoScript['plugin.']['tx_fluidpages.']['siteRootInheritance']) ? 1 > $typoScript['plugin.']['tx_fluidpages.']['siteRootInheritance'] : FALSE); $pageIsSiteRoot = (bool) $parameters['row']['is_siteroot']; $forceDisplayInheritSiteRoot = (bool) ('tx_fed_page_controller_action_sub' === $parameters['field']); $forceHideInherit = (bool) (0 === intval($parameters['row']['pid'])); if (FALSE === $pageIsSiteRoot || TRUE === $forceDisplayInheritSiteRoot || FALSE === $hideInheritFieldSiteRoot) { if (FALSE === $forceHideInherit) { $emptyLabel = LocalizationUtility::translate('pages.tx_fed_page_controller_action.default', 'Fluidpages'); $selected = TRUE === empty($value) ? ' checked="checked" ' : NULL; $selector .= '<label>'; $selector .= '<input type="radio" name="' . $name . '" ' . $onChange . '" value="" ' . $selected . '/> ' . $emptyLabel . LF; $selector .= '</label>' . LF; } } foreach ($availableTemplates as $extension => $group) { $extensionKey = ExtensionNamingUtility::getExtensionKey($extension); if (FALSE === ExtensionManagementUtility::isLoaded($extensionKey)) { $groupTitle = ucfirst($extension); } else { $emConfigFile = ExtensionManagementUtility::extPath($extensionKey, 'ext_emconf.php'); require $emConfigFile; $groupTitle = $EM_CONF['']['title']; } $packageLabel = LocalizationUtility::translate('pages.tx_fed_page_package', 'Fluidpages'); $selector .= '<h4 style="clear: both; margin-top: 1em;">' . $packageLabel . ': ' . $groupTitle . '</h4>' . LF; foreach ($group as $template) { try { $paths = $this->configurationService->getPageConfiguration($extension); $extensionName = ExtensionNamingUtility::getExtensionName($extension); $templatePathAndFilename = $this->pageService->expandPathsAndTemplateFileToTemplatePathAndFilename($paths, $template); if (FALSE === file_exists($templatePathAndFilename)) { $this->configurationService->message('Missing template file: ' . $templatePathAndFilename, GeneralUtility::SYSLOG_SEVERITY_WARNING); continue; } $form = $this->configurationService->getFormFromTemplateFile($templatePathAndFilename, 'Configuration', 'form', $paths, $extensionName); if (FALSE === $form instanceof Form) { $this->configurationService->message('Template file ' . $templatePathAndFilename . ' contains an unparsable Form definition', GeneralUtility::SYSLOG_SEVERITY_FATAL); continue; } if (FALSE === $form->getEnabled()) { continue; } $thumbnail = $form->getIcon(); $label = $form->getLabel(); $translatedLabel = LocalizationUtility::translate($label, $extensionName); if (NULL !== $translatedLabel) { $label = $translatedLabel; } $optionValue = $extension . '->' . $template; $selected = $optionValue == $value ? ' checked="checked"' : ''; $option = '<label style="padding: 0.5em; border: 1px solid #CCC; display: inline-block; vertical-align: bottom; margin: 0 1em 1em 0; cursor: pointer; ' . ($selected ? 'background-color: #DDD;' : '') . '">'; $option .= '<img src="' . $thumbnail . '" alt="' . $label . '" style="margin: 0.5em 0 0.5em 0; max-width: 196px; max-height: 128px;"/><br />'; $option .= '<input type="radio" value="' . $optionValue . '"' . $selected . ' name="' . $name . '" ' . $onChange . ' /> ' . $label; $option .= '</label>'; $selector .= $option . LF; } catch (\Exception $error) { $this->configurationService->debug($error); } } } $selector .= '</div>' . LF; unset($pObj); return $selector; }