Passed
Pull Request — master (#75)
by Nathan
03:53
created

EntitySlackTcaWriter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 192
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 192
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getNotificationTcaServiceClass() 0 3 1
B buildTcaArray() 0 159 1
A getCtrl() 0 8 1
1
<?php
2
3
/*
4
 * Copyright (C) 2018
5
 * Nathan Boiron <[email protected]>
6
 * Romain Canon <[email protected]>
7
 *
8
 * This file is part of the TYPO3 NotiZ project.
9
 * It is free software; you can redistribute it and/or modify it
10
 * under the terms of the GNU General Public License, either
11
 * version 3 of the License, or any later version.
12
 *
13
 * For the full copyright and license information, see:
14
 * http://www.gnu.org/licenses/gpl-3.0.html
15
 */
16
17
namespace CuyZ\Notiz\Domain\Notification\Slack\Application\EntitySlack\TCA;
18
19
use CuyZ\Notiz\Core\Notification\TCA\EntityTcaWriter;
20
21
class EntitySlackTcaWriter extends EntityTcaWriter
22
{
23
    const SLACK_LLL = 'LLL:EXT:notiz/Resources/Private/Language/Notification/Slack/Entity.xlf';
24
25
    /**
26
     * @return array
27
     */
28
    protected function buildTcaArray()
29
    {
30
        return [
31
            'ctrl' => $this->getCtrl(),
32
33
            'palettes' => [
34
                'content' => [
35
                    'showitem' => 'message,markers',
36
                    'canNotCollapse' => true,
37
                ],
38
                'bot' => [
39
                    'showitem' => 'custom_bot,--linebreak--,bot,no_defined_bot,name,--linebreak--,avatar',
40
                    'canNotCollapse' => true,
41
                ],
42
                'channel' => [
43
                    'showitem' => 'slack_channel,no_defined_slack_channel',
44
                    'canNotCollapse' => true,
45
                ],
46
                'channel_custom' => [
47
                    'showitem' => 'target,--linebreak--,webhook_url',
48
                    'canNotCollapse' => true,
49
                ],
50
            ],
51
52
            'types' => [
53
                '0' => [
54
                    'showitem' => '
55
                error_message,
56
                title, sys_language_uid, hidden,
57
                --div--;' . self::LLL_TABS . ':tab.event,
58
                    event, event_configuration_flex,
59
                --div--;' . self::LLL_TABS . ':tab.channel,
60
                    channel,
61
                --div--;' . self::SLACK_LLL . ':tab.content,
62
                    --palette--;' . self::SLACK_LLL . ':palette.content;content,
63
                --div--;' . self::SLACK_LLL . ':tab.slack,
64
                    --palette--;' . self::SLACK_LLL . ':palette.bot;bot,
65
                    --palette--;' . self::SLACK_LLL . ':palette.channel;channel,
66
                    --palette--;' . self::SLACK_LLL . ':palette.channel_custom;channel_custom
67
'
68
                ]
69
            ],
70
71
            'columns' => [
72
73
                'message' => [
74
                    'exclude' => 1,
75
                    'label' => self::SLACK_LLL . ':field.message',
76
                    'config' => [
77
                        'type' => 'text',
78
                        'size' => 4000,
79
                        'eval' => 'trim,required',
80
                    ],
81
                ],
82
83
                'custom_bot' => [
84
                    'exclude' => 1,
85
                    'label' => self::SLACK_LLL . ':field.custom_bot',
86
                    'config' => [
87
                        'type' => 'check',
88
                        'default' => 0,
89
                    ],
90
                ],
91
92
                'bot' => [
93
                    'exclude' => 1,
94
                    'label' => self::SLACK_LLL . ':field.bot',
95
                    'displayCond' => [
96
                        'AND' => [
97
                            'FIELD:custom_bot:=:0',
98
                            'USER:' . $this->getNotificationTcaServiceClass() . '->hasDefinedBot',
99
                        ],
100
                    ],
101
                    'config' => [
102
                        'type' => 'select',
103
                        'itemsProcFunc' => $this->getNotificationTcaServiceClass() . '->getBotsList',
104
                        'size' => 1,
105
                        'maxitems' => 1,
106
                        'eval' => 'required',
107
                    ],
108
                ],
109
110
                'no_defined_bot' => [
111
                    'exclude' => 1,
112
                    'label' => self::SLACK_LLL . ':field.no_defined_bot',
113
                    'displayCond' => [
114
                        'AND' => [
115
                            'FIELD:custom_bot:=:0',
116
                            'USER:' . $this->getNotificationTcaServiceClass() . '->hasNoDefinedBot',
117
                        ],
118
                    ],
119
                    'config' => [
120
                        'type' => 'user',
121
                        'userFunc' => $this->getNotificationTcaServiceClass() . '->getNoDefinedBotText',
122
                    ],
123
                ],
124
125
                'name' => [
126
                    'exclude' => 1,
127
                    'label' => self::SLACK_LLL . ':field.name',
128
                    'displayCond' => 'FIELD:custom_bot:=:1',
129
                    'config' => [
130
                        'type' => 'input',
131
                        'size' => 255,
132
                        'eval' => 'trim,required',
133
                    ],
134
                ],
135
136
                'avatar' => [
137
                    'exclude' => 1,
138
                    'label' => self::SLACK_LLL . ':field.avatar',
139
                    'displayCond' => 'FIELD:custom_bot:=:1',
140
                    'config' => [
141
                        'type' => 'input',
142
                        'size' => 255,
143
                        'eval' => 'trim,required',
144
                    ],
145
                ],
146
147
                'no_defined_slack_channel' => [
148
                    'exclude' => 1,
149
                    'label' => self::SLACK_LLL . ':field.no_defined_slack_channel',
150
                    'displayCond' => 'USER:' . $this->getNotificationTcaServiceClass() . '->hasNoDefinedSlackChannel',
151
                    'config' => [
152
                        'type' => 'user',
153
                        'userFunc' => $this->getNotificationTcaServiceClass() . '->getNoDefinedSlackChannelText',
154
                    ],
155
                ],
156
157
                'slack_channel' => [
158
                    'exclude' => 1,
159
                    'label' => self::SLACK_LLL . ':field.slack_channel',
160
                    'displayCond' => 'USER:' . $this->getNotificationTcaServiceClass() . '->hasDefinedSlackChannel',
161
                    'config' => [
162
                        'type' => 'select',
163
                        'itemsProcFunc' => $this->getNotificationTcaServiceClass() . '->getSlackChannelsList',
164
                        'renderType' => 'selectMultipleSideBySide',
165
                        'size' => 5,
166
                        'maxitems' => 128,
167
                    ],
168
                ],
169
170
                'target' => [
171
                    'exclude' => 1,
172
                    'label' => self::SLACK_LLL . ':field.target',
173
                    'config' => [
174
                        'type' => 'input',
175
                        'size' => 255,
176
                        'eval' => 'trim,required',
177
                    ],
178
                ],
179
180
                'webhook_url' => [
181
                    'exclude' => 1,
182
                    'label' => self::SLACK_LLL . ':field.webhook_url',
183
                    'config' => [
184
                        'type' => 'input',
185
                        'size' => 255,
186
                        'eval' => 'trim,required',
187
                    ],
188
                ],
189
190
            ],
191
        ];
192
    }
193
194
    /**
195
     * @return array
196
     */
197
    protected function getCtrl()
198
    {
199
        $ctrl = $this->getDefaultCtrl();
200
201
        $ctrl['title'] = self::SLACK_LLL . ':title';
202
        $ctrl['requestUpdate'] .= ',custom_bot';
203
204
        return $ctrl;
205
    }
206
207
    /**
208
     * @return string
209
     */
210
    protected function getNotificationTcaServiceClass()
211
    {
212
        return EntitySlackTcaService::class;
213
    }
214
}
215