Provides methods to read various configuration related to Fluid Content Elements.
Author: Claus Due
Inheritance: extends FluidTYPO3\Flux\Service\FluxService, implements TYPO3\CMS\Core\SingletonInterface
Exemplo n.º 1
0
 /**
  * Postprocesses a selected backend layout
  *
  * @param integer $pageUid Starting page UID in the rootline (this current page)
  * @param array $backendLayout The backend layout which was detected from page id
  * @return NULL|void
  */
 public function postProcessBackendLayout(&$pageUid, &$backendLayout)
 {
     try {
         $record = $this->workspacesAwareRecordService->getSingle('pages', '*', $pageUid);
         // Stop processing if no fluidpages template configured in rootline
         if (NULL === $record) {
             return NULL;
         }
         $provider = $this->configurationService->resolvePrimaryConfigurationProvider('pages', 'tx_fed_page_flexform', $record);
         $action = $provider->getControllerActionFromRecord($record);
         if (TRUE === empty($action)) {
             $this->configurationService->message('No template selected - backend layout will not be rendered', GeneralUtility::SYSLOG_SEVERITY_INFO);
             return NULL;
         }
         $grid = $provider->getGrid($record)->build();
         if (FALSE === is_array($grid) || 0 === count($grid['rows'])) {
             // no grid is defined; we use the "raw" BE layout as a default behavior
             $this->configurationService->message('The selected page template does not contain a grid but the template is itself valid.');
             return NULL;
         }
     } catch (\RuntimeException $error) {
         $this->configurationService->debug($error);
         return NULL;
     }
     $config = array('backend_layout.' => array('colCount' => 0, 'rowCount' => 0, 'rows.' => array()));
     $colPosList = array();
     $items = array();
     $rowIndex = 0;
     foreach ($grid['rows'] as $row) {
         $index = 0;
         $colCount = 0;
         $rowKey = $rowIndex + 1 . '.';
         $columns = array();
         foreach ($row['columns'] as $column) {
             $key = $index + 1 . '.';
             $columns[$key] = array('name' => $column['label'], 'colPos' => $column['colPos'] >= 0 ? $column['colPos'] : $config['backend_layout.']['colCount']);
             if ($column['colspan']) {
                 $columns[$key]['colspan'] = $column['colspan'];
             }
             if ($column['rowspan']) {
                 $columns[$key]['rowspan'] = $column['rowspan'];
             }
             array_push($colPosList, $columns[$key]['colPos']);
             array_push($items, array($columns[$key]['name'], $columns[$key]['colPos'], NULL));
             $colCount += $column['colspan'] ? $column['colspan'] : 1;
             ++$index;
         }
         $config['backend_layout.']['colCount'] = max($config['backend_layout.']['colCount'], $colCount);
         $config['backend_layout.']['rowCount']++;
         $config['backend_layout.']['rows.'][$rowKey] = array('columns.' => $columns);
         ++$rowIndex;
     }
     unset($backendLayout['config']);
     $backendLayout['__config'] = $config;
     $backendLayout['__colPosList'] = $colPosList;
     $backendLayout['__items'] = $items;
 }
 /**
  * @dataProvider getConvertFileReferenceToTemplatePathAndFilenameTestValues
  * @param string $reference
  * @param string|NULL $resourceFactoryOutput
  * @param string $expected
  * @return void
  */
 public function testConvertFileReferenceToTemplatePathAndFilename($reference, $resourceFactoryOutput, $expected)
 {
     $instance = new ConfigurationService();
     if (NULL !== $resourceFactoryOutput) {
         $resourceFactory = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceFactory', array('getFileObjectFromCombinedIdentifier'));
         $resourceFactory->expects($this->once())->method('getFileObjectFromCombinedIdentifier')->with($reference)->willReturn($resourceFactoryOutput);
         $instance->injectResourceFactory($resourceFactory);
     }
     $result = $instance->convertFileReferenceToTemplatePathAndFilename($reference);
     $this->assertEquals($expected, $result);
 }
Exemplo n.º 3
0
 /**
  * @return string
  */
 public function rawAction()
 {
     $record = $this->getRecord();
     $templateFileReference = $record['tx_fluidpages_templatefile'];
     $templatePathAndFilename = $this->pageConfigurationService->convertFileReferenceToTemplatePathAndFilename($templateFileReference);
     $paths = $this->pageConfigurationService->getViewConfigurationByFileReference($templateFileReference);
     $this->provider->setTemplatePathAndFilename($templatePathAndFilename);
     $this->view->setTemplatePathAndFilename($templatePathAndFilename);
     $this->view->setTemplateRootPath($paths['templateRootPath']);
     $this->view->setPartialRootPath($paths['partialRootPath']);
     $this->view->setLayoutRootPath($paths['layoutRootPath']);
 }
 /**
  * Renders a Fluid Template Layout select field
  *
  * @param array $parameters
  * @param mixed $pObj
  * @return string
  */
 public function addLayoutOptions(&$parameters, &$pObj)
 {
     $referringField = $parameters['config']['arguments']['referring_field'];
     $currentValue = $parameters['row'][$referringField];
     $configuration = $this->configurationService->getViewConfigurationByFileReference($currentValue);
     $templatePaths = new TemplatePaths($configuration);
     $files = $templatePaths->resolveAvailableLayoutFiles();
     $files = array_map('basename', $files);
     foreach ($files as $file) {
         if (0 !== strpos($file, '.')) {
             $file = pathinfo($file, PATHINFO_FILENAME);
             array_push($parameters['items'], [$file, $file]);
         }
     }
 }
Exemplo n.º 5
0
 /**
  * @param array $row
  * @return array
  */
 protected function getInheritedConfiguration(array $row)
 {
     $tableName = $this->getTableName($row);
     $tableFieldName = $this->getFieldName($row);
     $cacheKey = $tableName . $tableFieldName . $row['uid'];
     if (false === isset(self::$cache[$cacheKey])) {
         $tree = $this->getInheritanceTree($row);
         $data = [];
         foreach ($tree as $branch) {
             /** @var SubPageProvider $provider */
             $provider = $this->pageConfigurationService->resolvePrimaryConfigurationProvider($this->tableName, self::FIELD_NAME_SUB, $branch);
             $form = $provider->getForm($branch);
             if (null === $form) {
                 continue;
             }
             $fields = $form->getFields();
             $values = $provider->getFlexFormValuesSingle($branch);
             foreach ($fields as $field) {
                 $values = $this->unsetInheritedValues($field, $values);
             }
             $data = RecursiveArrayUtility::merge($data, $values);
         }
         self::$cache[$cacheKey] = $data;
     }
     return self::$cache[$cacheKey];
 }
Exemplo n.º 6
0
 /**
  * @param array $row
  * @return array
  */
 protected function getInheritedConfiguration(array $row)
 {
     $tableName = $this->getTableName($row);
     $tableFieldName = $this->getFieldName($row);
     $cacheKey = $tableName . $tableFieldName . $row['uid'];
     if (TRUE === empty(self::$cache[$cacheKey])) {
         $tree = $this->getInheritanceTree($row);
         $data = array();
         foreach ($tree as $branch) {
             $provider = $this->configurationService->resolvePrimaryConfigurationProvider($this->tableName, self::FIELD_NAME_SUB, $branch);
             $form = $provider->getForm($branch);
             if (NULL === $form) {
                 break;
             }
             $fields = $form->getFields();
             $values = $provider->getFlexFormValuesSingle($branch);
             foreach ($fields as $field) {
                 $values = $this->unsetInheritedValues($field, $values);
             }
             $data = RecursiveArrayUtility::merge($data, $values);
         }
         self::$cache[$cacheKey] = $data;
     }
     return self::$cache[$cacheKey];
 }
Exemplo n.º 7
0
 /**
  * @param Form $form
  * @param array $parameters
  * @return string
  */
 protected function renderOption(Form $form, 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 {
         $extension = $form->getExtensionName();
         $thumbnail = MiscellaneousUtility::getIconForTemplate($form);
         $template = pathinfo($form->getOption(Form::OPTION_TEMPLATEFILE), PATHINFO_FILENAME);
         $formLabel = $form->getLabel();
         if (strpos($formLabel, 'LLL:') === 0) {
             $label = LocalizationUtility::translate($formLabel, $extension);
         } else {
             $label = $formLabel;
         }
         $optionValue = $extension . '->' . lcfirst($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 integer $pageUid Starting page UID in the rootline (this current page)
  * @return array
  */
 protected function getBackendLayoutConfiguration($pageUid)
 {
     try {
         $record = $this->recordService->getSingle('pages', '*', $pageUid);
         // Stop processing if no fluidpages template configured in rootline
         if (NULL === $record) {
             return array();
         }
         $provider = $this->configurationService->resolvePrimaryConfigurationProvider('pages', 'tx_fed_page_flexform', $record);
         $action = $provider->getControllerActionFromRecord($record);
         if (TRUE === empty($action)) {
             $this->configurationService->message('No template selected - backend layout will not be rendered', GeneralUtility::SYSLOG_SEVERITY_INFO);
             return array();
         }
         $paths = $provider->getTemplatePaths($record);
         if (0 === count($paths)) {
             $this->configurationService->message('Unable to detect a configuration. If it is not intentional, check that you ' . 'have included the TypoScript for the desired template collection.', GeneralUtility::SYSLOG_SEVERITY_NOTICE);
             return array();
         }
         $grid = $provider->getGrid($record)->build();
         if (FALSE === is_array($grid) || 0 === count($grid['rows'])) {
             // no grid is defined; we use the "raw" BE layout as a default behavior
             $this->configurationService->message('The selected page template does not contain a grid but the template is itself valid.');
             return array();
         }
     } catch (\Exception $error) {
         $this->configurationService->debug($error);
         return array();
     }
     $config = array('colCount' => 0, 'rowCount' => 0, 'rows.' => array());
     $rowIndex = 0;
     foreach ($grid['rows'] as $row) {
         $index = 0;
         $colCount = 0;
         $rowKey = $rowIndex + 1 . '.';
         $columns = array();
         foreach ($row['columns'] as $column) {
             $key = $index + 1 . '.';
             $columnName = $GLOBALS['LANG']->sL($column['label']);
             if (TRUE === empty($columnName)) {
                 $columnName = $column['name'];
             }
             $columns[$key] = array('name' => $columnName, 'colPos' => $column['colPos'] >= 0 ? $column['colPos'] : $config['colCount']);
             if ($column['colspan']) {
                 $columns[$key]['colspan'] = $column['colspan'];
             }
             if ($column['rowspan']) {
                 $columns[$key]['rowspan'] = $column['rowspan'];
             }
             $colCount += $column['colspan'] ? $column['colspan'] : 1;
             ++$index;
         }
         $config['colCount'] = max($config['colCount'], $colCount);
         $config['rowCount']++;
         $config['rows.'][$rowKey] = array('columns.' => $columns);
         ++$rowIndex;
     }
     return $config;
 }
Exemplo n.º 9
0
 /**
  * Post-process the TCEforms DataStructure for a record associated
  * with this ConfigurationProvider
  *
  * @param array $row
  * @param mixed $dataStructure
  * @param array $conf
  * @return NULL
  */
 public function postProcessDataStructure(array &$row, &$dataStructure, array $conf)
 {
     $action = $this->getControllerActionReferenceFromRecord($row);
     if (TRUE === empty($action)) {
         if (FALSE === $this->isUsingSubFieldName()) {
             $this->configurationService->message('No controller action was found for this page.', GeneralUtility::SYSLOG_SEVERITY_WARNING);
         }
         return NULL;
     }
     parent::postProcessDataStructure($row, $dataStructure, $conf);
 }
 /**
  * Renders a Fluid Template Layout select field
  *
  * @param array $parameters
  * @param mixed $pObj
  * @return string
  */
 public function addLayoutOptions(&$parameters, &$pObj)
 {
     $referringField = $parameters['config']['arguments']['referring_field'];
     $currentValue = $parameters['row'][$referringField];
     $configuration = $this->configurationService->getViewConfigurationByFileReference($currentValue);
     $layoutRootPath = $configuration['layoutRootPath'];
     $layoutRootPath = GeneralUtility::getFileAbsFileName($layoutRootPath);
     $files = array();
     $files = TRUE === is_dir($layoutRootPath) ? GeneralUtility::getAllFilesAndFoldersInPath($files, $layoutRootPath) : array();
     foreach ($files as $file) {
         $file = substr($file, strlen($layoutRootPath));
         if (0 !== strpos($file, '.')) {
             $dir = pathinfo($file, PATHINFO_DIRNAME);
             $file = pathinfo($file, PATHINFO_FILENAME);
             if ('.' !== $dir) {
                 $file = $dir . '/' . $file;
             }
             array_push($parameters['items'], array($file, $file));
         }
     }
 }
 /**
  * @param integer $pageUid Starting page UID in the rootline (this current page)
  * @return array
  */
 protected function getBackendLayoutConfiguration($pageUid)
 {
     try {
         $record = $this->recordService->getSingle('pages', '*', $pageUid);
         // Stop processing if no fluidpages template configured in rootline
         if (null === $record) {
             return [];
         }
         $provider = $this->configurationService->resolvePageProvider($record);
         $action = $provider->getControllerActionFromRecord($record);
         if (true === empty($action)) {
             $this->configurationService->message('No template selected - backend layout will not be rendered', GeneralUtility::SYSLOG_SEVERITY_INFO);
             return [];
         }
         $grid = $provider->getGrid($record)->build();
         if (false === is_array($grid) || 0 === count($grid['rows'])) {
             // no grid is defined; we use the "raw" BE layout as a default behavior
             $this->configurationService->message('The selected page template does not contain a grid but the template is itself valid.');
             return [];
         }
     } catch (\Exception $error) {
         $this->configurationService->debug($error);
         return [];
     }
     $config = ['colCount' => 0, 'rowCount' => 0, 'rows.' => []];
     $rowIndex = 0;
     foreach ($grid['rows'] as $row) {
         $index = 0;
         $colCount = 0;
         $rowKey = $rowIndex + 1 . '.';
         $columns = [];
         foreach ($row['columns'] as $column) {
             $key = $index + 1 . '.';
             $columns[$key] = ['name' => $column['label'], 'colPos' => $column['colPos'] >= 0 ? $column['colPos'] : null];
             if ($column['colspan']) {
                 $columns[$key]['colspan'] = $column['colspan'];
             }
             if ($column['rowspan']) {
                 $columns[$key]['rowspan'] = $column['rowspan'];
             }
             $colCount += $column['colspan'] ? $column['colspan'] : 1;
             ++$index;
         }
         $config['colCount'] = max($config['colCount'], $colCount);
         $config['rowCount']++;
         $config['rows.'][$rowKey] = ['columns.' => $columns];
         ++$rowIndex;
     }
     if (false === $this->isPageModuleLanguageView()) {
         $config['rows.'][$rowIndex + 1 . '.'] = ['columns.' => ['1.' => ['name' => LocalizationUtility::translate('fluidContentArea', 'fluidpages'), 'colPos' => ContentService::COLPOS_FLUXCONTENT]]];
     }
     return $config;
 }
Exemplo n.º 12
0
 /**
  * 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;
 }
Exemplo n.º 13
0
 /**
  * @param array $row
  * @throws \RuntimeException
  * @return string
  */
 public function getControllerActionFromRecord(array $row)
 {
     if (PageControllerInterface::DOKTYPE_RAW === intval($row['doktype'])) {
         return 'raw';
     }
     $action = $this->getControllerActionReferenceFromRecord($row);
     if (TRUE === empty($action)) {
         $this->configurationService->message('No page template selected and no template was inherited from parent page(s)');
         return 'default';
     }
     $controllerActionName = array_pop(explode('->', $action));
     $controllerActionName[0] = strtolower($controllerActionName[0]);
     return $controllerActionName;
 }
Exemplo n.º 14
0
 /**
  * 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;
 }
Exemplo n.º 15
0
 /**
  * @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;
 }
Exemplo n.º 16
0
 /**
  * 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;
 }
Exemplo n.º 18
0
 /**
  * Postprocesses a selected backend layout
  *
  * @param integer $pageUid Starting page UID in the rootline (this current page)
  * @param array $backendLayout The backend layout which was detected from page id
  * @return NULL|void
  */
 public function postProcessBackendLayout(&$pageUid, &$backendLayout)
 {
     try {
         $record = $this->pageService->getPage($pageUid);
         // Stop processing if no fluidpages template configured in rootline
         if (NULL === $record) {
             return NULL;
         }
         $provider = $this->configurationService->resolvePrimaryConfigurationProvider('pages', 'tx_fed_page_flexform', $record);
         $action = $provider->getControllerActionFromRecord($record);
         if (TRUE === empty($action)) {
             $this->configurationService->message('No template selected - backend layout will not be rendered', GeneralUtility::SYSLOG_SEVERITY_INFO);
             return NULL;
         }
         $paths = $provider->getTemplatePaths($record);
         if (0 === count($paths)) {
             if (VersionUtility::assertCoreVersionIsAtLeastSixPointZero()) {
                 if (FALSE === (bool) GeneralUtility::_GET('redirected')) {
                     // BUG: TYPO3 6.0 exhibits an odd behavior in some circumstances; reloading the page seems to completely avoid problems
                     $get = GeneralUtility::_GET();
                     unset($get['id']);
                     $get['redirected'] = 1;
                     $params = GeneralUtility::implodeArrayForUrl('', $get);
                     header('Location: ?id=' . $pageUid . $params);
                     exit;
                 }
                 return NULL;
             }
             $this->configurationService->message('Unable to detect a configuration. If it is not intentional, check that you ' . 'have included the TypoScript for the desired template collection.', GeneralUtility::SYSLOG_SEVERITY_NOTICE);
             return NULL;
         }
         $grid = $provider->getGrid($record)->build();
         if (FALSE === is_array($grid) || 0 === count($grid['rows'])) {
             // no grid is defined; we use the "raw" BE layout as a default behavior
             $this->configurationService->message('The selected page template does not contain a grid but the template is itself valid.');
             return NULL;
         }
     } catch (\Exception $error) {
         $this->configurationService->debug($error);
         return NULL;
     }
     $config = array('backend_layout.' => array('colCount' => 0, 'rowCount' => 0, 'rows.' => array()));
     $colPosList = array();
     $items = array();
     $rowIndex = 0;
     foreach ($grid['rows'] as $row) {
         $index = 0;
         $colCount = 0;
         $rowKey = $rowIndex + 1 . '.';
         $columns = array();
         foreach ($row['columns'] as $column) {
             $key = $index + 1 . '.';
             $columnName = $GLOBALS['LANG']->sL($column['label']);
             if (TRUE === empty($columnName)) {
                 $columnName = $column['name'];
             }
             $columns[$key] = array('name' => $columnName, 'colPos' => $column['colPos'] >= 0 ? $column['colPos'] : $config['backend_layout.']['colCount']);
             if ($column['colspan']) {
                 $columns[$key]['colspan'] = $column['colspan'];
             }
             if ($column['rowspan']) {
                 $columns[$key]['rowspan'] = $column['rowspan'];
             }
             array_push($colPosList, $columns[$key]['colPos']);
             array_push($items, array($columns[$key]['name'], $columns[$key]['colPos'], NULL));
             $colCount += $column['colspan'] ? $column['colspan'] : 1;
             ++$index;
         }
         $config['backend_layout.']['colCount'] = max($config['backend_layout.']['colCount'], $colCount);
         $config['backend_layout.']['rowCount']++;
         $config['backend_layout.']['rows.'][$rowKey] = array('columns.' => $columns);
         ++$rowIndex;
     }
     unset($backendLayout['config']);
     $backendLayout['__config'] = $config;
     $backendLayout['__colPosList'] = $colPosList;
     $backendLayout['__items'] = $items;
 }