/** * @param $templatePathAndFilename * @return ExposedTemplateView */ protected function getPreparedViewWithTemplateFile($templatePathAndFilename) { $templatePaths = $this->getFixtureTemplatePaths(); $service = $this->createFluxServiceInstance(); $viewContext = new ViewContext($templatePathAndFilename, 'Flux', 'API'); $viewContext->setTemplatePaths(new TemplatePaths($templatePaths)); $view = $service->getPreparedExposedTemplateView($viewContext); return $view; }
/** * @return Form[][] */ public function getContentElementFormInstances() { $elements = array(); $allTemplatePaths = $this->getContentConfiguration(); $controllerName = 'Content'; foreach ($allTemplatePaths as $registeredExtensionKey => $templatePathSet) { $files = array(); $extensionKey = TRUE === isset($templatePathSet['extensionKey']) ? $templatePathSet['extensionKey'] : $registeredExtensionKey; $extensionKey = ExtensionNamingUtility::getExtensionKey($extensionKey); $templatePaths = new TemplatePaths($templatePathSet); $viewContext = new ViewContext(NULL, $extensionKey); $viewContext->setTemplatePaths($templatePaths); $viewContext->setSectionName('Configuration'); foreach ($templatePaths->getTemplateRootPaths() as $templateRootPath) { $files = GeneralUtility::getAllFilesAndFoldersInPath($files, $templateRootPath . '/' . $controllerName . '/', 'html'); if (0 < count($files)) { foreach ($files as $templateFilename) { $actionName = pathinfo($templateFilename, PATHINFO_FILENAME); $fileRelPath = $actionName . '.html'; $viewContext->setTemplatePathAndFilename($templateFilename); $form = $this->getFormFromTemplateFile($viewContext); if (TRUE === empty($form)) { $this->sendDisabledContentWarning($templateFilename); continue; } if (FALSE === $form->getEnabled()) { $this->sendDisabledContentWarning($templateFilename); continue; } $id = preg_replace('/[\\.\\/]/', '_', $registeredExtensionKey . '/' . $actionName . '.html'); $form->setOption('contentElementId', $registeredExtensionKey . ':' . $fileRelPath); $elements[$registeredExtensionKey][$id] = $form; } } } } return $elements; }
/** * @param array $row * @return ViewContext */ public function getViewContext(array $row, RequestInterface $request = NULL) { if (FALSE === $this->viewContext instanceof ViewContext) { // Note: we do *not* store a local property because we do *not* want this function // to re-use the ViewContext unless explicitly set from the outside or initialised // by a sub-class. $context = new ViewContext($this->getTemplatePathAndFilename($row), $this->getControllerPackageNameFromRecord($row), $this->getControllerNameFromRecord($row), $request); $context->setSectionName($this->getConfigurationSectionName($row)); $context->setTemplatePaths(new TemplatePaths($this->getTemplatePaths($row))); $context->setVariables($this->getViewVariables($row)); return $context; } return $this->viewContext; }
/** * @param ProviderInterface $provider * @param array $row * @param Form $form * @return string|NULL */ protected function renderPreviewSection(ProviderInterface $provider, array $row, Form $form = NULL) { $templatePathAndFilename = $provider->getTemplatePathAndFilename($row); if (NULL === $templatePathAndFilename) { return NULL; } $extensionKey = $provider->getExtensionKey($row); $paths = $provider->getTemplatePaths($row); $flexformVariables = $provider->getFlexFormValues($row); $templateVariables = $provider->getTemplateVariables($row); $variables = RecursiveArrayUtility::merge($templateVariables, $flexformVariables); $variables['row'] = $row; $variables['record'] = $row; if (TRUE === is_object($form)) { $formLabel = $form->getLabel(); $label = LocalizationUtility::translate($formLabel, $extensionKey); $variables['label'] = $label; } $templatePaths = new TemplatePaths($paths); $viewContext = new ViewContext($templatePathAndFilename, $extensionKey, self::CONTROLLER_NAME); $viewContext->setTemplatePaths($templatePaths); $viewContext->setVariables($variables); $view = $this->configurationService->getPreparedExposedTemplateView($viewContext); $existingContentObject = $this->configurationManager->getContentObject(); $contentObject = new ContentObjectRenderer(); $contentObject->start($row, $provider->getTableName($row)); $this->configurationManager->setContentObject($contentObject); $previewContent = $view->renderStandaloneSection(self::PREVIEW_SECTION, $variables, TRUE); $this->configurationManager->setContentObject($existingContentObject); $previewContent = trim($previewContent); return $previewContent; }
/** * @test */ public function canRenderTemplateWithCompactingSwitchedOn() { $backup = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['flux']['setup']['compact']; $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['flux']['setup']['compact'] = '1'; $templatePathAndFilename = $this->getAbsoluteFixtureTemplatePathAndFilename(self::FIXTURE_TEMPLATE_COMPACTED); $service = $this->createFluxServiceInstance(); $viewContext = new ViewContext($templatePathAndFilename); $paths = array('templateRootPath' => 'EXT:flux/Tests/Fixtures/Templates/', 'partialRootPath' => 'EXT:flux/Tests/Fixtures/Partials/', 'layoutRootPath' => 'EXT:flux/Tests/Fixtures/Layouts/'); $viewContext->setTemplatePaths(new TemplatePaths($paths)); $viewContext->setSectionName('Configuration'); $form = $service->getFormFromTemplateFile($viewContext); $this->assertInstanceOf('FluidTYPO3\\Flux\\Form', $form); $stored = $form->build(); $this->assertIsArray($stored); $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['flux']['setup']['compact'] = $backup; }
/** * @param string $templatePathAndFilename * @return array */ protected function performBasicTemplateReadTest($templatePathAndFilename) { $service = $this->createFluxServiceInstance(); $paths = array('templateRootPath' => 'EXT:flux/Tests/Fixtures/Templates/', 'partialRootPath' => 'EXT:flux/Tests/Fixtures/Partials/', 'layoutRootPath' => 'EXT:flux/Tests/Fixtures/Layouts/'); $viewContext = new ViewContext($templatePathAndFilename); $viewContext->setTemplatePaths(new TemplatePaths($paths)); $viewContext->setSectionName('Configuration'); $form = $service->getFormFromTemplateFile($viewContext); $this->assertIsValidAndWorkingFormObject($form); return $form; }
/** * @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; }
/** * @test */ public function supportsFormComponentsPlacedInPartialTemplates() { $template = $this->getAbsoluteFixtureTemplatePathAndFilename(self::FIXTURE_TEMPLATE_USESPARTIAL); $service = $this->createFluxServiceInstance(); $paths = array('templateRootPaths' => array('EXT:flux/Tests/Fixtures/Templates/'), 'partialRootPaths' => array('EXT:flux/Tests/Fixtures/Partials/'), 'layoutRootPaths' => array('EXT:flux/Tests/Fixtures/Layouts/')); $viewContext = new ViewContext($template); $viewContext->setTemplatePaths(new TemplatePaths($paths)); $viewContext->setSectionName('Configuration'); $form = $service->getFormFromTemplateFile($viewContext); $this->assertIsValidAndWorkingFormObject($form); }
/** * @param string $extension * @param string $contentType * @param string $version * @return string */ public function getIconFromVersion($extension, $contentType, $version = NULL) { $extensionKey = ExtensionNamingUtility::getExtensionKey($extension); $templatePathAndFilename = $this->resolveTemplateFileForVariant($extensionKey, $contentType, $extension, $version); $paths = $this->getViewConfigurationForExtensionName($extensionKey); $templatePaths = new TemplatePaths($paths); $viewContext = new ViewContext($templatePathAndFilename, $extensionKey); $viewContext->setTemplatePaths($templatePaths); $viewContext->setSectionName('Configuration'); $form = FluxService::getFormFromTemplateFile($viewContext); if (FALSE === $form instanceof Form) { return ''; } else { return MiscellaneousUtility::getIconForTemplate($form); } }
/** * @return void */ public function detectAndRegisterAllFluidBackendModules() { $configurations = $this->getBackendModuleTemplatePaths(); foreach ($configurations as $extensionKey => $paths) { $paths = new TemplatePaths($paths); $context = new ViewContext(NULL, $extensionKey, 'Backend'); $context->setSectionName('Configuration'); $context->setTemplatePaths($paths); $files = $paths->resolveAvailableTemplateFiles('Backend'); foreach ($files as $fileName) { $templatePathAndFilename = $fileName; $context->setTemplatePathAndFilename($templatePathAndFilename); $form = $this->getFormFromTemplateFile($context); $this->registerModuleBasedOnFluxForm($extensionKey, $form); } } }
/** * @param array $row * @return Grid */ public function getGrid(array $row) { if (NULL !== $this->grid) { return $this->grid; } $cacheKey = $this->getCacheKeyForStoredVariable($row, 'grid'); if (FALSE === isset(self::$cache[$cacheKey])) { $class = get_class($this); $controllerName = substr(substr($class, strrpos($class, '\\') + 1), 0, -8); $templatePathAndFilename = $this->getTemplatePathAndFilename($row); $section = $this->getConfigurationSectionName($row); $gridName = 'grid'; $paths = $this->getTemplatePaths($row); $extensionKey = $this->getExtensionKey($row); $extensionName = ExtensionNamingUtility::getExtensionName($extensionKey); $variables = $this->getViewVariables($row); $viewContext = new ViewContext($templatePathAndFilename, $extensionName, $controllerName); $viewContext->setTemplatePaths(new TemplatePaths($paths)); $viewContext->setSectionName($section); $viewContext->setVariables($variables); $grid = $this->configurationService->getGridFromTemplateFile($viewContext, $gridName); self::$cache[$cacheKey] = $grid; } return self::$cache[$cacheKey]; }
/** * 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; }