Skip to content

Commit

Permalink
ENHANCEMENT Allow insert links with display link text
Browse files Browse the repository at this point in the history
  • Loading branch information
phalkunz authored and Damian Mooyman committed Aug 3, 2017
1 parent fc03620 commit 417caf2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion client/dist/js/TinyMCE_sslink-internal.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions client/src/legacy/TinyMCE_sslink-internal.js
Expand Up @@ -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(
Expand All @@ -74,6 +78,7 @@ jQuery.entwine('ss', ($) => {
className="insert-link__dialog-wrapper--internal"
fileAttributes={attrs}
identifier="Admin.InsertLinkInternalModal"
requireLinkText={requireLinkText}
/>
</ApolloProvider>,
this[0]
Expand Down
14 changes: 14 additions & 0 deletions code/Forms/InternalLinkFormFactory.php
Expand Up @@ -8,6 +8,7 @@
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
Expand Down Expand Up @@ -35,6 +36,19 @@ protected function getFormFields($controller, $name, $context)
),
]);

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;
}
}
8 changes: 6 additions & 2 deletions code/Forms/InternalLinkModalExtension.php
Expand Up @@ -34,8 +34,12 @@ public function getOwner()
*/
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) ]
);
}
}

0 comments on commit 417caf2

Please sign in to comment.