EventConfigurationProcessor   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 32
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A doProcess() 0 25 4
1
<?php
2
declare(strict_types=1);
3
4
/*
5
 * Copyright (C)
6
 * Nathan Boiron <[email protected]>
7
 * Romain Canon <[email protected]>
8
 *
9
 * This file is part of the TYPO3 NotiZ project.
10
 * It is free software; you can redistribute it and/or modify it
11
 * under the terms of the GNU General Public License, either
12
 * version 3 of the License, or any later version.
13
 *
14
 * For the full copyright and license information, see:
15
 * http://www.gnu.org/licenses/gpl-3.0.html
16
 */
17
18
namespace CuyZ\Notiz\Core\Notification\TCA\Processor;
19
20
/**
21
 * Builds the TCA array for the event configuration.
22
 *
23
 * It is a FlexForm field, with as many definition sheets as there are events
24
 * using FlexForm. Display conditions are dynamically assigned to show the
25
 * correct definition depending on the selected event.
26
 */
27
class EventConfigurationProcessor extends GracefulProcessor
28
{
29
    const COLUMN = 'event_configuration_flex';
30
31
    /**
32
     * @param string $tableName
33
     */
34
    protected function doProcess(string $tableName)
35
    {
36
        $flexFormDs = [
37
            'default' => 'FILE:EXT:notiz/Configuration/FlexForm/Event/Default.xml',
38
        ];
39
        $displayConditions = [];
40
41
        foreach ($this->definitionService->getDefinition()->getEvents() as $event) {
42
            $provider = $event->getConfiguration()->getFlexFormProvider();
43
44
            if ($provider->hasFlexForm()) {
45
                $identifier = $event->getFullIdentifier();
46
47
                $flexFormDs[$identifier] = $provider->getFlexFormValue();
48
                $displayConditions[] = $identifier;
49
            }
50
        }
51
52
        // If no definition is found, the field is not shown at all.
53
        if (empty($flexFormDs)) {
54
            $GLOBALS['TCA'][$tableName]['columns'][self::COLUMN]['config'] = ['type' => 'passthrough'];
55
        }
56
57
        $GLOBALS['TCA'][$tableName]['columns'][self::COLUMN]['config']['ds'] = $flexFormDs;
58
        $GLOBALS['TCA'][$tableName]['columns'][self::COLUMN]['displayCond'] = 'FIELD:event:IN:' . implode(',', $displayConditions);
59
    }
60
}
61