-
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathDatamapDataHandlerHook.php
More file actions
112 lines (97 loc) · 3.37 KB
/
DatamapDataHandlerHook.php
File metadata and controls
112 lines (97 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
declare(strict_types=1);
namespace Extcode\CartProducts\Hooks;
/*
* This file is part of the package extcode/cart-products.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\Utility\MathUtility;
class DatamapDataHandlerHook
{
/**
* @var int[][]
*/
protected static $colPosCount = [];
/**
* @param DataHandler $dataHandler
*/
public function processDatamap_beforeStart(DataHandler $dataHandler): void
{
$datamap = $dataHandler->datamap;
if (empty($datamap['tt_content']) || $dataHandler->bypassAccessCheckForRecords) {
return;
}
foreach ($datamap['tt_content'] as $id => $incomingFieldArray) {
$incomingFieldArray['uid'] = $id;
if (MathUtility::canBeInterpretedAsInteger($id)) {
$incomingFieldArray = array_merge(BackendUtility::getRecord('tt_content', $id), $incomingFieldArray);
}
$pageId = (int)$incomingFieldArray['pid'];
if ($pageId < 0) {
$previousRecord = BackendUtility::getRecord('tt_content', abs($pageId), 'pid');
$pageId = (int)$previousRecord['pid'];
$incomingFieldArray['pid'] = $pageId;
}
$page = BackendUtility::getRecord('pages', abs($pageId));
$listType = $incomingFieldArray['list_type'] ?? '';
if (!$this->isAllowedTargetPage($listType, $page['doktype'])) {
unset($dataHandler->datamap['tt_content'][$id]);
$dataHandler->log(
'tt_content',
$id,
1,
$pageId,
1,
'The record "%s" couldn\'t be saved due to disallowed value(s).',
23,
[
$incomingFieldArray[$GLOBALS['TCA']['tt_content']['ctrl']['label']],
]
);
}
}
}
public function processDatamap_afterAllOperations(DataHandler $dataHandler): void
{
$newIdUidArray = $dataHandler->substNEWwithIDs;
if (empty($newIdUidArray)) {
return;
}
foreach (self::$colPosCount as $identifier => $uidArray) {
$intersect = array_intersect_key($newIdUidArray, $uidArray);
if (empty($intersect)) {
continue;
}
self::$colPosCount[$identifier] = array_replace(
array_diff_key($uidArray, $newIdUidArray),
array_combine($intersect, $intersect)
);
}
}
protected function isAllowedTargetPage($listType, $doktype)
{
if (empty($listType) || substr((string)$listType, 0, 11) !== 'cartproducts_') {
return true;
}
if (
(
($doktype === 183) && (
$listType === 'cartproducts_singleproduct'
)
)
|| (
($doktype !== 183) && (
$listType === 'cartproducts_products'
|| $listType === 'cartproducts_slots'
)
)
) {
return true;
}
return false;
}
}