forked from lochmueller/calendarize
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegister.php
More file actions
142 lines (129 loc) Β· 4.55 KB
/
Copy pathRegister.php
File metadata and controls
142 lines (129 loc) Β· 4.55 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
declare(strict_types=1);
namespace HDNET\Calendarize;
use HDNET\Calendarize\Domain\Model\ConfigurationGroup;
use HDNET\Calendarize\Domain\Model\Event;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
/**
* Register the calendarize objects.
*/
class Register
{
public const UNIQUE_REGISTER_KEY = 'Event';
/**
* Register in the extTables.
*
* @deprecated use Register::extLocalconf in your ext_localconf and Register::createTcaConfiguration in your TCA override configuration
*/
public static function extTables(array $configuration): void
{
self::createTcaConfiguration($configuration);
self::registerItem($configuration);
}
/**
* Register in the extLocalconf.
*
* @param array $configuration
*/
public static function extLocalconf(array $configuration): void
{
self::registerItem($configuration);
}
/**
* Get the register.
*
* @return array
*/
public static function getRegister(): array
{
return $GLOBALS['TYPO3_CONF_VARS']['EXT']['Calendarize'] ?? [];
}
/**
* Default configuration for the current extension.
* If you want to use the calendarize features in your own extension,
* you have to implement an own configuration.
*
* @return array
*/
public static function getDefaultCalendarizeConfiguration(): array
{
return [
'uniqueRegisterKey' => self::UNIQUE_REGISTER_KEY,
'title' => 'Calendarize Event',
'modelName' => Event::class,
'partialIdentifier' => 'Event',
'tableName' => 'tx_calendarize_domain_model_event',
'required' => true,
// 'tcaTypeList' => '', // optional - only for special type elements
// 'overrideBookingRequestModel' => \NAME\SPACE\CLASS\Name::class,
// 'fieldName' => 'xxxx', // default is "calendarize"
];
}
/**
* @return array
*/
public static function getGroupCalendarizeConfiguration(): array
{
return [
'uniqueRegisterKey' => 'ConfigurationGroup',
'title' => 'Calendarize Configuration Group',
'modelName' => ConfigurationGroup::class,
'partialIdentifier' => 'ConfigurationGroup',
'tableName' => 'tx_calendarize_domain_model_configurationgroup',
'required' => true,
'fieldName' => 'configurations',
];
}
/**
* Add the calendarize to the given TCA.
*
* @param array $configuration
*/
public static function createTcaConfiguration(array $configuration): void
{
$fieldName = $configuration['fieldName'] ?? 'calendarize';
$tableName = $configuration['tableName'];
$typeList = isset($configuration['tcaTypeList']) ? trim($configuration['tcaTypeList']) : '';
// Configure position of where to put the calendarize fields
// Supports everything offered by TYPO3, e.g.: before:abc, after:abc, replace:abc
$position = isset($configuration['tcaPosition']) ? trim($configuration['tcaPosition']) : '';
$GLOBALS['TCA'][$tableName]['columns'][$fieldName] = [
'label' => 'Calendarize',
'l10n_mode' => 'exclude',
'config' => [
'type' => 'inline',
'foreign_table' => 'tx_calendarize_domain_model_configuration',
'minitems' => $configuration['required'] ? 1 : 0,
'maxitems' => 99,
'behaviour' => [
'enableCascadingDelete' => true,
],
],
];
$GLOBALS['TCA'][$tableName]['columns']['calendarize_info'] = [
'label' => 'LLL:EXT:calendarize/Resources/Private/Language/locallang.xlf:tca.information',
'config' => [
'type' => 'none',
'renderType' => 'calendarizeInfoElement',
'parameters' => [
'items' => $GLOBALS['TCA'][$tableName]['columns']['calendarize_info']['config']['parameters']['items'] ?? 10,
],
],
];
ExtensionManagementUtility::addToAllTCAtypes(
$tableName,
$fieldName . ',calendarize_info',
$typeList,
$position,
);
}
/**
* Internal register.
*
* @param array $configuration
*/
protected static function registerItem(array $configuration): void
{
$GLOBALS['TYPO3_CONF_VARS']['EXT']['Calendarize'][$configuration['uniqueRegisterKey']] = $configuration;
}
}