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