FluidTYPO3\Fluidpages\Service\PageService::getAvailablePageTemplateFiles PHP Method

getAvailablePageTemplateFiles() public method

Returns a list of Form instances indexed by the path ot the template file.
public getAvailablePageTemplateFiles ( string $format = 'html' ) : Form[]
$format string
return FluidTYPO3\Flux\Form[]
    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;
    }

Usage Example

 /**
  * Renders a Fluid Page Layout file selector
  *
  * @param array $parameters
  * @param mixed $pObj
  * @return string
  */
 public function renderField(&$parameters, &$pObj)
 {
     $availableTemplates = $this->pageService->getAvailablePageTemplateFiles();
     $selector = '<div>';
     $selector .= $this->renderInheritanceField($parameters);
     foreach ($availableTemplates as $extension => $group) {
         $selector .= $this->renderOptions($extension, $group, $parameters);
     }
     $selector .= '</div>';
     return $selector;
 }
All Usage Examples Of FluidTYPO3\Fluidpages\Service\PageService::getAvailablePageTemplateFiles