Service for interacting with Pages - gets content elements and page configuration options.
Inheritance: implements TYPO3\CMS\Core\SingletonInterface
Exemplo n.º 1
0
 /**
  * @param array $row
  * @return string
  */
 public function getControllerActionReferenceFromRecord(array $row)
 {
     if (true === empty($row[self::FIELD_ACTION_MAIN])) {
         $row = $this->pageService->getPageTemplateConfiguration($row['uid']);
     }
     return $row[self::FIELD_ACTION_MAIN];
 }
Exemplo n.º 2
0
 /**
  * @param array $row
  * @return string
  */
 public function getControllerActionReferenceFromRecord(array $row)
 {
     $configuration = $this->pageService->getPageTemplateConfiguration($row['uid']);
     if (TRUE === $this->isUsingSubFieldName()) {
         return $configuration[$this->subAction];
     }
     return $configuration[$this->mainAction];
 }
Exemplo n.º 3
0
 /**
  * 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;
 }
Exemplo n.º 4
0
 /**
  * @param array $row
  * @return \FluidTYPO3\Flux\Form|NULL
  */
 public function getForm(array $row)
 {
     if (TRUE === $this->isUsingSubFieldName()) {
         $configuration = $this->pageService->getPageTemplateConfiguration($row['uid']);
         if ($configuration[$this->mainAction] === $configuration[$this->subAction]) {
             $form = Form::create();
             $form->createField('UserFunction', '')->setFunction('FluidTYPO3\\Fluidpages\\UserFunction\\NoSubPageConfiguration->renderField');
             return $form;
         }
     }
     return parent::getForm($row);
 }
Exemplo n.º 5
0
 /**
  * @dataProvider getAvailablePageTemplateFilesTestValues
  * @param string|array $typoScript
  * @param array $expected
  */
 public function testGetAvailablePageTemplateFiles($typoScript, array $expected)
 {
     /** @var ConfigurationService|\PHPUnit_Framework_MockObject_MockObject $service */
     $service = $this->getMock('FluidTYPO3\\Fluidpages\\Service\\ConfigurationService', array('getPageConfiguration', 'message'));
     $service->expects($this->once())->method('getPageConfiguration')->willReturn($typoScript);
     $service->expects($this->any())->method('message');
     $instance = new PageService();
     $instance->injectConfigurationService($service);
     $result = $instance->getAvailablePageTemplateFiles();
     $this->assertEquals($expected, $result);
 }
 /**
  * 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.º 7
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;
 }