I am using insert, filefield, and a WYSIWYG to edit the body of a content type. I would like it if selected text in the body WYSIWYG would turn into a link to a file when you select the "insert" button of the file. The closest I can come is having the file name replace the selected text.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

quicksketch’s picture

Status: Active » Closed (won't fix)

Unfortunately this would require per-WYSIWYG integration, which I'm not interested in trying to support. Additionally I'm not sure it's expected behavior. Clicking the "Insert" button inserts, instead of making links or inserting.

attiks’s picture

My clients are needing this as well, particularly for links to pdf files, so I made a first attempt to provide this.

The patch adds a new insert style 'Selection as link' that uses the current selected text as link text, if no text is selected it uses t('Link') as link text.

For the moment only plaintext and tinymce are supported, mainly because i don't really use the others.

@quicksketch: if I (or somenone else) provides the commands for the other wysiwyg editors, are you willing to commit this?

attiks’s picture

Component: User interface » Code
Status: Closed (won't fix) » Needs work
netprince’s picture

attiks,

tried your patch, two things...

1) templates/insert-link-selection.tpl.php is missing, so I copied insert_link.tpl.php to create the file.

2) when I use insert with 'selection as link', it removes my selected text, and no link or filename replaces it.

I'm using D6 with insert 6.x-1.0, tinyMCE 3.3.9 as editor.

attiks’s picture

new patch attached with the missing file, there's a placeholder in the tpl.php file so please try again with this file.

quicksketch’s picture

Hmm, interested to hear what others think but I'm still leaning towards not including this, even if it were possible through WYSIWYG.

attiks’s picture

Nathan,

The problem is that I cannot add this as a separate module (yes, I tried), because the javascript needs changes to be able to support it, and I really don't feel like forking your module just to support it.

I understand that this isn't needed by a lot of people, so lets wait a couple of weeks to see if we can get mort feedback.

dhalbert’s picture

Hmm, interested to hear what others think but I'm still leaning towards not including this, even if it were possible through WYSIWYG.

A belated comment: setting the link but not changing the selected text is the way the link buttons in the WYSIWYG/TinyMCE editor and BUEditor work. I just had an email interchange with one of my editors who expected that and was surprised by the current behavior. (we're using 7.x)

quicksketch’s picture

The problem is that I cannot add this as a separate module (yes, I tried), because the javascript needs changes to be able to support it

As long as your module loads second, you can easily override Drupal.insert.insertIntoActiveEditor to change the JavaScript behavior (then probably call the original callback if it's not a selection). It looks like in your JS modifications, the only change necessary to make this s separate module would be passing in the "style" variable into insertIntoActiveEditor, which I would be happy to do.

But as for including the per-WYSIWYG functionality directly in the module to support selections, it's now been 2.5 years and only 3 people out of 40,000 installations have requested the feature. I don't think it's worth adding considering the technical and maintenance requirements.

Snater’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)

Scanning old tickets while working on the D8 version. On the one hand this would be a nice feature, on the other hand the behaviour just does not seem to fit in as the use-case is very specific even requiring a separate style.

Closing as per most recent comment.