Passed
Pull Request — master (#146)
by Romain
04:03
created

EventConfigurationProvider   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 53
rs 10
c 0
b 0
f 0
wmc 7

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 45 7
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\Backend\FormEngine\DataProvider;
18
19
use CuyZ\Notiz\Core\Notification\Service\LegacyNotificationTcaService;
20
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
21
22
/**
23
 * Builds the TCA array for the event configuration.
24
 *
25
 * It is a FlexForm field, with as many definition sheets as there are events
26
 * using FlexForm. Display conditions are dynamically assigned to show the
27
 * correct definition depending on the selected event.
28
 */
29
class EventConfigurationProvider extends GracefulProvider
30
{
31
    const COLUMN = '__eventConfiguration';
32
33
    /**
34
     * @param array $result
35
     * @return array Result
36
     */
37
    public function process(array $result)
38
    {
39
        $tableName = $result['tableName'];
40
41
        if (!isset($GLOBALS['TCA'][$tableName]['ctrl'][self::COLUMN])) {
42
            return $result;
43
        }
44
45
        $columnName = $GLOBALS['TCA'][$tableName]['ctrl'][self::COLUMN];
46
47
        if (!isset($GLOBALS['TCA'][$tableName]['columns'][$columnName])) {
48
            return $result;
49
        }
50
51
        $flexFormDs = [];
52
        $displayConditions = [];
53
54
        foreach ($this->definitionService->getDefinition()->getEvents() as $event) {
55
            $provider = $event->getConfiguration()->getFlexFormProvider();
56
57
            if ($provider->hasFlexForm()) {
58
                $identifier = $event->getFullIdentifier();
59
60
                $flexFormDs[$identifier] = $provider->getFlexFormValue();
61
                $displayConditions[] = $identifier;
62
            }
63
        }
64
65
        // If no definition is found, the field is not shown at all.
66
        if (empty($flexFormDs)) {
67
            $GLOBALS['TCA'][$tableName]['columns'][$columnName]['config'] = ['type' => 'passthrough'];
68
        }
69
70
        /**
71
         * @deprecated Value can be empty when TYPO3 v7 is not supported anymore.
72
         */
73
        $flexFormDs['default'] = 'FILE:EXT:notiz/Configuration/FlexForm/Event/DefaultEventFlexForm.xml';
74
75
        $GLOBALS['TCA'][$tableName]['columns'][$columnName]['config']['ds'] = $flexFormDs;
76
77
        $GLOBALS['TCA'][$tableName]['columns'][$columnName]['displayCond'] = version_compare(VersionNumberUtility::getCurrentTypo3Version(), '8.0.0', '<')
78
            ? 'USER:' . LegacyNotificationTcaService::class . '->displayEventFlexForm:' . $tableName . ':' . implode(',', $displayConditions)
79
            : 'FIELD:event:IN:' . implode(',', $displayConditions);
80
81
        return $result;
82
    }
83
}
84