Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions _config.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
<?php
use SilverStripe\Core\Manifest\ModuleLoader;
use SilverStripe\Forms\HTMLEditor\HtmlEditorConfig;
use SilverStripe\Forms\HTMLEditor\HTMLEditorConfig;
use SilverStripe\View\Parsers\ShortcodeParser;
use SilverStripe\TinyMCE\TinyMCEConfig;

HtmlEditorConfig::get('cms')->enablePlugins([
'sslinkdataobject' => ModuleLoader::getModule('flxlabs/silverstripe-dataobject-links')
->getResource('client/dist/js/TinyMCE_sslink-dataobject.js')
]);
// Register TinyMCE plugin
call_user_func(function () {
$editorConfig = HTMLEditorConfig::get('cms');

if (!$editorConfig instanceof TinyMCEConfig) {
return;
}

$editorConfig->enablePlugins([
'sslinkdataobject' => ModuleLoader::getModule('flxlabs/silverstripe-dataobject-links')
->getResource('client/dist/js/TinyMCE_sslink-dataobject.js')
]);
});

/**
* Register handler for our shortcodes
Expand Down
2 changes: 2 additions & 0 deletions _config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ SilverStripe\Admin\LeftAndMain:
- FLXLabs\DataObjectLink\DataObjectLinkExtension

SilverStripe\Admin\ModalController:
link_modal_form_factories:
EditorDataObjectLink: FLXLabs\DataObjectLink\DataObjectLinkFormFactory
extensions:
- FLXLabs\DataObjectLink\DataObjectLinkModalExtension
Binary file added client/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion client/dist/js/TinyMCE_sslink-dataobject.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/dist/js/sslink-dataobject-transforms.js

Large diffs are not rendered by default.

64 changes: 38 additions & 26 deletions client/src/TinyMCE_sslink-dataobject.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,27 @@ import i18n from 'i18n';
import TinyMCEActionRegistrar from 'lib/TinyMCEActionRegistrar';
import React from 'react';
import ReactDOM from 'react-dom';
import { ApolloProvider } from '@apollo/client';
import { Provider } from 'react-redux';
import { createRoot } from 'react-dom/client';
//import { ApolloProvider } from '@apollo/client';
//import { Provider } from 'react-redux';
import jQuery from 'jquery';
import ShortcodeSerialiser from 'lib/ShortcodeSerialiser';
import { createInsertLinkModal } from 'containers/InsertLinkModal/InsertLinkModal';
import { provideInjector } from 'lib/Injector';
import { loadComponent } from 'lib/Injector';

const commandName = 'sslinkdataobject';

// Link to a dataobject
TinyMCEActionRegistrar.addAction('sslink', {
text: i18n._t('CMS.LINKLABEL_PAGE', 'Link to an Object'),
onclick: (editor) => editor.execCommand(commandName),
priority: 53,
}).addCommandWithUrlTest(commandName, /^\[dataobject_link.+]$/);


const plugin = {
init(editor) {
// Link to a dataobject
TinyMCEActionRegistrar.addAction('sslink', {
text: i18n._t('CMS.LINKLABEL_PAGE', 'Link to an Object'),
onclick: (editorInst) => editorInst.execCommand(commandName),
priority: 53,
}).addCommandWithUrlTest(commandName, /^\[dataobject_link.+]$/);

editor.addCommand(commandName, () => {
const field = jQuery(`#${editor.id}`).entwine('ss');

Expand All @@ -30,21 +33,20 @@ const plugin = {
};

const modalId = 'insert-link__dialog-wrapper--dataobject';
const sectionConfigKey = 'SilverStripe\\CMS\\Controllers\\CMSPageEditController';
const formName = 'editorDataObjectLink';
const InsertLinkDataObjectModal = provideInjector(createInsertLinkModal(sectionConfigKey, formName));
//const sectionConfigKey = 'SilverStripe\\CMS\\Controllers\\CMSPageEditController';
const sectionConfigKey = 'SilverStripe\\Admin\\LeftAndMain';
const formName = 'EditorDataObjectLink';
const InsertLinkDataObjectModal = loadComponent(createInsertLinkModal(sectionConfigKey, formName));

jQuery.entwine('ss', ($) => {
$('textarea.htmleditor').entwine({
openLinkDataObjectDialog() {
let dialog = $(`#${modalId}`);

if (!dialog.length) {
dialog = $(`<div id="${modalId}" />`);
$('body').append(dialog);
}
dialog.addClass('insert-link__dialog-wrapper');

dialog.setElement(this);
dialog.open();
},
Expand All @@ -63,15 +65,29 @@ jQuery.entwine('ss', ($) => {
const attrs = this.getOriginalAttributes();
const requireLinkText = this.getRequireLinkText();

// create/update the react component
let root = this.getReactRoot();
if (root) {
// Previous root is still present. Unmount it.
root.unmount();
this.setReactRoot(null);
if (!root) {
root = createRoot(this[0]);
this.setReactRoot(root);
}
root = ReactDOM.createRoot(this[0]);
// create/update the react component
root.render(
<InsertLinkDataObjectModal
show={isOpen}
isOpen={isOpen}
onInsert={handleInsert}
onHide={handleHide}
onClosed={handleHide}
title={i18n._t('CMS.LINK_PAGE', 'Link to a DataObject')}
bodyClassName="modal__dialog"
className={modalId}
fileAttributes={attrs}
identifier="Admin.InsertLinkDataObjectModal"
requireLinkText={requireLinkText}
/>
);
/*root.render(
<ApolloProvider client={client}>
<Provider store={store}>
<InsertLinkDataObjectModal
Expand All @@ -89,8 +105,7 @@ jQuery.entwine('ss', ($) => {
/>
</Provider>
</ApolloProvider>,
);
this.setReactRoot(root);
);*/
},

/**
Expand All @@ -103,7 +118,6 @@ jQuery.entwine('ss', ($) => {
const selectionContent = selection.getContent() || '';
const tagName = selection.getNode().tagName;
const requireLinkText = tagName !== 'A' && selectionContent.trim() === '';

return requireLinkText;
},

Expand All @@ -130,13 +144,12 @@ jQuery.entwine('ss', ($) => {
getOriginalAttributes() {
const editor = this.getElement().getEditor();
const node = $(editor.getSelectedNode());

// Get href
const href = node.attr('href') || '';
if (!href || !clazz) {
if (!href) {
return {};
}

// check if page is safe
const shortcode = ShortcodeSerialiser.match('dataobject_link', false, href);
if (!shortcode) {
Expand All @@ -145,7 +158,6 @@ jQuery.entwine('ss', ($) => {

// Parse class ourselves because shortcode parser sucks
const clazz = shortcode.original.match(/clazz=(.*?)\W/)[1];

return {
ClassName: clazz,
ObjectID: shortcode.properties.id ? parseInt(shortcode.properties.id, 10) : 0,
Expand Down
5 changes: 2 additions & 3 deletions client/src/sslink-dataobject-transforms.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Injector from 'lib/Injector';

Injector.transform(
'tinymce-link-dataobject',
(updater) => {
Expand All @@ -13,7 +12,7 @@ Injector.transform(
ss.store.dispatch({
type: '@@redux-form/INITIALIZE',
meta: {
form: 'Admin.InsertLinkDataObjectModal.editorDataObjectLink',
form: 'Admin.InsertLinkDataObjectModal.linkModalForm/EditorDataObjectLink',
keepDirty: false,
keepSubmitSucceeded: true,
},
Expand Down Expand Up @@ -112,4 +111,4 @@ Injector.transform(
{
before: '*',
},
);
);
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
}
],
"require": {
"silverstripe/framework": "^5",
"silverstripe/admin": "^2",
"silverstripe/vendor-plugin": "^2.0"
"silverstripe/framework": "^6",
"silverstripe/admin": "^3.1",
"silverstripe/htmleditor-tinymce": "^1.0"
},
"autoload": {
"psr-4": {
Expand Down
Loading