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

Commit 51cece2

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 51cece2

File tree

4 files changed

+187
-13
lines changed

4 files changed

+187
-13
lines changed

Classes/Provider/PageProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ public function getControllerActionFromRecord(array $row)
199199
*/
200200
public function getControllerActionReferenceFromRecord(array $row)
201201
{
202-
if (true === empty($row[self::FIELD_ACTION_MAIN])) {
202+
$useFluidpages = substr($row['backend_layout'], 0, 12) == 'fluidpages__';
203+
if (true === empty($row[self::FIELD_ACTION_MAIN]) || false === $useFluidpages) {
203204
$row = $this->pageService->getPageTemplateConfiguration($row['uid']);
204205
}
205206
return $row[self::FIELD_ACTION_MAIN];

Classes/Service/PageService.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function getPageTemplateConfiguration($pageUid)
109109
if ($fromCache) {
110110
return $fromCache;
111111
}
112-
$fieldList = 'tx_fed_page_controller_action_sub,t3ver_oid,pid,uid';
112+
$fieldList = 'tx_fed_page_controller_action_sub,backend_layout,backend_layout_next_level,t3ver_oid,pid,uid';
113113
$page = $this->workspacesAwareRecordService->getSingle(
114114
'pages',
115115
'tx_fed_page_controller_action,' . $fieldList,
@@ -120,17 +120,28 @@ public function getPageTemplateConfiguration($pageUid)
120120
// to fill values as they are detected.
121121
$resolvedMainTemplateIdentity = $page['tx_fed_page_controller_action'];
122122
$resolvedSubTemplateIdentity = $page['tx_fed_page_controller_action_sub'];
123+
$checkTemplates = true;
124+
$resolvedUseFluidpages = substr($page['backend_layout'], 0, 12) == 'fluidpages__';
125+
$checkUseFluidpages = (false === $resolvedUseFluidpages);
123126
do {
124127
$containsSubDefinition = (false !== strpos($page['tx_fed_page_controller_action_sub'], '->'));
125128
$isCandidate = ((integer) $page['uid'] !== $pageUid);
126-
if (true === $containsSubDefinition && true === $isCandidate) {
129+
if (true == $checkTemplates && true === $containsSubDefinition && true === $isCandidate) {
127130
$resolvedSubTemplateIdentity = $page['tx_fed_page_controller_action_sub'];
128131
if (true === empty($resolvedMainTemplateIdentity)) {
129132
// Conditions met: current page is not $pageUid, original page did not
130133
// contain a "this page" layout, current rootline page has "sub" selection.
131134
// Then, set our "this page" value to use the "sub" selection that was detected.
132135
$resolvedMainTemplateIdentity = $resolvedSubTemplateIdentity;
133136
}
137+
$checkTemplates = false;
138+
}
139+
$containsSubBackendLayout = !empty($page['backend_layout_next_level']);
140+
if (true === $checkUseFluidpages && true === $isCandidate && true === $containsSubBackendLayout) {
141+
$resolvedUseFluidpages = substr($page['backend_layout_next_level'], 0, 12) == 'fluidpages__';
142+
$checkUseFluidpages = false;
143+
}
144+
if (false === $checkTemplates && false === $checkUseFluidpages) {
134145
break;
135146
}
136147
// Note: 't3ver_oid' is analysed in order to make versioned records inherit the original record's
@@ -142,6 +153,11 @@ public function getPageTemplateConfiguration($pageUid)
142153
$resolveParentPageUid
143154
);
144155
} while (null !== $page);
156+
157+
if (false === $resolvedUseFluidpages) {
158+
// No "fluidpages' backend layout was configured for this page
159+
return null;
160+
}
145161
if (true === empty($resolvedMainTemplateIdentity) && true === empty($resolvedSubTemplateIdentity)) {
146162
// Neither directly configured "this page" nor inherited "sub" contains a valid value;
147163
// no configuration was detected at all.

Tests/Unit/Provider/PageProviderTest.php

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,86 @@ public function getControllerActionFromRecordTestValues()
165165
{
166166
return array(
167167
array(array('doktype' => PageControllerInterface::DOKTYPE_RAW), '', false, 'raw'),
168-
array(array('doktype' => 0, 'tx_fed_page_controller_action' => ''), 'tx_fed_page_flexform', true, 'default'),
169-
array(array('doktype' => 0, 'tx_fed_page_controller_action' => 'fluidpages->action'), 'tx_fed_page_flexform', false, 'action'),
168+
array(array('doktype' => 0, 'backend_layout' => 'fluidpages__fluidpages', 'tx_fed_page_controller_action' => ''), 'tx_fed_page_flexform', true, 'default'),
169+
array(array('doktype' => 0, 'backend_layout' => 'fluidpages__fluidpages', 'tx_fed_page_controller_action' => 'fluidpages->action'), 'tx_fed_page_flexform', false, 'action'),
170170
);
171171
}
172172

173+
/**
174+
* @dataProvider getControllerActionReferenceFromRecordTestValues
175+
*
176+
* @param array $record Page row
177+
* @param mixed $calcRow Row data calculated by pageService->getPageTemplateConfiguration
178+
* @param mixed $expected Expected return value
179+
*/
180+
public function testGetControllerActionReferenceFromRecord(array $record, $calcRow, $expected)
181+
{
182+
$instance = new PageProvider();
183+
/** @var PageService $service */
184+
$pageServiceMock = $this->getMockBuilder('FluidTYPO3\\Fluidpages\\Service\\PageService')->setMethods(array('getPageTemplateConfiguration'))->getMock();
185+
$pageServiceMock->expects($this->any())
186+
->method('getPageTemplateConfiguration')
187+
->will($this->returnValue($calcRow));
188+
$instance->injectPageService($pageServiceMock);
189+
190+
$result = $instance->getControllerActionReferenceFromRecord($record);
191+
$this->assertEquals($expected, $result);
192+
}
193+
194+
/**
195+
* Data provider for testGetControllerActionReferenceFromRecord()
196+
*
197+
* @return array
198+
*/
199+
public function getControllerActionReferenceFromRecordTestValues()
200+
{
201+
return [
202+
'no action' => [
203+
[
204+
'tx_fed_page_controller_action' => '',
205+
],
206+
null,
207+
null
208+
],
209+
'normal action' => [
210+
[
211+
'tx_fed_page_controller_action' => 'test1->test1',
212+
'backend_layout' => 'fluidpages__foo',
213+
],
214+
[],
215+
'test1->test1'
216+
],
217+
'no action, result from pageService' => [
218+
[
219+
'tx_fed_page_controller_action' => '',
220+
'backend_layout' => 'fluidpages__bar',
221+
],
222+
[
223+
'tx_fed_page_controller_action' => 'test1->test1',
224+
],
225+
'test1->test1'
226+
],
227+
'no backend layout' => [
228+
[
229+
'tx_fed_page_controller_action' => 'test1->test1',
230+
'backend_layout' => '',
231+
],
232+
null,
233+
null
234+
],
235+
'no backend layout, result from pageService' => [
236+
[
237+
'tx_fed_page_controller_action' => 'test1->test1',
238+
'backend_layout' => '',
239+
],
240+
[
241+
'tx_fed_page_controller_action' => 'test2->test2'
242+
],
243+
'test2->test2'
244+
],
245+
];
246+
}
247+
173248
public function testGetFlexFormValuesReturnsCollectedDataWhenEncounteringNullForm()
174249
{
175250
$tree = array(

Tests/Unit/Service/PageServiceTest.php

Lines changed: 90 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,96 @@ public function testGetPageTemplateConfiguration(array $records, $expected)
7171
*/
7272
public function getPageTemplateConfigurationTestValues()
7373
{
74-
$m = 'tx_fed_page_controller_action';
75-
$s = 'tx_fed_page_controller_action_sub';
76-
return array(
77-
array(array(array()), null),
78-
array(array(array($m => '', $s => '')), null),
79-
array(array(array($m => 'test1->test1', $s => 'test2->test2')), array($m => 'test1->test1', $s => 'test2->test2')),
80-
array(array(array($m => ''), array($s => 'test2->test2')), array($m => 'test2->test2', $s => 'test2->test2'))
81-
);
74+
$b = 'backend_layout';
75+
$bs = 'backend_layout_next_level';
76+
$a = 'tx_fed_page_controller_action';
77+
$as = 'tx_fed_page_controller_action_sub';
78+
$bfp = 'fluidpages__fluidpages';
79+
return [
80+
'no data at all' => [
81+
[[]],
82+
null
83+
],
84+
'empty actions' => [
85+
[
86+
[$a => '', $as => '', $b => $bfp, $bs => $bfp]
87+
],
88+
null
89+
],
90+
'controller action on page itself' => [
91+
[
92+
[$a => 'test1->test1', $as => 'test2->test2', $b => $bfp, $bs => $bfp]
93+
],
94+
[$a => 'test1->test1', $as => 'test2->test2']
95+
],
96+
'sub controller action on parent page' => [
97+
[
98+
//pages are listed in reverse order, root level last
99+
[$a => '', $b => $bfp, $bs => $bfp],
100+
[$as => 'test2->test2', $b => $bfp, $bs => $bfp]
101+
],
102+
[$a => 'test2->test2', $as => 'test2->test2']
103+
],
104+
'no backend layout configured' => [
105+
[
106+
[$a => 'test1->test1', $as => 'test2->test2', $b => '', $bs => ''],
107+
],
108+
null
109+
],
110+
'backend layout configured only for parent page' => [
111+
[
112+
[$a => 'test1->test1', $as => 'test2->test2', $b => '' , $bs => ''],
113+
[$a => 'test1->test1', $as => 'test2->test2', $b => $bfp, $bs => ''],
114+
],
115+
null
116+
],
117+
'backend layout configured on parent page' => [
118+
[
119+
[$a => 'test1->test1', $as => 'test2->test2', $b => '', $bs => ''],
120+
[$a => 'test1->test1', $as => 'test2->test2', $b => '', $bs => $bfp],
121+
],
122+
[$a => 'test1->test1', $as => 'test2->test2'],
123+
],
124+
'backend layout configured on parent page #2' => [
125+
[
126+
[$a => '' , $as => '' , $b => '', $bs => ''],
127+
[$a => 'test1->test1', $as => 'test2->test2', $b => '', $bs => $bfp],
128+
],
129+
[$a => 'test2->test2', $as => 'test2->test2'],
130+
],
131+
'different backend layout in between' => [
132+
[
133+
[$a => '' , $as => '' , $b => '', $bs => ''],
134+
[$a => '' , $as => '' , $b => '', $bs => 'templavoila'],
135+
[$a => 'test1->test1', $as => 'test2->test2', $b => '', $bs => $bfp],
136+
],
137+
null
138+
],
139+
'self backend layout, but different backend layout in between' => [
140+
[
141+
[$a => '' , $as => '' , $b => $bfp, $bs => ''],
142+
[$a => '' , $as => '' , $b => '', $bs => 'templavoila'],
143+
[$a => 'test1->test1', $as => 'test2->test2', $b => '', $bs => $bfp],
144+
],
145+
[$a => 'test2->test2', $as => 'test2->test2']
146+
],
147+
'action and backend layout on different levels: action higher' => [
148+
[
149+
[$a => '' , $as => '' , $b => '', $bs => ''],
150+
[$a => '' , $as => '' , $b => '', $bs => $bfp],
151+
[$a => 'test1->test1', $as => 'test2->test2', $b => '', $bs => ''],
152+
],
153+
[$a => 'test2->test2', $as => 'test2->test2']
154+
],
155+
'action and backend layout on different levels: backend layout higher' => [
156+
[
157+
[$a => '' , $as => '' , $b => '', $bs => ''],
158+
[$a => 'test1->test1', $as => 'test2->test2', $b => '', $bs => ''],
159+
[$a => '' , $as => '' , $b => '', $bs => $bfp],
160+
],
161+
[$a => 'test2->test2', $as => 'test2->test2']
162+
],
163+
];
82164
}
83165

84166
/**

0 commit comments

Comments
 (0)