1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* StaticInfoTablesMapper. |
5
|
|
|
*/ |
6
|
|
|
declare(strict_types = 1); |
7
|
|
|
|
8
|
|
|
namespace HDNET\Autoloader\Mapper; |
9
|
|
|
|
10
|
|
|
use HDNET\Autoloader\MapperInterface; |
11
|
|
|
use SJBR\StaticInfoTables\Hook\Backend\Form\FormDataProvider\TcaSelectItemsProcessor; |
12
|
|
|
use SJBR\StaticInfoTables\Hook\Backend\Form\Wizard\SuggestReceiver; |
13
|
|
|
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* StaticInfoTablesMapper. |
17
|
|
|
*/ |
18
|
|
|
class StaticInfoTablesMapper implements MapperInterface |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Class base. |
22
|
|
|
*/ |
23
|
|
|
const CLASS_BASE = 'sjbr\\staticinfotables\\domain\\model\\'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Last class name. |
27
|
|
|
* |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $lastClass; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Check if the current mapper can handle the given type. |
34
|
|
|
* |
35
|
|
|
* @param string $type |
36
|
|
|
* |
37
|
|
|
* @return bool |
38
|
|
|
*/ |
39
|
|
|
public function canHandleType($type) |
40
|
|
|
{ |
41
|
|
|
if (!ExtensionManagementUtility::isLoaded('static_info_tables')) { |
42
|
|
|
return false; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$this->lastClass = mb_strtolower($type); |
46
|
|
|
|
47
|
|
|
return !(false === mb_strpos($this->lastClass, self::CLASS_BASE)); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Get the TCA configuration for the current type. |
52
|
|
|
* |
53
|
|
|
* @param string $fieldName |
54
|
|
|
* @param bool $overWriteLabel |
55
|
|
|
* |
56
|
|
|
* @return array |
57
|
|
|
*/ |
58
|
|
|
public function getTcaConfiguration($fieldName, $overWriteLabel = false) |
59
|
|
|
{ |
60
|
|
|
$withoutNameSpace = str_replace(self::CLASS_BASE, '', $this->lastClass); |
61
|
|
|
|
62
|
|
|
switch ($withoutNameSpace) { |
63
|
|
|
case 'country': |
64
|
|
|
$table = 'static_countries'; |
65
|
|
|
$itemsProcFunc = 'translateCountriesSelector'; |
66
|
|
|
|
67
|
|
|
break; |
68
|
|
|
|
69
|
|
|
case 'countryzone': |
70
|
|
|
$table = 'static_country_zones'; |
71
|
|
|
$itemsProcFunc = 'translateCountryZonesSelector'; |
72
|
|
|
|
73
|
|
|
break; |
74
|
|
|
|
75
|
|
|
case 'currency': |
76
|
|
|
$table = 'static_currencies'; |
77
|
|
|
$itemsProcFunc = 'translateCurrenciesSelector'; |
78
|
|
|
|
79
|
|
|
break; |
80
|
|
|
|
81
|
|
|
case 'language': |
82
|
|
|
$table = 'static_languages'; |
83
|
|
|
$itemsProcFunc = 'translateLanguagesSelector'; |
84
|
|
|
|
85
|
|
|
break; |
86
|
|
|
|
87
|
|
|
case 'territory': |
88
|
|
|
$table = 'static_territories'; |
89
|
|
|
$itemsProcFunc = 'translateTerritoriesSelector'; |
90
|
|
|
|
91
|
|
|
break; |
92
|
|
|
|
93
|
|
|
default: |
94
|
|
|
return []; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return [ |
98
|
|
|
'exclude' => 1, |
99
|
|
|
'label' => $overWriteLabel ? $overWriteLabel : $fieldName, |
100
|
|
|
'config' => [ |
101
|
|
|
'type' => 'select', |
102
|
|
|
'size' => 1, |
103
|
|
|
'minitems' => 0, |
104
|
|
|
'maxitems' => 1, |
105
|
|
|
'items' => [ |
106
|
|
|
['', 0], |
107
|
|
|
], |
108
|
|
|
'itemsProcFunc' => TcaSelectItemsProcessor::class . '->' . $itemsProcFunc, |
109
|
|
|
'foreign_table' => $table, |
110
|
|
|
'wizards' => [ |
111
|
|
|
'suggest' => ['type' => 'suggest', |
112
|
|
|
'default' => [ |
113
|
|
|
'receiverClass' => SuggestReceiver::class, |
114
|
|
|
], |
115
|
|
|
], |
116
|
|
|
], |
117
|
|
|
], |
118
|
|
|
]; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Get the database definition for the current mapper. |
123
|
|
|
* |
124
|
|
|
* @return string |
125
|
|
|
*/ |
126
|
|
|
public function getDatabaseDefinition() |
127
|
|
|
{ |
128
|
|
|
return 'int(11) DEFAULT \'0\' NOT NULL'; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|