So I had a thought about adding links to images when embedding in the WYSIWYG

What if we add a link field to the Media browser's final page where you select the display mode, alignment, Alt Text and Title text that could be a URL. That way while you are finalizing you image you can add the link there and then it could be rendered outright. Then we could in theory add LinkIt to this field if the site has it enabled, or some admin page that would allow them to select either text field or linkit as the option.

Original idea came from this issue Linked images from the Media module in WYSIWYG having A tags stripped when rendered to template

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

emerham created an issue. See original summary.

emerham’s picture

If there is interest in this we will commit time to work on it.

joseph.olstad’s picture

sounds great, improved linkit integration would be super.

emerham’s picture

So I was able to turn media embedded in media_wysiwyg into links but I had to touch file entity in order to have the template write the link HTML. I really wanted to avoid doing this but I was unable to think of another way.

joseph.olstad’s picture

Do you have the patches for file_entity and media? can we have a look?

joseph.olstad’s picture

are you using file_entity 7.x-2.0?

emerham’s picture

I am using file_entity 7.x-2.0 (dev).

I've add both modules patches as well as an image showing the field on the embed form.

I'm still looking into linkit options...

joseph.olstad’s picture

Status: Active » Reviewed & tested by the community

ok, the file_entity patch looks reasonable , I think we can commit that and push a new release with that.
The media patch looks reasonable as well.

Probably commit this in the next few weeks.

Thanks.

emerham’s picture

I appreciate your optimism, but I want to do some security testing on it first, make sure no XSS, try to get linkit in as an option.

The last submitted patch, 7: add_link_field_to_embed_page-12110481-7.patch, failed testing.

joseph.olstad’s picture

Status: Reviewed & tested by the community » Needs work

sounds good, also have to review the test results, one fail.

emerham’s picture

By Modifying the file entity template i'm getting some bad rendering when editing. CKEditor is not rendering the images fully and stopping right after the <a>. I can still rightclick on the media object in the editor and get back into editing the file. When hitting save on the embed model the image is then properly rendered in CKEditor.

I have not had any issues when the page is rendered.

emerham’s picture

got that issues sovled, submitting for testing again

emerham’s picture

Left an alter in patch 13 that I ended up not using. Adding patch without the alter

emerham’s picture

Status: Needs work » Needs review

Changing status to get auto tests running

Status: Needs review » Needs work

The last submitted patch, 14: add_link_field_to_embed_page-2881204-14.patch, failed testing.

joseph.olstad’s picture

In the patch, what is the
//$external_url....
?
Commented out, is this just leftovers?

emerham’s picture

yeah it was left in by accident.

So I just setup my own testing box and ran the tests with my patches and they all pass....

emerham’s picture

Status: Needs work » Needs review
FileSize
4.21 KB

Trying again for tests to pass

joseph.olstad’s picture

so two patches, patch #7 and patch #19 ?

I'll have a closer look over the weekend maybe

emerham’s picture

the file entity patch in 7 and the media patch in 19. If you want I can make a co-issue over in file_entity and post the patch there.

joseph.olstad’s picture

sure please do make a co-issue , and this one as the parent issue. Thanks :)

emerham’s picture

remove file_entity patch from listing here

joseph.olstad’s picture

paste this in any comment block : square bracket open #2883529 square bracket close
and get this:
#2883529: Linking Issues - related to 2881204

joseph.olstad’s picture

Status: Needs review » Reviewed & tested by the community

tested, works great, thanks!

joseph.olstad’s picture

Status: Reviewed & tested by the community » Fixed

requires latest file_entity 7.x-2.x dev build and latest media 7.x-2.x dev or latest 7.x-3.x dev

brockfanning’s picture

I think this is a great idea for a feature, but would it be possible to limit this to the 7.3 branch?

Also it seems like this is intended only for images, but is being applied regardless to all file types. Am I correct about that?

joseph.olstad’s picture

Ya it seems to apply to all file types, it (the option) appears on media_youtube video files, which is probably not desired in that case, but probably doesn't hurt either.

joseph.olstad’s picture

I was about to tag a release for this.

@brockfanning, could you formalize your concerns in the form of a patch?
such as something optional.

I've tested out this functionality, seems to work fine.

joseph.olstad’s picture

Status: Fixed » Needs review

If you want this functionality, it is in file_entity 7.x-2.1 and media 7.x-3.0-beta1

setting this to needs review for 7.x-2.x dev , @brockfanning, can you please review this for us?

joseph.olstad’s picture

@brockfanning, can we deal with your concerns as a new issue?

I made an oops on the 7.x-2.4 release, ended up tagging the wrong branch. Aside from that, I've tested the 7.x-3.x branch , and lots of people are using it without issues, so as the 7.x-3.x functionality and improvements have had some bake time, I think its ready to take it out of the oven and merge into 7.x-2.x.

I'm cutting a release today.

brockfanning’s picture

@joseph.olstad: If it's going into 7.x-2.x, then I'll start a separate issue to make it optional. The reasoning is that I have sites where I've already dealt with the linking problem in a different way, and would not want to suddenly change the workflow (or worse, have 2 different workflows for the some purpose) for all my users. I wouldn't be able to update to a new 7.x-2.x version until this feature became optional, either by a patch or new release.

I think it would also be nice to prevent the option from displaying on non-image file types, though it's not as critical as the above issue. I haven't looked too closely at the code, but it doesn't seem like this should be that hard.

emerham’s picture

@brockfanning If there was a config option to enable this in the admin side would that help with the feature upgrade?

We don't enable embedding of other media types into the WYSIWYG which is why I never thought of testing other media types for the embeder. I did think about setting up a config variable to enable/disable this functionality but thought it would be better if it just was always on..

brockfanning’s picture

@emerham: Yes, the config option is what I would need. In recent history when we've added changes of behavior to Media we've given them config options that default to off (so that sites won't experience any unexpected changes) and then provided a message in a dummy hook_update_N function that alerts site builders that the new functionality is available.

joseph.olstad’s picture

joseph.olstad’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

jds1’s picture

This link field is not working for me. Client reported an issue so I upgraded to the latest versions of Media (7.x-2.8), Media CKEditor (7.x-2.1), and File Entity (7.x-2.2). When I save a node the image is completely stripped out. Don't even see it when inspecting. I've messed with CKEditor settings and other options to no avail. Is anyone else having this issue?

EDIT: not sure why I haven't been able to add a comment but Emerham's suggestions totally worked below. Follow these steps if you're having issues: I needed to change some things around in the Media Browser/Text Format settings. Thank you, Emerham!

emerham’s picture

@if-jds I just created two new d7 sites and I am running the latest tag releases for all media/ckeditor related modules.
My settings are:
Media browser:

  • Full Entity Rendering
  • Allowed types in WYSIWYG
  • Image
  • Vidoe
  • Document
  • Provide alignment option when embedding media
  • Provide the ability to link media to pages

For CKEditor I am using the CDN and version //cdn.ckeditor.com/4.6.2/full-all

Media Plugin is enabled on the CKEditor text profile as well as for the text format.
The first filter on text format is Convert Media tags to markup

I just embedded and created multiple images and links to external/internal pages and my images all showed up.

jds1’s picture

@emerham – this was SUPER-helpful. I needed to tweak some of the Media Browser/Text Format settings and I got it. Client site was not updated to latest versions but I was able to get this working locally and can now proceed.

Thank you!