Passed
Pull Request — master (#75)
by Nathan
05:29
created

EntitySlackTcaWriter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 181
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 181
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 148 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',
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
                'slack_channel' => [
148
                    'exclude' => 1,
149
                    'label' => self::SLACK_LLL . ':field.slack_channel',
150
                    'config' => [
151
                        'type' => 'select',
152
                        'itemsProcFunc' => $this->getNotificationTcaServiceClass() . '->getSlackChannelsList',
153
                        'renderType' => 'selectMultipleSideBySide',
154
                        'size' => 5,
155
                        'maxitems' => 128,
156
                    ],
157
                ],
158
159
                'target' => [
160
                    'exclude' => 1,
161
                    'label' => self::SLACK_LLL . ':field.target',
162
                    'config' => [
163
                        'type' => 'input',
164
                        'size' => 255,
165
                        'eval' => 'trim,required',
166
                    ],
167
                ],
168
169
                'webhook_url' => [
170
                    'exclude' => 1,
171
                    'label' => self::SLACK_LLL . ':field.webhook_url',
172
                    'config' => [
173
                        'type' => 'input',
174
                        'size' => 255,
175
                        'eval' => 'trim,required',
176
                    ],
177
                ],
178
179
            ],
180
        ];
181
    }
182
183
    /**
184
     * @return array
185
     */
186
    protected function getCtrl()
187
    {
188
        $ctrl = $this->getDefaultCtrl();
189
190
        $ctrl['title'] = self::SLACK_LLL . ':title';
191
        $ctrl['requestUpdate'] .= ',custom_bot';
192
193
        return $ctrl;
194
    }
195
196
    /**
197
     * @return string
198
     */
199
    protected function getNotificationTcaServiceClass()
200
    {
201
        return EntitySlackTcaService::class;
202
    }
203
}
204