mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 06:05:56 +00:00
ENHANCEMENT Allow insert links with display link text
This commit is contained in:
parent
fc0362087e
commit
417caf2972
2
client/dist/js/TinyMCE_sslink-internal.js
vendored
2
client/dist/js/TinyMCE_sslink-internal.js
vendored
@ -1 +1 @@
|
||||
!function(e){function t(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var n={};t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=18)}([function(e,t){e.exports=jQuery},function(e,t){e.exports=i18n},,,,,,,,function(e,t){e.exports=Injector},function(e,t){e.exports=InsertLinkModal},function(e,t){e.exports=React},function(e,t){e.exports=ReactApollo},function(e,t){e.exports=ReactDom},function(e,t){e.exports=ShortcodeSerialiser},function(e,t){e.exports=TinyMCEActionRegistrar},,,function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(1),i=n.n(r),o=n(15),a=n.n(o),l=n(11),s=n.n(l),c=n(13),u=n.n(c),d=n(12),p=(n.n(d),n(0)),f=n.n(p),g=n(14),k=n.n(g),h=n(10),m=(n.n(h),n(9));n.n(m),a.a.addAction("sslink",{text:i.a._t("CMS.LINKLABEL_PAGE","Page on this site"),onclick:function(e){return e.execCommand("sslinkinternal")}}).addCommandWithUrlTest("sslinkinternal",/^\[sitetree_link/);var _={init:function(e){e.addCommand("sslinkinternal",function(){f()("#"+e.id).entwine("ss").openLinkInternalDialog()})}},x="insert-link__dialog-wrapper--internal",A=n.i(m.provideInjector)(n.i(h.createInsertLinkModal)("SilverStripe\\CMS\\Controllers\\CMSPageEditController","editorInternalLink"));f.a.entwine("ss",function(e){e("textarea.htmleditor").entwine({openLinkInternalDialog:function(){var t=e("#"+x);t.length||(t=e('<div id="'+x+'" />'),e("body").append(t)),t.addClass("insert-link__dialog-wrapper"),t.setElement(this),t.open()}}),e("#"+x).entwine({renderModal:function(e){var t=this,n=ss.store,r=ss.apolloClient,o=function(){return t.close()},a=function(){return t.handleInsert.apply(t,arguments)},l=this.getOriginalAttributes();u.a.render(s.a.createElement(d.ApolloProvider,{store:n,client:r},s.a.createElement(A,{show:e,onInsert:a,onHide:o,title:i.a._t("CMS.LINK_PAGE","Link to a page"),bodyClassName:"modal__dialog",className:"insert-link__dialog-wrapper--internal",fileAttributes:l,identifier:"Admin.InsertLinkInternalModal"})),this[0])},buildAttributes:function(e){return{href:k.a.serialise({name:"sitetree_link",properties:{id:e.PageID}},!0)+(e.Anchor&&e.Anchor.length?"#"+e.Anchor:""),target:e.TargetBlank?"_blank":"",title:e.Description}},getOriginalAttributes:function(){var t=this.getElement().getEditor(),n=e(t.getSelectedNode()),r=(n.attr("href")||"").split("#");if(!r[0])return{};var i=k.a.match("sitetree_link",!1,r[0]);return i?{PageID:i.properties.id?parseInt(i.properties.id,10):0,Anchor:r[1]||"",Description:n.attr("title"),TargetBlank:!!n.attr("target")}:{}}})}),tinymce.PluginManager.add("sslinkinternal",function(e){return _.init(e)}),t.default=_}]);
|
||||
!function(e){function t(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var n={};t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=18)}([function(e,t){e.exports=jQuery},function(e,t){e.exports=i18n},,,,,,,,function(e,t){e.exports=Injector},function(e,t){e.exports=InsertLinkModal},function(e,t){e.exports=React},function(e,t){e.exports=ReactApollo},function(e,t){e.exports=ReactDom},function(e,t){e.exports=ShortcodeSerialiser},function(e,t){e.exports=TinyMCEActionRegistrar},,,function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(1),i=n.n(r),o=n(15),a=n.n(o),l=n(11),s=n.n(l),c=n(13),u=n.n(c),d=n(12),p=(n.n(d),n(0)),f=n.n(p),g=n(14),m=n.n(g),k=n(10),h=(n.n(k),n(9));n.n(h),a.a.addAction("sslink",{text:i.a._t("CMS.LINKLABEL_PAGE","Page on this site"),onclick:function(e){return e.execCommand("sslinkinternal")}}).addCommandWithUrlTest("sslinkinternal",/^\[sitetree_link/);var _={init:function(e){e.addCommand("sslinkinternal",function(){f()("#"+e.id).entwine("ss").openLinkInternalDialog()})}},x="insert-link__dialog-wrapper--internal",A=n.i(h.provideInjector)(n.i(k.createInsertLinkModal)("SilverStripe\\CMS\\Controllers\\CMSPageEditController","editorInternalLink"));f.a.entwine("ss",function(e){e("textarea.htmleditor").entwine({openLinkInternalDialog:function(){var t=e("#"+x);t.length||(t=e('<div id="'+x+'" />'),e("body").append(t)),t.addClass("insert-link__dialog-wrapper"),t.setElement(this),t.open()}}),e("#"+x).entwine({renderModal:function(e){var t=this,n=ss.store,r=ss.apolloClient,o=function(){return t.close()},a=function(){return t.handleInsert.apply(t,arguments)},l=this.getOriginalAttributes(),c=tinymce.activeEditor.selection,p=c.getContent()||"",f=c.getNode().tagName,g="A"!==f&&""===p.trim();u.a.render(s.a.createElement(d.ApolloProvider,{store:n,client:r},s.a.createElement(A,{show:e,onInsert:a,onHide:o,title:i.a._t("CMS.LINK_PAGE","Link to a page"),bodyClassName:"modal__dialog",className:"insert-link__dialog-wrapper--internal",fileAttributes:l,identifier:"Admin.InsertLinkInternalModal",requireLinkText:g})),this[0])},buildAttributes:function(e){return{href:m.a.serialise({name:"sitetree_link",properties:{id:e.PageID}},!0)+(e.Anchor&&e.Anchor.length?"#"+e.Anchor:""),target:e.TargetBlank?"_blank":"",title:e.Description}},getOriginalAttributes:function(){var t=this.getElement().getEditor(),n=e(t.getSelectedNode()),r=(n.attr("href")||"").split("#");if(!r[0])return{};var i=m.a.match("sitetree_link",!1,r[0]);return i?{PageID:i.properties.id?parseInt(i.properties.id,10):0,Anchor:r[1]||"",Description:n.attr("title"),TargetBlank:!!n.attr("target")}:{}}})}),tinymce.PluginManager.add("sslinkinternal",function(e){return _.init(e)}),t.default=_}]);
|
@ -61,6 +61,10 @@ jQuery.entwine('ss', ($) => {
|
||||
const handleHide = () => this.close();
|
||||
const handleInsert = (...args) => this.handleInsert(...args);
|
||||
const attrs = this.getOriginalAttributes();
|
||||
const selection = tinymce.activeEditor.selection;
|
||||
const selectionContent = selection.getContent() || '';
|
||||
const tagName = selection.getNode().tagName;
|
||||
const requireLinkText = tagName !== 'A' && selectionContent.trim() === '';
|
||||
|
||||
// create/update the react component
|
||||
ReactDOM.render(
|
||||
@ -74,6 +78,7 @@ jQuery.entwine('ss', ($) => {
|
||||
className="insert-link__dialog-wrapper--internal"
|
||||
fileAttributes={attrs}
|
||||
identifier="Admin.InsertLinkInternalModal"
|
||||
requireLinkText={requireLinkText}
|
||||
/>
|
||||
</ApolloProvider>,
|
||||
this[0]
|
||||
|
@ -8,6 +8,7 @@ use SilverStripe\Forms\CheckboxField;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\TextField;
|
||||
use SilverStripe\Forms\TreeDropdownField;
|
||||
use SilverStripe\Forms\RequiredFields;
|
||||
|
||||
/**
|
||||
* Provides a form factory for inserting internal page links in a HTML editor
|
||||
@ -35,6 +36,19 @@ class InternalLinkFormFactory extends LinkFormFactory
|
||||
),
|
||||
]);
|
||||
|
||||
if ($context['RequireLinkText']) {
|
||||
$fields->insertAfter('PageID', TextField::create('Text', _t(__CLASS__.'.LINKTEXT', 'Link text')));
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
protected function getValidator($controller, $name, $context)
|
||||
{
|
||||
if ($context['RequireLinkText']) {
|
||||
return RequiredFields::create('Text');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -34,8 +34,12 @@ class InternalLinkModalExtension extends Extension
|
||||
*/
|
||||
public function editorInternalLink()
|
||||
{
|
||||
/** @var InternalLinkFormFactory $factory */
|
||||
$showLinkText = $this->getOwner()->getRequest()->getVar('requireLinkText');
|
||||
$factory = InternalLinkFormFactory::singleton();
|
||||
return $factory->getForm($this->getOwner(), "editorInternalLink");
|
||||
return $factory->getForm(
|
||||
$this->getOwner(),
|
||||
"editorInternalLink",
|
||||
[ 'RequireLinkText' => isset($showLinkText) ]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user