Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Classes/Backend/Grid/ContainerGridColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

class ContainerGridColumn extends GridColumn
{
public const CONTAINER_COL_POS_DELIMITER = '-';

public function __construct(
PageLayoutContext $context,
array $columnDefinition,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* of the License, or any later version.
*/

use B13\Container\Backend\Grid\ContainerGridColumn;
use B13\Container\Domain\Factory\ContainerFactory;
use B13\Container\Domain\Factory\Exception;
use B13\Container\Domain\Model\Container;
Expand Down Expand Up @@ -56,7 +55,7 @@ public function addCopyMapping(int $sourceContentId, int $containerId, int $targ
$record = $this->getRecord($sourceContentId);
$sourceColPos = (int)$record['colPos'];
$sourceContainerId = (int)$record['tx_container_parent'];
$this->copyMapping[$sourceContainerId . ContainerGridColumn::CONTAINER_COL_POS_DELIMITER . $sourceColPos] = [
$this->copyMapping[$sourceContainerId . '-' . $sourceColPos] = [
'containerId' => $containerId,
'sourceColPos' => $sourceColPos,
'targetColPos' => $targetColpos,
Expand Down
56 changes: 21 additions & 35 deletions Classes/Hooks/Datahandler/CommandMapBeforeStartHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@
* of the License, or any later version.
*/

use B13\Container\Backend\Grid\ContainerGridColumn;
use B13\Container\Domain\Factory\ContainerFactory;
use B13\Container\Domain\Factory\Exception;
use B13\Container\Domain\Service\ContainerService;
use B13\Container\Tca\Registry;
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\Utility\GeneralUtility;

#[Autoconfigure(public: true)]
class CommandMapBeforeStartHook
Expand All @@ -36,7 +34,7 @@ public function processCmdmap_beforeStart(DataHandler $dataHandler): void
{
$this->unsetInconsistentLocalizeCommands($dataHandler);
$dataHandler->cmdmap = $this->rewriteSimpleCommandMap($dataHandler->cmdmap);
$dataHandler->cmdmap = $this->extractContainerIdFromColPosOnUpdate($dataHandler->cmdmap);
$dataHandler->cmdmap = $this->setContainerIdToZeroIfNotSetOnUpdate($dataHandler->cmdmap);
$this->unsetInconsistentCopyOrMoveCommands($dataHandler);
// previously page id is used for copy/moving element at top of a container colum
// but this leeds to wrong sorting in page context (e.g. List-Module)
Expand Down Expand Up @@ -91,6 +89,24 @@ protected function unsetInconsistentCopyOrMoveCommands(DataHandler $dataHandler)
}
}

protected function setContainerIdToZeroIfNotSetOnUpdate(array $cmdmap): array
{
if (!empty($cmdmap['tt_content'])) {
foreach ($cmdmap['tt_content'] as $id => &$cmds) {
foreach ($cmds as &$cmd) {
if (
(!empty($cmd['update'])) &&
isset($cmd['update']['colPos']) &&
!isset($cmd['update']['tx_container_parent'])
) {
$cmd['update']['tx_container_parent'] = 0;
}
}
}
}
return $cmdmap;
}

protected function rewriteCommandMapTargetForAfterContainer(array $cmdmap): array
{
if (!empty($cmdmap['tt_content'])) {
Expand Down Expand Up @@ -195,8 +211,9 @@ protected function rewriteSimpleCommandMap(array $cmdmap): array
'action' => 'paste',
'target' => $target,
'update' => [
'colPos' => $targetRecordForOperation['tx_container_parent'] . ContainerGridColumn::CONTAINER_COL_POS_DELIMITER . $targetRecordForOperation['colPos'],
'colPos' => $targetRecordForOperation['colPos'],
'sys_language_uid' => $targetRecordForOperation['sys_language_uid'],
'tx_container_parent' => $targetRecordForOperation['tx_container_parent'],

],
],
Expand Down Expand Up @@ -246,37 +263,6 @@ protected function unsetInconsistentLocalizeCommands(DataHandler $dataHandler):
}
}

protected function extractContainerIdFromColPosOnUpdate(array $cmdmap): array
{
if (!empty($cmdmap['tt_content'])) {
foreach ($cmdmap['tt_content'] as $id => &$cmds) {
foreach ($cmds as &$cmd) {
if (
(!empty($cmd['update'])) &&
isset($cmd['update']['colPos'])
) {
$cmd['update'] = $this->dataFromContainerIdColPos($cmd['update']);
}
}
}
}
return $cmdmap;
}

protected function dataFromContainerIdColPos(array $data): array
{
$colPos = $data['colPos'];
if (strpos((string)$colPos, ContainerGridColumn::CONTAINER_COL_POS_DELIMITER) > 0) {
[$containerId, $newColPos] = GeneralUtility::intExplode(ContainerGridColumn::CONTAINER_COL_POS_DELIMITER, $colPos);
$data['colPos'] = $newColPos;
$data['tx_container_parent'] = $containerId;
} elseif (!isset($data['tx_container_parent'])) {
$data['tx_container_parent'] = 0;
$data['colPos'] = (int)$colPos;
}
return $data;
}

protected function logAndUnsetCmd(int $id, string $cmd, string $message, DataHandler $dataHandler): void
{
$dataHandler->log(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public function copyContainerIntoOtherContainerWithSameColPosCopiesAlsoChildEven
'action' => 'paste',
'target' => -2,
'update' => [
'colPos' => '1-200',
'colPos' => 200,
'tx_container_parent' => 1,
],
],
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public function moveElementIntoContainerAtTopDoNotMoveDisallowedCTypeElement():
'action' => 'paste',
'target' => 1,
'update' => [
'colPos' => '1-200',
'colPos' => 200,
'sys_language_uid' => 0,

'tx_container_parent' => 1,
],
],
],
Expand All @@ -71,8 +71,9 @@ public function moveElementIntoContainerAfterOtherElemenDoNotMoveDisallowedCType
'action' => 'paste',
'target' => -2,
'update' => [
'colPos' => '1-200',
'colPos' => 200,
'sys_language_uid' => 0,
'tx_container_parent' => 1,

],
],
Expand All @@ -98,8 +99,9 @@ public function copyElementIntoContainerAtTopDoNotCopyDisallowedCTypeElement():
'action' => 'paste',
'target' => 1,
'update' => [
'colPos' => '1-200',
'colPos' => 200,
'sys_language_uid' => 0,
'tx_container_parent' => 1,

],
],
Expand All @@ -125,8 +127,9 @@ public function moveElementIntoContainerAtTopMoveAisallowedCTypeElement(): void
'action' => 'paste',
'target' => 1,
'update' => [
'colPos' => '1-200',
'colPos' => 200,
'sys_language_uid' => 0,
'tx_container_parent' => 1,

],
],
Expand All @@ -152,8 +155,9 @@ public function moveElementIntoContainerAfterOtherElemenMoveAllowedCTypeElement(
'action' => 'paste',
'target' => -2,
'update' => [
'colPos' => '1-200',
'colPos' => 200,
'sys_language_uid' => 0,
'tx_container_parent' => 1,

],
],
Expand Down Expand Up @@ -208,9 +212,9 @@ public function copyElementIntoContainerAtTopCopyAllowedCTypeElement(): void
'action' => 'paste',
'target' => 1,
'update' => [
'colPos' => '1-200',
'colPos' => 200,
'sys_language_uid' => 0,

'tx_container_parent' => 1,
],
],
],
Expand All @@ -235,9 +239,9 @@ public function copyChildFromOtherContainerIntoColposWhereTargetElementInOtherCo
'action' => 'paste',
'target' => -2,
'update' => [
'colPos' => '1-201',
'colPos' => 201,
'sys_language_uid' => 0,

'tx_container_parent' => 1,
],
],
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public function moveElementIntoContainerAtTopToNotMoveTranslationIfDisallowedCTy
'action' => 'paste',
'target' => 1,
'update' => [
'colPos' => '1-200',
'colPos' => 200,
'sys_language_uid' => 0,

'tx_container_parent' => 1,
],
],
],
Expand All @@ -69,9 +69,9 @@ public function copyElementIntoContainerAtTopDoNotCopyTranslationIfDisallowedCTy
'action' => 'paste',
'target' => 1,
'update' => [
'colPos' => '1-200',
'colPos' => 200,
'sys_language_uid' => 0,

'tx_container_parent' => 1,
],
],
],
Expand Down
26 changes: 15 additions & 11 deletions Tests/Functional/Datahandler/ContentDefender/MaxItemsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public function canMoveElementIntoContainerIfMaxitemsIsNotReached(): void
'action' => 'paste',
'target' => 1,
'update' => [
'colPos' => '1-202',
'colPos' => 202,
'sys_language_uid' => 0,

'tx_container_parent' => 1,
],
],
],
Expand All @@ -71,9 +71,9 @@ public function cannotMoveElementIntoContainerIfMaxitemsIsReached(): void
'action' => 'paste',
'target' => -3,
'update' => [
'colPos' => '1-202',
'colPos' => 202,
'sys_language_uid' => 0,

'tx_container_parent' => 1,
],
],
],
Expand Down Expand Up @@ -104,9 +104,9 @@ public function cannotCopyElementIntoContainerIfMaxitemsIsReachedAfterIntoContai
'action' => 'paste',
'target' => 1,
'update' => [
'colPos' => '1-202',
'colPos' => 202,
'sys_language_uid' => 0,

'tx_container_parent' => 1,
],
],
],
Expand Down Expand Up @@ -157,7 +157,7 @@ public function canCreateElementInContainerIfMaxitemsIsNotReached(): void
$datamap = [
'tt_content' => [
$newId => [
'colPos' => '202',
'colPos' => 202,
'tx_container_parent' => 1,
'pid' => -1,
'sys_language_uid' => 0,
Expand Down Expand Up @@ -257,8 +257,9 @@ public function canCopyElementFromContainerMaxitemsReachedColumnToOtherColumn():
'action' => 'paste',
'target' => 1,
'update' => [
'colPos' => '1-201',
'colPos' => 201,
'sys_language_uid' => 0,
'tx_container_parent' => 1,
],
],
],
Expand All @@ -283,8 +284,9 @@ public function canCopyElementFromContainerMaxitemsReachedColumnToOtherContainer
'action' => 'paste',
'target' => 1,
'update' => [
'colPos' => '3-201',
'colPos' => 201,
'sys_language_uid' => 0,
'tx_container_parent' => 3,
],
],
],
Expand All @@ -309,8 +311,9 @@ public function canMoveElementFromContainerMaxitemsReachedColumnToOtherContainer
'action' => 'paste',
'target' => 1,
'update' => [
'colPos' => '3-201',
'colPos' => 201,
'sys_language_uid' => 0,
'tx_container_parent' => 3,
],
],
],
Expand All @@ -335,8 +338,9 @@ public function cannotMoveElementInsideContainerColumnIfMaxitemsIsReached(): voi
'action' => 'paste',
'target' => -2,
'update' => [
'colPos' => '1-202',
'colPos' => 202,
'sys_language_uid' => 0,
'tx_container_parent' => 1,
],
],
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public function moveContainerIntoItSelfsNestedAtTop(): void
'action' => 'paste',
'target' => 2,
'update' => [
'colPos' => '2-202',
'colPos' => 202,
'sys_language_uid' => 0,

'tx_container_parent' => 2,
],
],
],
Expand All @@ -74,9 +74,9 @@ public function moveContainerIntoItSelfsAtTop(): void
'action' => 'paste',
'target' => 2,
'update' => [
'colPos' => '1-202',
'colPos' => 202,
'sys_language_uid' => 0,

'tx_container_parent' => 1,
],
],
],
Expand Down Expand Up @@ -118,7 +118,6 @@ public function moveContainerAfterElementMovesChildren(): void
'update' => [
'colPos' => 0,
'sys_language_uid' => 0,

],
],
],
Expand Down
Loading
Loading