-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUGFIX] Detach colPos list items provider from BackendLayoutView
- Loading branch information
1 parent
e863026
commit b6fc780
Showing
6 changed files
with
168 additions
and
347 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
Classes/Integration/HookSubscribers/ColumnPositionItems.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace FluidTYPO3\Flux\Integration\HookSubscribers; | ||
|
||
use FluidTYPO3\Flux\Integration\FormEngine\SelectOption; | ||
use FluidTYPO3\Flux\Provider\Interfaces\GridProviderInterface; | ||
use FluidTYPO3\Flux\Provider\ProviderResolver; | ||
use FluidTYPO3\Flux\Service\WorkspacesAwareRecordService; | ||
use FluidTYPO3\Flux\Utility\ColumnNumberUtility; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
class ColumnPositionItems | ||
{ | ||
private WorkspacesAwareRecordService $recordService; | ||
private ProviderResolver $providerResolver; | ||
|
||
public function __construct(WorkspacesAwareRecordService $recordService, ProviderResolver $providerResolver) | ||
{ | ||
$this->recordService = $recordService; | ||
$this->providerResolver = $providerResolver; | ||
} | ||
|
||
/** | ||
* Gets colPos items to be shown in the forms engine. | ||
* This method is called as "itemsProcFunc" with the accordant context | ||
* for tt_content.colPos. | ||
*/ | ||
public function colPosListItemProcFunc(array &$parameters): void | ||
{ | ||
$parentRecordUid = ColumnNumberUtility::calculateParentUid($parameters['row']['colPos']); | ||
$parentRecord = $this->recordService->getSingle('tt_content', '*', $parentRecordUid); | ||
$provider = $this->providerResolver->resolvePrimaryConfigurationProvider('tt_content', null, $parentRecord); | ||
if ($parentRecord && $provider instanceof GridProviderInterface) { | ||
$grid = $provider->getGrid($parentRecord); | ||
/** @var SelectOption $dividerItem */ | ||
$dividerItem = GeneralUtility::makeInstance( | ||
SelectOption::class, | ||
'LLL:EXT:flux/Resources/Private/Language/locallang.xlf:flux.backendLayout.columnsInParent', | ||
'--div--' | ||
); | ||
$parameters['items'][] = $dividerItem->toArray(); | ||
foreach ($grid->getRows() as $row) { | ||
foreach ($row->getColumns() as $column) { | ||
/** @var SelectOption $item */ | ||
$item = GeneralUtility::makeInstance( | ||
SelectOption::class, | ||
$column->getLabel(), | ||
ColumnNumberUtility::calculateColumnNumberForParentAndColumn( | ||
$parentRecordUid, | ||
$column->getColumnPosition() | ||
) | ||
); | ||
$parameters['items'][] = $item->toArray(); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
Tests/Unit/Integration/HookSubscribers/ColumnPositionItemsTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php | ||
declare(strict_types=1); | ||
namespace FluidTYPO3\Flux\Tests\Unit\Integration\HookSubscribers; | ||
|
||
/* | ||
* This file is part of the FluidTYPO3/Flux project under GPLv2 or later. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.md file that was distributed with this source code. | ||
*/ | ||
|
||
use FluidTYPO3\Flux\Form\Container\Column; | ||
use FluidTYPO3\Flux\Form\Container\Grid; | ||
use FluidTYPO3\Flux\Form\Container\Row; | ||
use FluidTYPO3\Flux\Integration\FormEngine\SelectOption; | ||
use FluidTYPO3\Flux\Integration\HookSubscribers\ColumnPositionItems; | ||
use FluidTYPO3\Flux\Provider\ProviderInterface; | ||
use FluidTYPO3\Flux\Provider\ProviderResolver; | ||
use FluidTYPO3\Flux\Service\WorkspacesAwareRecordService; | ||
use FluidTYPO3\Flux\Tests\Unit\AbstractTestCase; | ||
|
||
class ColumnPositionItemsTest extends AbstractTestCase | ||
{ | ||
private WorkspacesAwareRecordService $recordService; | ||
private ProviderResolver $providerResolver; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->recordService = $this->getMockBuilder(WorkspacesAwareRecordService::class) | ||
->onlyMethods(['getSingle']) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->providerResolver = $this->getMockBuilder(ProviderResolver::class) | ||
->onlyMethods(['resolvePrimaryConfigurationProvider']) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
} | ||
|
||
public function testDoesNotProcessWithoutParentRecord(): void | ||
{ | ||
$this->recordService->method('getSingle')->willReturn(null); | ||
$this->providerResolver->method('resolvePrimaryConfigurationProvider')->willReturn( | ||
$this->getMockBuilder(ProviderInterface::class)->getMockForAbstractClass() | ||
); | ||
$subject = new ColumnPositionItems($this->recordService, $this->providerResolver); | ||
|
||
$parameters = ['row' => ['colPos' => 101]]; | ||
$subject->colPosListItemProcFunc($parameters); | ||
self::assertSame($parameters, $parameters); | ||
} | ||
|
||
public function testDoesNotProcessWithoutProvider(): void | ||
{ | ||
$this->recordService->method('getSingle')->willReturn(['uid' => 123]); | ||
$this->providerResolver->method('resolvePrimaryConfigurationProvider')->willReturn(null); | ||
$subject = new ColumnPositionItems($this->recordService, $this->providerResolver); | ||
|
||
$parameters = ['row' => ['colPos' => 101]]; | ||
$subject->colPosListItemProcFunc($parameters); | ||
self::assertSame($parameters, $parameters); | ||
} | ||
|
||
public function testDoesNotProcessWithoutProviderAndParentRecord(): void | ||
{ | ||
$this->recordService->method('getSingle')->willReturn(null); | ||
$this->providerResolver->method('resolvePrimaryConfigurationProvider')->willReturn(null); | ||
$subject = new ColumnPositionItems($this->recordService, $this->providerResolver); | ||
|
||
$parameters = ['row' => ['colPos' => 101]]; | ||
$subject->colPosListItemProcFunc($parameters); | ||
self::assertSame($parameters, $parameters); | ||
} | ||
|
||
public function testAddsExpectedItems(): void | ||
{ | ||
$grid = Grid::create(); | ||
$grid->createContainer(Row::class, 'row')->createContainer(Column::class, 'col')->setColumnPosition(3); | ||
|
||
$provider = $this->getMockBuilder(ProviderInterface::class)->getMockForAbstractClass(); | ||
$provider->method('getGrid')->willReturn($grid); | ||
|
||
$this->recordService->method('getSingle')->willReturn(['uid' => 123]); | ||
$this->providerResolver->method('resolvePrimaryConfigurationProvider')->willReturn($provider); | ||
$subject = new ColumnPositionItems($this->recordService, $this->providerResolver); | ||
|
||
$parameters = ['row' => ['colPos' => 103]]; | ||
$expected = $parameters; | ||
$expected['items'] = [ | ||
(new SelectOption( | ||
'LLL:EXT:flux/Resources/Private/Language/locallang.xlf:flux.backendLayout.columnsInParent', | ||
'--div--' | ||
))->toArray(), | ||
(new SelectOption( | ||
'LLL:EXT:flux/Resources/Private/Language/locallang.xlf:flux..columns.col', | ||
103 | ||
))->toArray(), | ||
]; | ||
|
||
$subject->colPosListItemProcFunc($parameters); | ||
self::assertSame($expected, $parameters); | ||
} | ||
} |
Oops, something went wrong.