DefaultEventFromGet   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefinition() 0 6 1
A addData() 0 29 5
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\Backend\FormEngine\DataProvider;
19
20
use CuyZ\Notiz\Core\Definition\DefinitionService;
21
use CuyZ\Notiz\Core\Definition\Tree\Definition;
22
use CuyZ\Notiz\Core\Notification\TCA\EntityTcaWriter;
23
use CuyZ\Notiz\Service\Container;
24
use TYPO3\CMS\Backend\Form\FormDataProviderInterface;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Backend\Form\FormDataProviderInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
use TYPO3\CMS\Core\Utility\GeneralUtility;
26
27
/**
28
 * Will check if an argument `selectedEvent` exists in the request. If this
29
 * argument matches an existing event, it will be selected for the field
30
 * `event`.
31
 *
32
 * This service allows creating links for creating notifications in the form
33
 * engine, with a chosen event selected by default.
34
 */
35
class DefaultEventFromGet implements FormDataProviderInterface
36
{
37
    const ENABLE_DEFAULT_VALUE = 'enableDefaultValue';
38
39
    /**
40
     * @param array $result
41
     * @return array
42
     */
43
    public function addData(array $result): array
44
    {
45
        // This feature is available for new records only.
46
        if ($result['command'] !== 'new') {
47
            return $result;
48
        }
49
50
        // The feature needs to be enabled in the `ctrl` section of the TCA.
51
        if (!isset($result['processedTca']['ctrl'][EntityTcaWriter::NOTIFICATION_ENTITY]['dataProvider'][self::ENABLE_DEFAULT_VALUE])) {
52
            return $result;
53
        }
54
55
        // The argument `selectedEvent` must exist in the request.
56
        $selectedEvent = GeneralUtility::_GP('selectedEvent');
57
58
        if (!$selectedEvent) {
59
            return $result;
60
        }
61
62
        $definition = $this->getDefinition();
63
64
        // The given event must be a valid identifier.
65
        if (!$definition->hasEventFromFullIdentifier($selectedEvent)) {
66
            return $result;
67
        }
68
69
        $result['databaseRow']['event'] = $selectedEvent;
70
71
        return $result;
72
    }
73
74
    /**
75
     * @return Definition
76
     */
77
    protected function getDefinition(): Definition
78
    {
79
        /** @var DefinitionService $definitionService */
80
        $definitionService = Container::get(DefinitionService::class);
81
82
        return $definitionService->getDefinition();
83
    }
84
}
85