-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathEditorNoneProvider.php
More file actions
139 lines (120 loc) · 3.84 KB
/
EditorNoneProvider.php
File metadata and controls
139 lines (120 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2024 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Plugin\Editors\None\Provider;
use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\CMS\Editor\AbstractEditorProvider;
use Joomla\Event\DispatcherInterface;
use Joomla\Registry\Registry;
/**
* Editor provider class
*
* @since 5.2.0
*/
final class EditorNoneProvider extends AbstractEditorProvider
{
/**
* A Registry object holding the parameters for the plugin
*
* @var Registry
* @since 5.2.0
*/
protected $params;
/**
* The application object
*
* @var CMSApplicationInterface
*
* @since 5.2.0
*/
protected $application;
/**
* Class constructor
*
* @param Registry $params
* @param CMSApplicationInterface $application
* @param DispatcherInterface $dispatcher
*
* @since 5.2.0
*/
public function __construct(Registry $params, CMSApplicationInterface $application, DispatcherInterface $dispatcher)
{
$this->params = $params;
$this->application = $application;
$this->setDispatcher($dispatcher);
}
/**
* Return Editor name, CMD string.
*
* @return string
* @since 5.2.0
*/
public function getName(): string
{
return 'none';
}
/**
* Gets the editor HTML markup
*
* @param string $name Input name.
* @param string $content The content of the field.
* @param array $attributes Associative array of editor attributes.
* @param array $params Associative array of editor parameters.
*
* @return string The HTML markup of the editor
*
* @since 5.2.0
*/
public function display(string $name, string $content = '', array $attributes = [], array $params = []): string
{
$col = $attributes['col'] ?? '';
$row = $attributes['row'] ?? '';
$width = $attributes['width'] ?? '';
$height = $attributes['height'] ?? '';
$id = $attributes['id'] ?? '';
$buttons = $params['buttons'] ?? true;
$asset = $params['asset'] ?? 0;
$author = $params['author'] ?? 0;
$readonly = !empty($params['readonly']) ? ' readonly disabled' : '';
if (!$width && !$col) {
$width = '100%';
}
if (!$height && !$row) {
$height = '500px';
}
if (!$id) {
$id = $name;
}
// Only add "px" to width and height if they are not given as a percentage
if (is_numeric($width)) {
$width .= 'px';
}
if (is_numeric($height)) {
$height .= 'px';
}
/** @var \Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = $this->application->getDocument()->getWebAssetManager();
// Add assets
if (!$wa->assetExists('script', 'webcomponent.editor-none')) {
$wa->registerScript(
'webcomponent.editor-none',
'plg_editors_none/joomla-editor-none.min.js',
[],
['type' => 'module'],
['editors']
);
}
$wa->useScript('webcomponent.editor-none');
// Render buttons
$buttonsStr = $this->displayButtons($buttons, ['asset' => $asset, 'author' => $author, 'editorId' => $id]);
return '<joomla-editor-none>'
. '<textarea name="' . $name . '" id="' . $id . '" cols="' . $col . '" rows="' . $row
. '" style="width: ' . $width . '; height: ' . $height . ';"' . $readonly . '>' . $content . '</textarea>'
. $buttonsStr
. '</joomla-editor-none>';
}
}