Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

Commit 051e279

Browse files
committed
[BUGFIX] Support mixing of fluidpages with other backend layouts
When mixing both fluidpages and templavoila page layouts, the page's backend_layout setting needs to be checked to make sure that fluidpages is responsible for handling the rendering. Resolves: #366
1 parent a09324c commit 051e279

File tree

7 files changed

+461
-103
lines changed

7 files changed

+461
-103
lines changed

Classes/Provider/PageProvider.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use FluidTYPO3\Fluidpages\Controller\PageControllerInterface;
1212
use FluidTYPO3\Fluidpages\Service\ConfigurationService;
1313
use FluidTYPO3\Fluidpages\Service\PageService;
14+
use FluidTYPO3\Fluidpages\UserFunction\LayoutSelect;
1415
use FluidTYPO3\Flux\Form;
1516
use FluidTYPO3\Flux\Provider\AbstractProvider;
1617
use FluidTYPO3\Flux\Provider\ProviderInterface;
@@ -106,6 +107,15 @@ public function injectPageService(PageService $pageService)
106107
$this->pageService = $pageService;
107108
}
108109

110+
/**
111+
* @param LayoutSelect $layoutSelect
112+
* @return void
113+
*/
114+
public function injectLayoutSelect(LayoutSelect $layoutSelect)
115+
{
116+
$this->layoutSelect = $layoutSelect;
117+
}
118+
109119
/**
110120
* @param ConfigurationService $pageConfigurationService
111121
* @return void
@@ -199,8 +209,9 @@ public function getControllerActionFromRecord(array $row)
199209
*/
200210
public function getControllerActionReferenceFromRecord(array $row)
201211
{
202-
if (true === empty($row[self::FIELD_ACTION_MAIN])) {
203-
$row = $this->pageService->getPageTemplateConfiguration($row['uid']);
212+
$useFluidpages = $this->layoutSelect->isFluidpagesBackendLayout($row['backend_layout']);
213+
if (true === empty($row[self::FIELD_ACTION_MAIN]) || false === $useFluidpages) {
214+
$row = $this->layoutSelect->getPageTemplateConfiguration($row['uid']);
204215
}
205216
return $row[self::FIELD_ACTION_MAIN];
206217
}

Classes/Service/PageService.php

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -96,63 +96,12 @@ public function injectWorkspacesAwareRecordService(WorkspacesAwareRecordService
9696
* @param integer $pageUid
9797
* @return array|NULL
9898
* @api
99+
* @deprecated
99100
*/
100101
public function getPageTemplateConfiguration($pageUid)
101102
{
102-
$pageUid = (integer) $pageUid;
103-
if (1 > $pageUid) {
104-
return null;
105-
}
106-
$cacheId = 'fluidpages-template-configuration-' . $pageUid;
107-
$runtimeCache = $this->getRuntimeCache();
108-
$fromCache = $runtimeCache->get($cacheId);
109-
if ($fromCache) {
110-
return $fromCache;
111-
}
112-
$fieldList = 'tx_fed_page_controller_action_sub,t3ver_oid,pid,uid';
113-
$page = $this->workspacesAwareRecordService->getSingle(
114-
'pages',
115-
'tx_fed_page_controller_action,' . $fieldList,
116-
$pageUid
117-
);
118-
119-
// Initialize with possibly-empty values and loop root line
120-
// to fill values as they are detected.
121-
$resolvedMainTemplateIdentity = $page['tx_fed_page_controller_action'];
122-
$resolvedSubTemplateIdentity = $page['tx_fed_page_controller_action_sub'];
123-
do {
124-
$containsSubDefinition = (false !== strpos($page['tx_fed_page_controller_action_sub'], '->'));
125-
$isCandidate = ((integer) $page['uid'] !== $pageUid);
126-
if (true === $containsSubDefinition && true === $isCandidate) {
127-
$resolvedSubTemplateIdentity = $page['tx_fed_page_controller_action_sub'];
128-
if (true === empty($resolvedMainTemplateIdentity)) {
129-
// Conditions met: current page is not $pageUid, original page did not
130-
// contain a "this page" layout, current rootline page has "sub" selection.
131-
// Then, set our "this page" value to use the "sub" selection that was detected.
132-
$resolvedMainTemplateIdentity = $resolvedSubTemplateIdentity;
133-
}
134-
break;
135-
}
136-
// Note: 't3ver_oid' is analysed in order to make versioned records inherit the original record's
137-
// configuration as an emulated first parent page.
138-
$resolveParentPageUid = (integer) (0 > $page['pid'] ? $page['t3ver_oid'] : $page['pid']);
139-
$page = $this->workspacesAwareRecordService->getSingle(
140-
'pages',
141-
$fieldList,
142-
$resolveParentPageUid
143-
);
144-
} while (null !== $page);
145-
if (true === empty($resolvedMainTemplateIdentity) && true === empty($resolvedSubTemplateIdentity)) {
146-
// Neither directly configured "this page" nor inherited "sub" contains a valid value;
147-
// no configuration was detected at all.
148-
return null;
149-
}
150-
$configurarion = [
151-
'tx_fed_page_controller_action' => $resolvedMainTemplateIdentity,
152-
'tx_fed_page_controller_action_sub' => $resolvedSubTemplateIdentity
153-
];
154-
$runtimeCache->set($cacheId, $configurarion);
155-
return $configurarion;
103+
$ls = GeneralUtility::makeInstance(\FluidTYPO3\Fluidpages\UserFunction\LayoutSelect::class);
104+
return $ls->getPageTemplateConfiguration($pageUid);
156105
}
157106

158107
/**
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
<?php
2+
namespace FluidTYPO3\Fluidpages\UserFunction;
3+
4+
use FluidTYPO3\Flux\Service\WorkspacesAwareRecordService;;
5+
use TYPO3\CMS\Core\Cache\CacheManager;
6+
use TYPO3\CMS\Core\Utility\GeneralUtility;
7+
use TYPO3\CMS\Backend\Form\FormDataProvider\EvaluateDisplayConditions;
8+
use TYPO3\CMS\Extbase\Object\ObjectManager;
9+
10+
/**
11+
* Decide if fluidpages shall be used to render a page
12+
*/
13+
class LayoutSelect
14+
{
15+
/**
16+
* @var WorkspacesAwareRecordService
17+
*/
18+
protected $workspacesAwareRecordService;
19+
20+
/**
21+
* Decide if the "Page layouts" fields and "Page configuration" flexform
22+
* shall be shown in the page settings.
23+
*
24+
* The first conditionParameters parameter determines if the subpages
25+
* settings are meant or not.
26+
*
27+
* @param array $param Parameters with key:
28+
* - record (page db row)
29+
* - flexformValueKey
30+
* - conditionParameters (displayCond config)
31+
* @param object $caller Object calling the method
32+
*
33+
* @return boolean True if it shall be shown
34+
*/
35+
public function doShowPageConfiguration($param, EvaluateDisplayConditions $caller)
36+
{
37+
$sub = (boolean) $param['conditionParameters'][0];
38+
39+
$conf = $this->getPageTemplateConfiguration($param['record']['uid']);
40+
if (null === $conf) {
41+
return false;
42+
}
43+
44+
if ($sub) {
45+
return false === empty($conf['tx_fed_page_controller_action_sub']);
46+
} else {
47+
return false === empty($conf['tx_fed_page_controller_action']);
48+
}
49+
}
50+
51+
/**
52+
* Process RootLine to find first usable, configured Fluid Page Template.
53+
* WARNING: do NOT use the output of this feature to overwrite $row - the
54+
* record returned may or may not be the same record as defined in $id.
55+
*
56+
* @param integer $pageUid
57+
* @return array|NULL Array with two keys:
58+
* - tx_fed_page_controller_action
59+
* - tx_fed_page_controller_action_sub
60+
* @api
61+
*/
62+
public function getPageTemplateConfiguration($pageUid)
63+
{
64+
$pageUid = (integer) $pageUid;
65+
if (1 > $pageUid) {
66+
return null;
67+
}
68+
$cacheId = 'fluidpages-template-configuration-' . $pageUid;
69+
$runtimeCache = $this->getRuntimeCache();
70+
$fromCache = $runtimeCache->get($cacheId);
71+
if ($fromCache) {
72+
return $fromCache;
73+
}
74+
$fieldList = 'tx_fed_page_controller_action_sub,backend_layout,backend_layout_next_level,t3ver_oid,pid,uid';
75+
$page = $this->getWorkspacesAwareRecordService()->getSingle(
76+
'pages',
77+
'tx_fed_page_controller_action,' . $fieldList,
78+
$pageUid
79+
);
80+
81+
$checkUsage = true;
82+
$useMainTemplate = $this->isFluidpagesBackendLayout($page['backend_layout']);
83+
$useSubTemplate = $this->isFluidpagesBackendLayout($page['backend_layout_next_level']);
84+
$mainTemplate = $page['tx_fed_page_controller_action'];
85+
$subTemplate = $page['tx_fed_page_controller_action_sub'];
86+
$isFirstPage = true;
87+
88+
do {
89+
if (false === $isFirstPage) {
90+
if ($checkUsage) {
91+
if ($this->isFluidpagesBackendLayout($page['backend_layout_next_level'])) {
92+
$useMainTemplate = true;
93+
$useSubTemplate = true;
94+
} else if (false === empty($page['backend_layout_next_level'])) {
95+
//we have a different layout in between, so do not look further up
96+
$checkUsage = false;
97+
}
98+
}
99+
$containsSubDefinition = (false !== strpos($page['tx_fed_page_controller_action_sub'], '->'));
100+
if ($containsSubDefinition) {
101+
if (empty($mainTemplate)) {
102+
$mainTemplate = $page['tx_fed_page_controller_action_sub'];
103+
}
104+
if (empty($subTemplate)) {
105+
$subTemplate = $page['tx_fed_page_controller_action_sub'];
106+
}
107+
}
108+
}
109+
// Note: 't3ver_oid' is analysed in order to make versioned records inherit the original record's
110+
// configuration as an emulated first parent page.
111+
$resolveParentPageUid = (integer) (0 > $page['pid'] ? $page['t3ver_oid'] : $page['pid']);
112+
$page = $this->getWorkspacesAwareRecordService()->getSingle(
113+
'pages',
114+
$fieldList,
115+
$resolveParentPageUid
116+
);
117+
$isFirstPage = false;
118+
} while (null !== $page);
119+
120+
if (empty($mainTemplate)) {
121+
$useMainTemplate = false;
122+
}
123+
if (empty($subTemplate)) {
124+
$useSubTemplate = false;
125+
}
126+
if (false === $useMainTemplate && false === $useSubTemplate) {
127+
//BC return value
128+
return null;
129+
}
130+
$configuration = [
131+
'tx_fed_page_controller_action' => $useMainTemplate ? $mainTemplate : null,
132+
'tx_fed_page_controller_action_sub' => $useSubTemplate ? $subTemplate : null
133+
];
134+
$runtimeCache->set($cacheId, $configuration);
135+
return $configuration;
136+
}
137+
138+
/**
139+
* Determine if the given backend layout string is a fluidpages layout
140+
*
141+
* @param string $belayout Page row backend_layout value
142+
*
143+
* @return boolean True if fluidpages should be used to render
144+
*/
145+
public function isFluidpagesBackendLayout($belayout)
146+
{
147+
return substr($belayout, 0, 12) == 'fluidpages__';
148+
}
149+
150+
/**
151+
* @return \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend
152+
*/
153+
protected function getRuntimeCache()
154+
{
155+
return GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_runtime');
156+
}
157+
158+
/**
159+
* @return use WorkspacesAwareRecordService
160+
*/
161+
protected function getWorkspacesAwareRecordService()
162+
{
163+
if (null === $this->workspacesAwareRecordService) {
164+
$this->workspacesAwareRecordService = GeneralUtility::makeInstance(ObjectManager::class)
165+
->get(WorkspacesAwareRecordService::class);
166+
}
167+
return $this->workspacesAwareRecordService;
168+
}
169+
170+
/**
171+
* Used in unit tests.
172+
*
173+
* @param WorkspacesAwareRecordService $workspacesAwareRecordService
174+
*
175+
* @return void
176+
*/
177+
public function setWorkspacesAwareRecordService(WorkspacesAwareRecordService $workspacesAwareRecordService)
178+
{
179+
$this->workspacesAwareRecordService = $workspacesAwareRecordService;
180+
}
181+
}
182+
?>

Configuration/TCA/Overrides/pages.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
'disabled' => false
1818
]
1919
]
20-
]
20+
],
21+
'displayCond' => 'USER:FluidTYPO3\\Fluidpages\\UserFunction\\LayoutSelect->doShowPageConfiguration:0',
2122
],
2223
'tx_fed_page_controller_action_sub' => [
2324
'exclude' => 1,
@@ -32,7 +33,8 @@
3233
'disabled' => false
3334
]
3435
]
35-
]
36+
],
37+
'displayCond' => 'USER:FluidTYPO3\\Fluidpages\\UserFunction\\LayoutSelect->doShowPageConfiguration:1',
3638
],
3739
'tx_fed_page_flexform' => [
3840
'exclude' => 1,
@@ -42,7 +44,8 @@
4244
'ds' => [
4345
'default' => '<T3DataStructure><ROOT><el></el></ROOT></T3DataStructure>'
4446
]
45-
]
47+
],
48+
'displayCond' => 'USER:FluidTYPO3\\Fluidpages\\UserFunction\\LayoutSelect->doShowPageConfiguration:0',
4649
],
4750
'tx_fed_page_flexform_sub' => [
4851
'exclude' => 1,
@@ -52,7 +55,8 @@
5255
'ds' => [
5356
'default' => '<T3DataStructure><ROOT><el></el></ROOT></T3DataStructure>'
5457
]
55-
]
58+
],
59+
'displayCond' => 'USER:FluidTYPO3\\Fluidpages\\UserFunction\\LayoutSelect->doShowPageConfiguration:1',
5660
],
5761
]);
5862

0 commit comments

Comments
 (0)