1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\Modules\Editor;
13
14 use Brickrouge\Document;
15 use Brickrouge\Element;
16
17 18 19 20 21
22 class MultiEditorElement extends Element
23 {
24 const EDITOR_TAGS = '#meditor-tags';
25 const SELECTOR_NAME = '#meditor-selector-name';
26 const NOT_SWAPPABLE = '#meditor-not-wappable';
27
28 static protected function add_assets(Document $document)
29 {
30 parent::add_assets($document);
31
32 $document->css->add('assets/elements.css');
33 $document->js->add('assets/elements.js');
34 }
35
36 protected $editor_id;
37
38 public function __construct($editor, array $attributes)
39 {
40 $this->editor_id = $editor ? $editor : 'rte';
41
42 parent::__construct
43 (
44 'div', $attributes + array
45 (
46 self::SELECTOR_NAME => 'editor',
47
48 'class' => 'editor-wrapper'
49 )
50 );
51 }
52
53 protected function get_editor()
54 {
55 global $core;
56
57 $editor_id = $this->editor_id;
58 $editor = $core->editors[$editor_id];
59 $element = $editor->from
60 (
61 ($this[self::EDITOR_TAGS] ?: array()) + array
62 (
63 Element::REQUIRED => $this[self::REQUIRED],
64 Element::DEFAULT_VALUE => $this[self::DEFAULT_VALUE],
65
66 'name' => $this['name'],
67
68 'value' => $this['value']
69 )
70 );
71
72 if ($element->type == 'textarea')
73 {
74 $rows = $this['rows'];
75
76 if ($rows !== null)
77 {
78 $element['rows'] = $rows;
79 }
80 }
81
82 return $element;
83 }
84
85 86 87 88 89
90 protected function alter_dataset(array $dataset)
91 {
92 $dataset = parent::alter_dataset($dataset);
93
94 $dataset['contents-name'] = $this['name'];
95 $dataset['selector-name'] = $this[self::SELECTOR_NAME];
96
97 return $dataset;
98 }
99
100 101 102 103 104 105 106
107 protected function render_inner_html()
108 {
109 $html = (string) $this->editor;
110 $editor_id = $this->editor_id;
111
112 if ($this[self::NOT_SWAPPABLE])
113 {
114 $html .= new Element
115 (
116 'hidden', array
117 (
118 'name' => $this[self::SELECTOR_NAME],
119 'value' => $editor_id
120 )
121 );
122 }
123 else
124 {
125 $options = (string) new SelectorElement
126 (
127 array
128 (
129 Element::LABEL => 'Editor',
130 Element::LABEL_POSITION => 'before',
131
132 'name' => $this[self::SELECTOR_NAME],
133 'class' => 'editor-selector',
134 'value' => $editor_id
135 )
136 );
137
138 if ($options)
139 {
140 $html .= '<div class="editor-options clearfix"><div style="float: right">' . $options . '</div></div>';
141 }
142 }
143
144 return $html;
145 }
146 }