In #1932652: Add image uploading to WYSIWYGs through editor.module, we added the ability to upload an image directly into CKEditor. While great, this has the side-effect of making it impossible to insert just a raw src attribute into the dialog for inserting an image. There could be lots of reasons for using a raw src instead of uploading an image:
- The user only has the URL to a managed file (e.g. right-clicked on an image and used "Copy image URL")
- The image is a theme-level or manually uploaded asset outside of Drupal.
- The image is hosted on another site (for better or worse).
Long-term, it may be best to fold this into an issue where multiple ways of selecting images are possible: e.g. Upload, URL, Media Browser, etc.
| Comment | File | Size | Author |
|---|---|---|---|
| #55 | interdiff_54-55.txt | 738 bytes | suresh prabhu parkala |
| #55 | 2510394-55.patch | 7.17 KB | suresh prabhu parkala |
| #54 | 2510394-54.patch | 7.17 KB | ravi.shankar |
| #48 | pp_1_allow_entering_2510394-47.patch | 7.19 KB | esod |
| #47 | pp_1_allow_entering_2510394-46.patch | 104.06 KB | esod |
Comments
Comment #1
quicksketchComment #2
wim leersNote that this actually already works, but it's just disabled for editors that image uploads enabled:
So enabling this is mostly a question of usability.
+1!
Comment #3
wim leersComment #4
wim leers#2644640: Pasted images cannot be edited in EditorImageDialog reported this as a bug when pasting images into CKEditor. Which is indeed a straight bug.
My biggest concern: how do we prevent people from just always pasting images, which we do not host, and which could therefore go offline at any time, or even be changed (imagine an innocent math chart being changed for adult content).
Comment #5
Anonymous (not verified) commentedGood point on the concern, I actually voiced this in my internal issue queue for our project since the way Drupal works is how we'd also want images to work in an ideal world (uploading so it is the authority of the image). Content editors, however, may still end up pasting images in. Since the site is no longer the "system of record" for the image, there's always a concern about the image either becoming broken, replaced with something else, etc. I'm not sure there's anything Drupal would/should do in that case... one thought I had was for an optional prompt to come up asking to create the file entry within Drupal if the editor detects an external image being pasted in or manually inserted. It would then upload the file in the background and allow it to be editable with the UI like uploaded images are.
Comment #6
Anonymous (not verified) commentedIn regards to my last post: I had been looking into CKEditor's afterPaste event.
http://ckeditor.com/forums/CKEditor-3.x/Paste-event
Comment #7
wim leersI was thinking the same thing. Or, actually, it could be a setting. By default, any image that is linked is automatically downloaded by Drupal and turned into a Drupal-hosted file. You'd have to change this setting from its default of to to allow hotlinking of images on external sites.
That is closely related to #2560457: Support drag-and-drop image uploads in CKEditor. There, we also need some auto-uploading logic.
Therefore, I propose:
Comment #9
wim leersThis was brought up again in #2702657: The image button of ckeditor can't handle external images.
Comment #10
lucaslg commentedI will try to start something.
Comment #11
wim leersThanks! :)
Comment #12
lucaslg commentedThis is definitely not finished and needs more work but that's where I got until now. People at DrupalDevDaysMilan adviced me to push sooner than later :-)
How it works
If "image upload" is active on the editor config, a radio button is added to select the source type : url or file.
The radio button toggle the display of both field in javascript (see screenshots).
The url field usage is unchanged, it does not download the linked file.
Known issues
- image update: editing an image to use a url instead of a file does not remove the image file and the file field value stay unchanged
- file field:clicking the remove button on the file field reload the form and breaks js and layout
- validation: a check is missing to verify that at least a url or a file are provided
Questions
I also had a few wonders about the implementation :
- should the switch between file and url be on client side or should I use ajax and reload the form from the server ? I find the first one more user friendly ?
- is the javascript at the right place or should it be in it's own file ?
- I had to add extra form elements to surround the file field because the prefix and suffix apparently don't work with managed_files #1865172: Form API : managed_file does not support #prefix and #suffix and I needed classes to hide the input and the associated label
Some tests should probably be added.
Comment #13
lucaslg commentedSame patch as #12, just added and updated a few comments.
Comment #14
wim leersGreat first step!
Client-side for sure. This should use the
#statesAPI.It's in the right place :)
Comment #15
gábor hojtsyComment #16
gábor hojtsyNow using the proper D8 media tag.
Comment #17
lucaslg commentedComment #18
wim leersIt looks like this may be blocked on #2771837: drupalimage CKEditor plugin should not require data-entity-uuid and data-entity-type when image upload is disabled.
Comment #19
lucaslg commentedThe code is now using
#stateAPI.
Managed_file field really have their own way of working. Just like prefix and suffix, state api doesn't seems to work directly on them, even if this issue was closed some time ago #1118016: conditional visibility of a managed_file using #states attribute does not work. I needed an extra container field.
Known issues
- image update: editing an image to use a url instead of a file does not remove the image file and the file field value stay unchanged
-
file field:clicking the remove button on the file field reload the form and breaks js and layoutThere is an extra margin when the form reloads but this is also present in the current 8.2.x branch
-
validation: a check is missing to verify that at least a url or a file are providedComment #21
webchickComment #22
wim leersThis is blocked by #2771837: drupalimage CKEditor plugin should not require data-entity-uuid and data-entity-type when image upload is disabled.
Comment #24
jrockowitz commentedApplying the most recent patch from #2771837: drupalimage CKEditor plugin should not require data-entity-uuid and data-entity-type when image upload is disabled with #19 seems to do the trick. Combined with the IMCE module the image dialog is now exactly what I needed.
@lucaslg Awesome work. You literally made my day better. Thank you.
Comment #25
gifad commented@lucaslg :
A solution would be to mark the radio butons as
disabledfor existing images ?Thanks again !
Comment #26
lucaslg commentedComment #27
lucaslg commentedGood idea Gifad.
It restricts a bit the fonctionnality because you can't change a file to url and vice versa but I can't make my mind if this is a problem or not.
This new patch disables the radio buttons when editing an existing file and fix the last "Known issue".
It also contains adjustments to make it compatible with the last changes from Drupal 8.3.x and 8.4.x.
Known issues
- image update: editing an image to use a url instead of a file does not remove the image file and the file field value stay unchanged- file field:clicking the remove button on the file field reload the form and breaks js and layout
- validation: a check is missing to verify that at least a url or a file are provided
There isan extra margin when the form reloads but this is also present in the current 8.2.x branch
Comment #29
lucaslg commentedI fixed the automated tests :
- changed the file form name because it is now in a container field : fid-container_fid
- changed the verification of the url field in the dialog (it is now always shown even if file upload is active)
- added a check to verify that the new radio buttons are displayed correctly (only if file upload is active)
Comment #30
lucaslg commentedComment #34
lucaslg commentedFinally, a few coding standard corrections.
Comment #37
rang501 commentedRerolled with 8.5.x-dev compatiblity.
Comment #39
rang501 commentedTests should pass now.
Comment #41
esod commentedRerolled the patch for Drupal 8.6.0-rc1. Can't create an interdiff since pp_1_allow_entering-2510394-39.patch no longer applies because
core/modules/editor/src/Tests/EditorUploadImageScaleTest.phphas been moved tocore/modules/editor/tests/src/Functional/EditorUploadImageScaleTest.php.Comment #42
Gaurav Jadaun commentedHello Esod, Please rerolled the patch for drupal 8.6.3
Comment #44
esod commentedReroll for Drupal 8.8.x.
Comment #46
esod commentedReroll the patch for the released Drupal 8.8.x.
Comment #47
esod commentedWhoops. Here's the reroll for the released version of Drupal 8.8.x without the syntax error.
Comment #48
esod commentedAnd one more time. Reroll for Drupal 8.8.x
Comment #53
artusamakSurprisingly, #48 still applies and work on 9.1.9. :)
Thank you!
Comment #54
ravi.shankar commentedAdded reroll of patch #48 on Drupal 9.3.x.
Comment #55
suresh prabhu parkala commentedTried to fix custom commands failures.
Comment #57
skylord commentedThanks a lot! Great patch for migrated sites!
Comment #59
artusamakYou still need to apply this patch https://www.drupal.org/project/drupal/issues/2771837 if you want to be able to edit your remote image afterward.
As is, the insert works great but once you save your content and go to the edit page again, the legend (if you had one) disappears and the image can't be edited anymore.
Comment #63
larowlanAt this point, this feels more like a feature request than a bug
Comment #64
wim leersEditorImageDialogis no more since #3306584: [11.x] Remove EditorLinkDialog, EditorImageDialog and EditorMediaDialog in Drupal 11.But we could make this work for CKEditor 5. See #3222756-15: Allow using images from external source.
In #22 I postponed this on #2771837: drupalimage CKEditor plugin should not require data-entity-uuid and data-entity-type when image upload is disabled. But that same bug fortunately does not exist for CKEditor 5 — we didn't port that bug 😄
Agreed that this is a feature request, not a bug. And it's not major given that >10 years of CKEditor in Drupal has only resulted in 25 followers for this issue.
Comment #65
wim leersBut … is this truly worth doing? "Hotlinking" external images is problematic: the URLs may stop working, and/or the image at that URL might change.
Quoting the original reasons by @quicksketch:
So I'm going to be bold and close this issue. It didn't materialize for nearly a decade. There's been little demand from the community. And since then, we've gained Media Library in core, and a neatly integrated CKEditor 5 media embedding experience. I think the considerations that went into this in 2015 would be very different today, so the relevance of this issue has diminished.
If anybody disagrees: feel free to reopen! 😊
Comment #66
drupaldope commentedComment #67
drupaldope commentedre-opened.
see https://www.drupal.org/project/drupal/issues/3439275#comment-15558438
forcing every single image to be uploaded in media library ? really ?
Comment #69
ehlovader commentedWas this still possible in Drupal 11?
In Drupal 10 the editorImageDialog and other Drupal managed forms were deprecated and are completely removed in D11.
See https://www.drupal.org/project/drupal/issues/3231341
I was wondering if anyone has accomplished a combined Upload and URL interface in a patch.
EDIT: I was able to get this working though, editing the ckeditor5.ckeditor5.yml and CKeditor5plugin/Image.php to add URL to integrations. I think both were required.
Which makes me wonder why the decision was made to only allow one of these? why not allow both?