Skip to content

Commit

Permalink
[BUGFIX] Support mixing of fluidpages with other backend layouts
Browse files Browse the repository at this point in the history
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: FluidTYPO3#366
  • Loading branch information
cweiske committed Sep 29, 2017
1 parent a09324c commit 51cece2
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 13 deletions.
3 changes: 2 additions & 1 deletion Classes/Provider/PageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ public function getControllerActionFromRecord(array $row)
*/
public function getControllerActionReferenceFromRecord(array $row)
{
if (true === empty($row[self::FIELD_ACTION_MAIN])) {
$useFluidpages = substr($row['backend_layout'], 0, 12) == 'fluidpages__';
if (true === empty($row[self::FIELD_ACTION_MAIN]) || false === $useFluidpages) {
$row = $this->pageService->getPageTemplateConfiguration($row['uid']);
}
return $row[self::FIELD_ACTION_MAIN];
Expand Down
20 changes: 18 additions & 2 deletions Classes/Service/PageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function getPageTemplateConfiguration($pageUid)
if ($fromCache) {
return $fromCache;
}
$fieldList = 'tx_fed_page_controller_action_sub,t3ver_oid,pid,uid';
$fieldList = 'tx_fed_page_controller_action_sub,backend_layout,backend_layout_next_level,t3ver_oid,pid,uid';
$page = $this->workspacesAwareRecordService->getSingle(
'pages',
'tx_fed_page_controller_action,' . $fieldList,
Expand All @@ -120,17 +120,28 @@ public function getPageTemplateConfiguration($pageUid)
// to fill values as they are detected.
$resolvedMainTemplateIdentity = $page['tx_fed_page_controller_action'];
$resolvedSubTemplateIdentity = $page['tx_fed_page_controller_action_sub'];
$checkTemplates = true;
$resolvedUseFluidpages = substr($page['backend_layout'], 0, 12) == 'fluidpages__';
$checkUseFluidpages = (false === $resolvedUseFluidpages);
do {
$containsSubDefinition = (false !== strpos($page['tx_fed_page_controller_action_sub'], '->'));
$isCandidate = ((integer) $page['uid'] !== $pageUid);
if (true === $containsSubDefinition && true === $isCandidate) {
if (true == $checkTemplates && true === $containsSubDefinition && true === $isCandidate) {
$resolvedSubTemplateIdentity = $page['tx_fed_page_controller_action_sub'];
if (true === empty($resolvedMainTemplateIdentity)) {
// Conditions met: current page is not $pageUid, original page did not
// contain a "this page" layout, current rootline page has "sub" selection.
// Then, set our "this page" value to use the "sub" selection that was detected.
$resolvedMainTemplateIdentity = $resolvedSubTemplateIdentity;
}
$checkTemplates = false;
}
$containsSubBackendLayout = !empty($page['backend_layout_next_level']);
if (true === $checkUseFluidpages && true === $isCandidate && true === $containsSubBackendLayout) {
$resolvedUseFluidpages = substr($page['backend_layout_next_level'], 0, 12) == 'fluidpages__';
$checkUseFluidpages = false;
}
if (false === $checkTemplates && false === $checkUseFluidpages) {
break;
}
// Note: 't3ver_oid' is analysed in order to make versioned records inherit the original record's
Expand All @@ -142,6 +153,11 @@ public function getPageTemplateConfiguration($pageUid)
$resolveParentPageUid
);
} while (null !== $page);

if (false === $resolvedUseFluidpages) {
// No "fluidpages' backend layout was configured for this page
return null;
}
if (true === empty($resolvedMainTemplateIdentity) && true === empty($resolvedSubTemplateIdentity)) {
// Neither directly configured "this page" nor inherited "sub" contains a valid value;
// no configuration was detected at all.
Expand Down
79 changes: 77 additions & 2 deletions Tests/Unit/Provider/PageProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,86 @@ public function getControllerActionFromRecordTestValues()
{
return array(
array(array('doktype' => PageControllerInterface::DOKTYPE_RAW), '', false, 'raw'),
array(array('doktype' => 0, 'tx_fed_page_controller_action' => ''), 'tx_fed_page_flexform', true, 'default'),
array(array('doktype' => 0, 'tx_fed_page_controller_action' => 'fluidpages->action'), 'tx_fed_page_flexform', false, 'action'),
array(array('doktype' => 0, 'backend_layout' => 'fluidpages__fluidpages', 'tx_fed_page_controller_action' => ''), 'tx_fed_page_flexform', true, 'default'),
array(array('doktype' => 0, 'backend_layout' => 'fluidpages__fluidpages', 'tx_fed_page_controller_action' => 'fluidpages->action'), 'tx_fed_page_flexform', false, 'action'),
);
}

/**
* @dataProvider getControllerActionReferenceFromRecordTestValues
*
* @param array $record Page row
* @param mixed $calcRow Row data calculated by pageService->getPageTemplateConfiguration
* @param mixed $expected Expected return value
*/
public function testGetControllerActionReferenceFromRecord(array $record, $calcRow, $expected)
{
$instance = new PageProvider();
/** @var PageService $service */
$pageServiceMock = $this->getMockBuilder('FluidTYPO3\\Fluidpages\\Service\\PageService')->setMethods(array('getPageTemplateConfiguration'))->getMock();
$pageServiceMock->expects($this->any())
->method('getPageTemplateConfiguration')
->will($this->returnValue($calcRow));
$instance->injectPageService($pageServiceMock);

$result = $instance->getControllerActionReferenceFromRecord($record);
$this->assertEquals($expected, $result);
}

/**
* Data provider for testGetControllerActionReferenceFromRecord()
*
* @return array
*/
public function getControllerActionReferenceFromRecordTestValues()
{
return [
'no action' => [
[
'tx_fed_page_controller_action' => '',
],
null,
null
],
'normal action' => [
[
'tx_fed_page_controller_action' => 'test1->test1',
'backend_layout' => 'fluidpages__foo',
],
[],
'test1->test1'
],
'no action, result from pageService' => [
[
'tx_fed_page_controller_action' => '',
'backend_layout' => 'fluidpages__bar',
],
[
'tx_fed_page_controller_action' => 'test1->test1',
],
'test1->test1'
],
'no backend layout' => [
[
'tx_fed_page_controller_action' => 'test1->test1',
'backend_layout' => '',
],
null,
null
],
'no backend layout, result from pageService' => [
[
'tx_fed_page_controller_action' => 'test1->test1',
'backend_layout' => '',
],
[
'tx_fed_page_controller_action' => 'test2->test2'
],
'test2->test2'
],
];
}

public function testGetFlexFormValuesReturnsCollectedDataWhenEncounteringNullForm()
{
$tree = array(
Expand Down
98 changes: 90 additions & 8 deletions Tests/Unit/Service/PageServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,96 @@ public function testGetPageTemplateConfiguration(array $records, $expected)
*/
public function getPageTemplateConfigurationTestValues()
{
$m = 'tx_fed_page_controller_action';
$s = 'tx_fed_page_controller_action_sub';
return array(
array(array(array()), null),
array(array(array($m => '', $s => '')), null),
array(array(array($m => 'test1->test1', $s => 'test2->test2')), array($m => 'test1->test1', $s => 'test2->test2')),
array(array(array($m => ''), array($s => 'test2->test2')), array($m => 'test2->test2', $s => 'test2->test2'))
);
$b = 'backend_layout';
$bs = 'backend_layout_next_level';
$a = 'tx_fed_page_controller_action';
$as = 'tx_fed_page_controller_action_sub';
$bfp = 'fluidpages__fluidpages';
return [
'no data at all' => [
[[]],
null
],
'empty actions' => [
[
[$a => '', $as => '', $b => $bfp, $bs => $bfp]
],
null
],
'controller action on page itself' => [
[
[$a => 'test1->test1', $as => 'test2->test2', $b => $bfp, $bs => $bfp]
],
[$a => 'test1->test1', $as => 'test2->test2']
],
'sub controller action on parent page' => [
[
//pages are listed in reverse order, root level last
[$a => '', $b => $bfp, $bs => $bfp],
[$as => 'test2->test2', $b => $bfp, $bs => $bfp]
],
[$a => 'test2->test2', $as => 'test2->test2']
],
'no backend layout configured' => [
[
[$a => 'test1->test1', $as => 'test2->test2', $b => '', $bs => ''],
],
null
],
'backend layout configured only for parent page' => [
[
[$a => 'test1->test1', $as => 'test2->test2', $b => '' , $bs => ''],
[$a => 'test1->test1', $as => 'test2->test2', $b => $bfp, $bs => ''],
],
null
],
'backend layout configured on parent page' => [
[
[$a => 'test1->test1', $as => 'test2->test2', $b => '', $bs => ''],
[$a => 'test1->test1', $as => 'test2->test2', $b => '', $bs => $bfp],
],
[$a => 'test1->test1', $as => 'test2->test2'],
],
'backend layout configured on parent page #2' => [
[
[$a => '' , $as => '' , $b => '', $bs => ''],
[$a => 'test1->test1', $as => 'test2->test2', $b => '', $bs => $bfp],
],
[$a => 'test2->test2', $as => 'test2->test2'],
],
'different backend layout in between' => [
[
[$a => '' , $as => '' , $b => '', $bs => ''],
[$a => '' , $as => '' , $b => '', $bs => 'templavoila'],
[$a => 'test1->test1', $as => 'test2->test2', $b => '', $bs => $bfp],
],
null
],
'self backend layout, but different backend layout in between' => [
[
[$a => '' , $as => '' , $b => $bfp, $bs => ''],
[$a => '' , $as => '' , $b => '', $bs => 'templavoila'],
[$a => 'test1->test1', $as => 'test2->test2', $b => '', $bs => $bfp],
],
[$a => 'test2->test2', $as => 'test2->test2']
],
'action and backend layout on different levels: action higher' => [
[
[$a => '' , $as => '' , $b => '', $bs => ''],
[$a => '' , $as => '' , $b => '', $bs => $bfp],
[$a => 'test1->test1', $as => 'test2->test2', $b => '', $bs => ''],
],
[$a => 'test2->test2', $as => 'test2->test2']
],
'action and backend layout on different levels: backend layout higher' => [
[
[$a => '' , $as => '' , $b => '', $bs => ''],
[$a => 'test1->test1', $as => 'test2->test2', $b => '', $bs => ''],
[$a => '' , $as => '' , $b => '', $bs => $bfp],
],
[$a => 'test2->test2', $as => 'test2->test2']
],
];
}

/**
Expand Down

0 comments on commit 51cece2

Please sign in to comment.