Skip to content

Commit b53d684

Browse files
committed
feat: adding link list functionality
1 parent 324cd2e commit b53d684

File tree

6 files changed

+70
-27
lines changed

6 files changed

+70
-27
lines changed

_build/config.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"lowCaseName": "tinymcerte",
44
"description": "TinyMCE 5",
55
"author": "John Peca/Thomas Jakobi",
6-
"version": "3.0.0-beta1",
6+
"version": "3.0.0-beta2",
77
"package": {
88
"elements": {
99
"plugins": [
@@ -23,7 +23,7 @@
2323
"systemSettings": [
2424
{
2525
"key": "plugins",
26-
"value": "advlist autoresize autolink lists charmap preview anchor visualblocks searchreplace code fullscreen insertdatetime media table image quickbars link modxlink modai",
26+
"value": "advlist autoresize autolink lists charmap preview anchor visualblocks searchreplace code fullscreen insertdatetime media table image quickbars modxlink modai",
2727
"area": "tinymcerte.default"
2828
},
2929
{
@@ -126,17 +126,17 @@
126126
},
127127
{
128128
"key": "insert_toolbar",
129-
"value": "image media quicktable modxlink unlink modai_generate",
129+
"value": "image media quicktable modxlink modai_generate",
130130
"area": "tinymcerte.toolbar"
131131
},
132132
{
133133
"key": "selection_toolbar",
134-
"value": "bold italic underline | modxlink unlink | h2 h3 h4 blockquote | modai_generate modai_enhance",
134+
"value": "bold italic underline | modxlink | h2 h3 h4 blockquote | modai_generate modai_enhance",
135135
"area": "tinymcerte.toolbar"
136136
},
137137
{
138138
"key": "toolbar1",
139-
"value": "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | modxlink unlink | image",
139+
"value": "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | modxlink | image",
140140
"area": "tinymcerte.toolbar"
141141
},
142142
{

core/components/tinymcerte/src/Processors/GetTreeProcessor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ private function fillTree(array $nodes, array $resources)
151151
'menu' => array_merge([
152152
[
153153
'title' => '' . $resources[$node]['pagetitle'] . ' (' . $node . ')',
154-
'value' => '[[~' . $node . ']]',
154+
'value' => $node,
155155
'display' => $resources[$node]['pagetitle'],
156156
'classes' => $resources[$node]['classes']
157157
]
@@ -161,7 +161,7 @@ private function fillTree(array $nodes, array $resources)
161161
} else {
162162
$result[] = [
163163
'title' => $resources[$node]['pagetitle'] . ' (' . $node . ')',
164-
'value' => '[[~' . $node . ']]',
164+
'value' => $node,
165165
'display' => $resources[$node]['pagetitle'],
166166
'classes' => $resources[$node]['classes']
167167
];

core/components/tinymcerte/src/Processors/SearchProcessor.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ class SearchProcessor extends modProcessor
2121
public function process()
2222
{
2323
$id = $this->getProperty('id');
24+
$ctx = $this->getProperty('wctx');
2425
$query = $this->getProperty('query');
2526
$limit = $this->getProperty('limit', 10);
27+
$crossContext = (bool) $this->modx->getOption('tinymcerte.links_across_contexts', null, false);
2628
$c = $this->modx->newQuery('modResource');
2729
$c->where([
2830
'deleted' => false,
@@ -37,13 +39,17 @@ public function process()
3739
'id:=' => $id,
3840
]);
3941
}
42+
if (!empty($ctx) && !$crossContext) {
43+
$c->where([
44+
'context_key:=' => $ctx,
45+
]);
46+
}
4047
$c->select('id, concat(pagetitle, " <small>(", context_key, ")</small>") as pagetitle, id as value');
4148
$c->limit($limit);
4249
$results = [];
4350
if ($c->prepare() && $c->stmt->execute()) {
4451
$results = $c->stmt->fetchAll(PDO::FETCH_ASSOC);
4552
}
4653
return $this->outputArray($results);
47-
4854
}
49-
}
55+
}

src/js/Plugins/modxlink/Link.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ export default class Link {
5252

5353
savePage(data) {
5454
if (!data.page_page && !data.page_anchor && !data.page_parameters) return;
55-
5655
const attributes = {
5756
...(Link.getGeneralAttributes(data, 'page')),
5857
'data-link-page': data.page_page
5958
};
59+
if (typeof data.page_url === 'undefined') {
60+
data.page_url = `[[~${data.page_page}]]`
61+
}
6062
attributes.href = data.page_url;
6163

6264
if (data.page_anchor) {

src/js/Plugins/modxlink/modxlink.js

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ export default (editor, url) => {
1010
processor: 'object[]',
1111
default: []
1212
});
13+
14+
editor.options.register('enable_link_list', {
15+
processor: 'boolean',
16+
default: true
17+
});
18+
19+
editor.options.register('link_list', {
20+
processor: 'object[]',
21+
default: []
22+
});
1323
const handleClick = () => {
1424
const dataHelper = new Data(editor);
1525
let currentTab = dataHelper.getActiveTab() ?? 'page';
@@ -37,7 +47,7 @@ export default (editor, url) => {
3747
} else if (item.menu) {
3848
menuItem.items = appendItems(item.menu);
3949
} else {
40-
menuItem.value = item.value;
50+
menuItem.value = item.value.toString();
4151

4252
if (itemCallback) {
4353
itemCallback(menuItem);
@@ -75,7 +85,6 @@ export default (editor, url) => {
7585
items: buildListItems(
7686
editor.options.get('link_class_list'),
7787
function (item) {
78-
7988
if (item.value) {
8089
item.textStyle = function () {
8190
return editor.formatter.getCssText({inline: 'a', classes: [item.value]});
@@ -104,6 +113,25 @@ export default (editor, url) => {
104113
type: 'panel',
105114
items: linkOptions
106115
};
116+
let pageSelector = null;
117+
118+
if (editor.options.get('enable_link_list')) {
119+
pageSelector = {
120+
type: 'listbox',
121+
name: 'page_page',
122+
label: 'Page',
123+
size: formsize,
124+
items: buildListItems(
125+
editor.options.get('link_list')
126+
)
127+
}
128+
} else {
129+
pageSelector = {
130+
id: 'pagecontainer',
131+
type: 'htmlpanel',
132+
html: '<input type="hidden" name="page_page" /><label for="page_url" class="tox-label">Page Title</label><select id="page_url"></select>'
133+
};
134+
}
107135

108136
const tabPanel = {
109137
type: 'tabpanel',
@@ -113,11 +141,7 @@ export default (editor, url) => {
113141
name: 'page',
114142
items: [
115143
linkOptionsPanel,
116-
{
117-
id: 'pagecontainer',
118-
type: 'htmlpanel',
119-
html: '<input type="hidden" name="page_page" /><label for="page_url" class="tox-label">Page Title</label><select id="page_url"></select>'
120-
},
144+
pageSelector,
121145
{
122146
type: 'input',
123147
label: 'Anchor Tag',
@@ -271,7 +295,14 @@ export default (editor, url) => {
271295
},
272296
onSubmit: (api) => {
273297
const link = new Link(editor);
274-
link.save(currentTab, {...api.getData(), ...choicesData});
298+
let data = api.getData();
299+
if (!editor.options.get('enable_link_list')) {
300+
data = {
301+
...data,
302+
...choicesData,
303+
};
304+
}
305+
link.save(currentTab, data);
275306
api.close();
276307
},
277308
onAction: (api, details) => {
@@ -299,7 +330,7 @@ export default (editor, url) => {
299330

300331
const toKeep = [];
301332
options.forEach(option => {
302-
if (toRemove.value !== option.value) {
333+
if (typeof toRemove === 'undefined' || toRemove.value !== option.value) {
303334
toKeep.push(option);
304335
}
305336
});
@@ -357,6 +388,18 @@ export default (editor, url) => {
357388
stateSelector: 'a[href]'
358389
});
359390

391+
const buildLinkList = () => {
392+
const linklistUrl = TinyMCERTE.editorConfig.connector_url + '?action=mgr/resource/gettree' + (MODx.ctx ? ('&wctx=' + MODx.ctx) : '') + '&HTTP_MODAUTH=' + MODx.siteId;
393+
if (editor.options.get('enable_link_list')) {
394+
fetch(linklistUrl).then(function (response) {
395+
return response.json();
396+
}).then(function (data) {
397+
editor.options.set('link_list', data.results || []);
398+
});
399+
}
400+
}
401+
buildLinkList();
402+
360403
return {
361404
getMetadata: function () {
362405
return {

src/js/modx/TinyMCE.ext.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,6 @@ Ext.extend(TinyMCERTE.Tiny, Ext.Component, {
6262
}
6363
});
6464
},
65-
linkList: function (success) {
66-
var linklistUrl = TinyMCERTE.editorConfig.connector_url + '?action=mgr/resource/gettree' + (MODx.ctx ? ('&wctx=' + MODx.ctx) : '') + '&HTTP_MODAUTH=' + MODx.siteId;
67-
fetch(linklistUrl).then(function (response) {
68-
return response.json();
69-
}).then(function (data) {
70-
return success(data.results || []);
71-
});
72-
},
7365
registerDrop: function () {
7466
var editor = this.editor;
7567
var fakeDiv = null;

0 commit comments

Comments
 (0)