resolveTemplateFileForControllerAndActionAndFormat() public method

Works _backwards_ through template paths in order to achieve an "overlay"-type behavior where the last paths added are the first to be checked and the first path added acts as fallback if no other paths have the file. If the file does not exist in any path, including fallback path, NULL is returned. Path configurations filled from TypoScript is automatically recorded in the right order (see fillFromTypoScriptArray), but when manually setting the paths that should be checked, you as user must be aware of this reverse behavior (which you should already be, given that it is the same way TypoScript path configurations work).
public resolveTemplateFileForControllerAndActionAndFormat ( string $controller, string $action, string $format = self::DEFAULT_FORMAT ) : string | null
$controller string
$action string
$format string
return string | null
Beispiel #1
0
 public function testResolveTemplateFileForControllerAndActionAndFormatReturnsNullIfNotFound()
 {
     $instance = new TemplatePaths(array('templateRootPaths' => array('EXT:flux/Does/Not/Exist/'), 'layoutRootPaths' => array('EXT:flux/Does/Not/Exist/'), 'partialRootPaths' => array('EXT:flux/Does/Not/Exist/')));
     // note: this is slight abuse of the method: we aim at the Fixtures directory
     // itself and emulate a controller called "Templates" to make TemplatePaths
     // look in the Fixtures/Templates folder.
     $result = $instance->resolveTemplateFileForControllerAndActionAndFormat('Templates', 'AbsolutelyMinimal');
     $this->assertNull($result);
 }
 /**
  * @param array $row
  * @return string
  */
 public function getTemplatePathAndFilename(array $row)
 {
     if (FALSE === empty($this->templatePathAndFilename)) {
         $templateReference = $this->templatePathAndFilename;
         if ('/' !== $templateReference[0]) {
             $templateReference = GeneralUtility::getFileAbsFileName($templateReference);
         }
         if (TRUE === file_exists($templateReference)) {
             return $templateReference;
         }
         return NULL;
     }
     $templateReference = $this->getControllerActionReferenceFromRecord($row);
     list(, $filename) = explode(':', $templateReference);
     list($controllerAction, $format) = explode('.', $filename);
     $controllerAction = $this->getControllerActionFromRecord($row);
     $paths = $this->getTemplatePaths($row);
     $templatePaths = new TemplatePaths($paths);
     return $templatePaths->resolveTemplateFileForControllerAndActionAndFormat('Content', $controllerAction, $format);
 }
 /**
  * @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;
 }
 /**
  * @param array $row
  * @return NULL|string
  */
 public function getTemplatePathAndFilename(array $row)
 {
     $action = $this->getControllerActionFromRecord($row);
     $paths = $this->getTemplatePaths($row);
     $templatePaths = new TemplatePaths($paths);
     return $templatePaths->resolveTemplateFileForControllerAndActionAndFormat('Backend', ucfirst($action));
 }
Beispiel #5
0
 /**
  * @param array $row
  * @return string
  */
 public function getTemplatePathAndFilename(array $row)
 {
     $templatePathAndFilename = $this->templatePathAndFilename;
     $action = $this->getControllerActionReferenceFromRecord($row);
     if (false === empty($action)) {
         $paths = $this->getTemplatePaths($row);
         $templatePaths = new TemplatePaths($paths);
         list(, $action) = explode('->', $action);
         $action = ucfirst($action);
         $templatePathAndFilename = $templatePaths->resolveTemplateFileForControllerAndActionAndFormat('Page', $action);
     }
     return $templatePathAndFilename;
 }
 /**
  * @param string $extensionKey
  * @param string $contentType
  * @param string $variant
  * @param string $version
  * @return string
  */
 public function resolveTemplateFileForVariant($extensionKey, $contentType, $variant = NULL, $version = NULL)
 {
     $paths = $this->getViewConfigurationForExtensionName(FALSE === empty($variant) ? $variant : $extensionKey);
     $templatePaths = new TemplatePaths($paths);
     $controllerName = 'CoreContent';
     $controllerAction = FALSE === empty($version) ? $contentType . '/' . $version : $contentType;
     return $templatePaths->resolveTemplateFileForControllerAndActionAndFormat($controllerName, $controllerAction);
 }