TipTapEditorConfig::getConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
namespace LeKoala\FormElements;
4
5
use SilverStripe\i18n\i18nEntityProvider;
6
use SilverStripe\Forms\HTMLEditor\HTMLEditorConfig;
7
8
/**
9
 * Default configuration for HtmlEditor specific to TipTap
10
 */
11
class TipTapEditorConfig extends HTMLEditorConfig implements i18nEntityProvider
12
{
13
    /**
14
     * JS settings
15
     *
16
     * @link https://tiptap.dev/guide/configuration
17
     * @var array
18
     */
19
    protected $settings = [];
20
21
    /**
22
     * Holder list of removed buttons
23
     *
24
     * @var array
25
     */
26
    protected $removeButtons = [];
27
28
    /**
29
     * Holder list of enabled buttons
30
     *
31
     * @var array
32
     */
33
    protected $buttons = [];
34
35
    /**
36
     * @param string $key
37
     * @return mixed
38
     */
39
    public function getOption($key)
40
    {
41
        if (isset($this->settings[$key])) {
42
            return $this->settings[$key];
43
        }
44
        return null;
45
    }
46
47
    /**
48
     * @param string $key
49
     * @param mixed $value
50
     * @return self
51
     */
52
    public function setOption($key, $value)
53
    {
54
        $this->settings[$key] = $value;
55
        return $this;
56
    }
57
58
    /**
59
     * @param array $options
60
     * @return self
61
     */
62
    public function setOptions($options)
63
    {
64
        foreach ($options as $key => $value) {
65
            $this->settings[$key] = $value;
66
        }
67
        return $this;
68
    }
69
70
    /**
71
     * Get all settings
72
     *
73
     * @return array
74
     */
75
    public function getSettings()
76
    {
77
        return $this->settings;
78
    }
79
80
    /**
81
     * @return array
82
     */
83
    public function getAttributes()
84
    {
85
        $attrs = [];
86
        return $attrs;
87
    }
88
89
    /**
90
     * @return array
91
     */
92
    public function getExtraAttributes()
93
    {
94
        $attrs = [];
95
        if (!empty($this->removeButtons)) {
96
            $attrs['data-remove-buttons'] = implode(",", $this->removeButtons);
97
        }
98
        if (!empty($this->buttons)) {
99
            $attrs['data-buttons'] = implode(",", $this->buttons);
100
        }
101
        return $attrs;
102
    }
103
104
    /**
105
     */
106
    protected function getConfig()
107
    {
108
        $settings = $this->getSettings();
109
        return $settings;
110
    }
111
112
    public function init()
113
    {
114
        HTMLEditorConfig::set_active(new static);
115
    }
116
117
    public function getConfigSchemaData()
118
    {
119
        $data = parent::getConfigSchemaData();
120
        return $data;
121
    }
122
123
    public function provideI18nEntities()
124
    {
125
        $entities = [];
126
        return $entities;
127
    }
128
129
    /**
130
     * @param string $key
131
     * @return mixed
132
     */
133
    public function getRemoveButtons()
134
    {
135
        return $this->removeButtons;
136
    }
137
138
    /**
139
     * @param string $key
140
     * @param mixed $value
141
     * @return self
142
     */
143
    public function setRemoveButtons($v)
144
    {
145
        $this->removeButtons = $v;
146
        return $this;
147
    }
148
149
    /**
150
     * @param string $key
151
     * @return mixed
152
     */
153
    public function getButtons()
154
    {
155
        return $this->buttons;
156
    }
157
158
    /**
159
     * @param string $key
160
     * @param mixed $value
161
     * @return self
162
     */
163
    public function setButtons($v)
164
    {
165
        $this->buttons = $v;
166
        return $this;
167
    }
168
}
169