DefinitionError   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 72
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefinitionErrorMessage() 0 7 1
A addData() 0 13 3
A __construct() 0 4 1
A getDefinitionErrorTca() 0 13 1
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\Notification\TCA\EntityTcaWriter;
22
use CuyZ\Notiz\Service\Container;
23
use CuyZ\Notiz\Service\ViewService;
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\ArrayUtility;
26
27
/**
28
 * If a definition error is found, the whole TCA is modified for entity
29
 * notifications; instead of normal fields, an error message is shown.
30
 */
31
class DefinitionError implements FormDataProviderInterface
32
{
33
    /**
34
     * @var DefinitionService
35
     */
36
    private $definitionService;
37
38
    /**
39
     * @var ViewService
40
     */
41
    private $viewService;
42
43
    /**
44
     * Manual dependency injection.
45
     */
46
    public function __construct()
47
    {
48
        $this->definitionService = Container::get(DefinitionService::class);
49
        $this->viewService = Container::get(ViewService::class);
50
    }
51
52
    /**
53
     * @param array $result
54
     * @return array
55
     */
56
    public function addData(array $result): array
57
    {
58
        $tableName = $result['tableName'];
59
60
        if (!isset($GLOBALS['TCA'][$tableName]['ctrl'][EntityTcaWriter::NOTIFICATION_ENTITY])) {
61
            return $result;
62
        }
63
64
        if ($this->definitionService->getValidationResult()->hasErrors()) {
65
            ArrayUtility::mergeRecursiveWithOverrule($GLOBALS['TCA'][$tableName], $this->getDefinitionErrorTca());
66
        }
67
68
        return $result;
69
    }
70
71
    /**
72
     * @return array
73
     */
74
    private function getDefinitionErrorTca(): array
75
    {
76
        return [
77
            'types' => [
78
                '0' => [
79
                    'showitem' => 'definition_error_message',
80
                ],
81
            ],
82
            'columns' => [
83
                'definition_error_message' => [
84
                    'config' => [
85
                        'type' => 'user',
86
                        'userFunc' => self::class . '->getDefinitionErrorMessage',
87
                    ],
88
                ],
89
            ],
90
        ];
91
    }
92
93
    /**
94
     * @return string
95
     */
96
    public function getDefinitionErrorMessage(): string
97
    {
98
        $view = $this->viewService->getStandaloneView('Backend/TCA/DefinitionErrorMessage');
99
100
        $view->assign('result', $this->definitionService->getValidationResult());
101
102
        return $view->render();
103
    }
104
}
105