Passed
Pull Request — master (#46)
by Romain
04:21
created

TextSlot::getFlexFormConfiguration()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 27
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 11
nc 4
nop 0
dl 0
loc 27
rs 8.439
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
            $flexForm .= '<enableRichtext>1</enableRichtext>';
65
66
            if ($this->rteMode
67
                && !$this->isUsingLegacyRte()
68
            ) {
69
                if (!isset($GLOBALS['TYPO3_CONF_VARS']['RTE']['Presets'][$this->rteMode])) {
70
                    $flexForm = "
71
                        <type>user</type>
72
                        <userFunc>CuyZ\Notiz\Notification\Service\NotificationTcaService->showCKEditorPresetMissing</userFunc>
73
                        <parameters>
74
                            <preset>$this->rteMode</preset>
75
                        </parameters>";
76
                } else {
77
                    $flexForm .= "<richtextConfiguration>$this->rteMode</richtextConfiguration>";
78
                }
79
            }
80
        }
81
82
        return $flexForm;
83
    }
84
85
    /**
86
     * @return string
87
     */
88
    public function getFlexFormAdditionalConfiguration()
89
    {
90
        $flexForm = '';
91
92
        if ($this->rteMode
93
            && $this->isUsingLegacyRte()
94
        ) {
95
            $flexForm .= "<defaultExtras>$this->rteMode</defaultExtras>";
96
        }
97
98
        return $flexForm;
99
    }
100
101
    /**
102
     * @return bool
103
     */
104
    private function isUsingLegacyRte()
105
    {
106
        return ExtensionManagementUtility::isLoaded('rtehtmlarea')
107
            && !ExtensionManagementUtility::isLoaded('rte_ckeditor');
108
    }
109
}
110