|
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\View\Slot\Application; |
|
19
|
|
|
|
|
20
|
|
|
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; |
|
21
|
|
|
|
|
22
|
|
|
class TextSlot extends Slot |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var bool |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $rte; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* The RTE mode that can be used for: |
|
31
|
|
|
* |
|
32
|
|
|
* - CKEditor: must contain a valid preset that was registered in the global |
|
33
|
|
|
* configuration of the extension. |
|
34
|
|
|
* - RTEHtmlArea: extra configuration for the RTE (field `defaultExtras`). |
|
35
|
|
|
* |
|
36
|
|
|
* @var string |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $rteMode; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param string $name |
|
42
|
|
|
* @param string $label |
|
43
|
|
|
* @param bool $rte |
|
44
|
|
|
* @param string|null $rteMode [PHP 7.1] |
|
45
|
|
|
*/ |
|
46
|
|
|
public function __construct(string $name, string $label, bool $rte, $rteMode) |
|
47
|
|
|
{ |
|
48
|
|
|
parent::__construct($name, $label); |
|
49
|
|
|
|
|
50
|
|
|
$this->rte = $rte; |
|
51
|
|
|
$this->rteMode = $rteMode; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @return string |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getFlexFormConfiguration(): string |
|
58
|
|
|
{ |
|
59
|
|
|
$flexForm = ' |
|
60
|
|
|
<type>text</type> |
|
61
|
|
|
<cols>40</cols> |
|
62
|
|
|
<rows>15</rows>'; |
|
63
|
|
|
|
|
64
|
|
|
if (!$this->rte) { |
|
65
|
|
|
return $flexForm; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
$flexForm .= '<enableRichtext>1</enableRichtext>'; |
|
69
|
|
|
|
|
70
|
|
|
if (!$this->rteMode |
|
71
|
|
|
|| $this->isUsingLegacyRte() |
|
72
|
|
|
) { |
|
73
|
|
|
return $flexForm; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
if (isset($GLOBALS['TYPO3_CONF_VARS']['RTE']['Presets'][$this->rteMode])) { |
|
77
|
|
|
return $flexForm . "<richtextConfiguration>$this->rteMode</richtextConfiguration>"; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/* |
|
81
|
|
|
* If we get to here, the CKEditor preset was not found: we warn the |
|
82
|
|
|
* user about it. |
|
83
|
|
|
*/ |
|
84
|
|
|
return " |
|
85
|
|
|
<type>user</type> |
|
86
|
|
|
<userFunc>CuyZ\Notiz\Core\Notification\TCA\User\MissingCkEditorPreset->process</userFunc> |
|
87
|
|
|
<parameters> |
|
88
|
|
|
<preset>$this->rteMode</preset> |
|
89
|
|
|
</parameters>"; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @return string |
|
94
|
|
|
*/ |
|
95
|
|
|
public function getFlexFormAdditionalConfiguration(): string |
|
96
|
|
|
{ |
|
97
|
|
|
$flexForm = ''; |
|
98
|
|
|
|
|
99
|
|
|
if ($this->rteMode |
|
100
|
|
|
&& $this->isUsingLegacyRte() |
|
101
|
|
|
) { |
|
102
|
|
|
$flexForm .= "<defaultExtras>$this->rteMode</defaultExtras>"; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
return $flexForm; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @return bool |
|
110
|
|
|
*/ |
|
111
|
|
|
private function isUsingLegacyRte(): bool |
|
112
|
|
|
{ |
|
113
|
|
|
return ExtensionManagementUtility::isLoaded('rtehtmlarea') |
|
114
|
|
|
&& !ExtensionManagementUtility::isLoaded('rte_ckeditor'); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|