Passed
Push — master ( 5e05be...4595aa )
by Romain
03:46
created

TextSlot::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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