Skip to content

Commit

Permalink
feat: decode current pid of RTE from typo3link routeUrl configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
maikschneider committed Oct 9, 2023
1 parent 7e4376d commit 8638f83
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
16 changes: 15 additions & 1 deletion Resources/Private/TypeScript/IconPicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default class IconPicker extends Core.Plugin {
public init(): void {
// @ts-ignore
const editor = this.editor as EditorWithUI;
const pid = this.guessPid(editor)

this.registerTypo3Icon(editor)

Expand All @@ -20,10 +21,23 @@ export default class IconPicker extends Core.Plugin {
return button;
});

this.picker = new IconSelection(1, '', '')
this.picker = new IconSelection(pid, '', '')
this.picker.initForRteEditor(editor)
}

protected guessPid(editor): number
{
const url = editor.config.get('typo3link')?.routeUrl

if (url) {
const pattern = /(?:\&P\[pid\]\=)\d+/gi;
const decodedUrl = decodeURIComponent(url);
return parseInt(decodedUrl.match(pattern)[0].substring(8));
}

return 0
}

protected registerTypo3Icon(editor): void
{
editor.model.schema.register('typo3icon', {
Expand Down
13 changes: 12 additions & 1 deletion Resources/Public/ECMAScript6/IconPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class IconPicker extends Core.Plugin {
init() {
// @ts-ignore
const editor = this.editor;
const pid = this.guessPid(editor);
this.registerTypo3Icon(editor);
editor.ui.componentFactory.add(IconPicker.pluginName, locale => {
const button = new UI.ButtonView(locale);
Expand All @@ -13,9 +14,19 @@ class IconPicker extends Core.Plugin {
button.on('execute', () => this.picker.rteButtonClick());
return button;
});
this.picker = new IconSelection(1, '', '');
this.picker = new IconSelection(pid, '', '');
this.picker.initForRteEditor(editor);
}
guessPid(editor) {
var _a;
const url = (_a = editor.config.get('typo3link')) === null || _a === void 0 ? void 0 : _a.routeUrl;
if (url) {
const pattern = /(?:\&P\[pid\]\=)\d+/gi;
const decodedUrl = decodeURIComponent(url);
return parseInt(decodedUrl.match(pattern)[0].substring(8));
}
return 0;
}
registerTypo3Icon(editor) {
editor.model.schema.register('typo3icon', {
inheritAllFrom: '$inlineObject',
Expand Down
13 changes: 12 additions & 1 deletion Resources/Public/JavaScript/IconPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ define(['TYPO3/CMS/Ckeditor5Bundle', '@blueways/bw-icons/IconSelection.js'], (fu
init() {
// @ts-ignore
const editor = this.editor;
const pid = this.guessPid(editor);
this.registerTypo3Icon(editor);
editor.ui.componentFactory.add(IconPicker.pluginName, locale => {
const button = new ckeditor5Bundle_js.UI.ButtonView(locale);
Expand All @@ -16,9 +17,19 @@ define(['TYPO3/CMS/Ckeditor5Bundle', '@blueways/bw-icons/IconSelection.js'], (fu
button.on('execute', () => this.picker.rteButtonClick());
return button;
});
this.picker = new IconSelection__default["default"](1, '', '');
this.picker = new IconSelection__default["default"](pid, '', '');
this.picker.initForRteEditor(editor);
}
guessPid(editor) {
var _a;
const url = (_a = editor.config.get('typo3link')) === null || _a === void 0 ? void 0 : _a.routeUrl;
if (url) {
const pattern = /(?:\&P\[pid\]\=)\d+/gi;
const decodedUrl = decodeURIComponent(url);
return parseInt(decodedUrl.match(pattern)[0].substring(8));
}
return 0;
}
registerTypo3Icon(editor) {
editor.model.schema.register('typo3icon', {
inheritAllFrom: '$inlineObject',
Expand Down

0 comments on commit 8638f83

Please sign in to comment.