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.

Comments

quicksketch’s picture

wim leers’s picture

Note that this actually already works, but it's just disabled for editors that image uploads enabled:

    $form['attributes']['src'] = array(
      '#title' => $this->t('URL'),
      '#type' => 'textfield',
      '#default_value' => isset($image_element['src']) ? $image_element['src'] : '',
      '#maxlength' => 2048,
      '#required' => TRUE,
    );

    // If the editor has image uploads enabled, show a managed_file form item,
    // otherwise show a (file URL) text form item.
    if ($image_upload['status']) {
      $form['attributes']['src']['#access'] = FALSE;
      $form['attributes']['src']['#required'] = FALSE;
    }
    else {
      $form['fid']['#access'] = FALSE;
      $form['fid']['#required'] = FALSE;
    }

So enabling this is mostly a question of usability.


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.

+1!

wim leers’s picture

Version: 8.0.x-dev » 8.1.x-dev
wim leers’s picture

Title: Allow entering raw src attribute when inline image uploading enabled » Allow entering raw src attribute when inline image uploading enabled; and ensure pasted images can still be edited
Category: Feature request » Bug report
Priority: Normal » Major

#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).

Anonymous’s picture

Good 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.

Anonymous’s picture

In regards to my last post: I had been looking into CKEditor's afterPaste event.
http://ckeditor.com/forums/CKEditor-3.x/Paste-event

wim leers’s picture

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.

I 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 autodownload setting from its default of on to off 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:

  1. To keep this issue scoped to external images should be editable and when inserting an image, allow the user to choose to enter an external source
  2. Let #2560457: Support drag-and-drop image uploads in CKEditor take care of both auto-uploading A) dragged-and-dropped images, B) pasted external images.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

wim leers’s picture

lucaslg’s picture

Assigned: Unassigned » lucaslg

I will try to start something.

wim leers’s picture

Thanks! :)

lucaslg’s picture

Assigned: lucaslg » Unassigned
StatusFileSize
new3.72 KB
new11.51 KB
new14.5 KB

This 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.

lucaslg’s picture

StatusFileSize
new4.12 KB
new2 KB

Same patch as #12, just added and updated a few comments.

wim leers’s picture

Great first step!

- 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 ?

Client-side for sure. This should use the #states API.

- is the javascript at the right place or should it be in it's own file ?

It's in the right place :)

gábor hojtsy’s picture

Issue tags: +Media Initiative
gábor hojtsy’s picture

Issue tags: -Media Initiative +D8Media

Now using the proper D8 media tag.

lucaslg’s picture

Assigned: Unassigned » lucaslg
wim leers’s picture

lucaslg’s picture

Assigned: lucaslg » Unassigned
StatusFileSize
new4.52 KB

The code is now using #state API.

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 layout
There 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 provided

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

webchick’s picture

wim leers’s picture

Title: Allow entering raw src attribute when inline image uploading enabled; and ensure pasted images can still be edited » [PP-1] Allow entering raw src attribute when inline image uploading enabled; and ensure pasted images can still be edited

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jrockowitz’s picture

StatusFileSize
new34.65 KB

Applying 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.

gifad’s picture

@lucaslg :

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

A solution would be to mark the radio butons as disabled for existing images ?

Thanks again !

lucaslg’s picture

Assigned: Unassigned » lucaslg
lucaslg’s picture

Assigned: lucaslg » Unassigned
Status: Active » Needs review
Issue tags: +drupaldevdays, +DevDaysSeville
StatusFileSize
new4.72 KB

Good 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

Status: Needs review » Needs work

The last submitted patch, 27: pp_1_allow_entering-2510394-27.patch, failed testing.

lucaslg’s picture

StatusFileSize
new7.07 KB

I 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)

lucaslg’s picture

Status: Needs work » Needs review

The last submitted patch, 13: allow_entering_raw_src-2510394-13.patch, failed testing.

The last submitted patch, 12: allow_entering_raw_src-2510394-12.patch, failed testing.

The last submitted patch, 19: allow_entering_raw_src-2510394-19.patch, failed testing.

lucaslg’s picture

StatusFileSize
new7.06 KB
new2.01 KB

Finally, a few coding standard corrections.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

rang501’s picture

Rerolled with 8.5.x-dev compatiblity.

Status: Needs review » Needs work

The last submitted patch, 37: pp_1_allow_entering-2510394-37.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

rang501’s picture

Status: Needs work » Needs review
StatusFileSize
new7.11 KB
new1.19 KB

Tests should pass now.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

esod’s picture

StatusFileSize
new7.2 KB

Rerolled 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.php has been moved to core/modules/editor/tests/src/Functional/EditorUploadImageScaleTest.php.

Gaurav Jadaun’s picture

Hello Esod, Please rerolled the patch for drupal 8.6.3

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

esod’s picture

StatusFileSize
new7.17 KB

Reroll for Drupal 8.8.x.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

esod’s picture

StatusFileSize
new7.19 KB

Reroll the patch for the released Drupal 8.8.x.

esod’s picture

StatusFileSize
new104.06 KB

Whoops. Here's the reroll for the released version of Drupal 8.8.x without the syntax error.

esod’s picture

StatusFileSize
new7.19 KB

And one more time. Reroll for Drupal 8.8.x

Status: Needs review » Needs work

The last submitted patch, 48: pp_1_allow_entering_2510394-47.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

artusamak’s picture

Surprisingly, #48 still applies and work on 9.1.9. :)
Thank you!

ravi.shankar’s picture

StatusFileSize
new7.17 KB

Added reroll of patch #48 on Drupal 9.3.x.

suresh prabhu parkala’s picture

Status: Needs work » Needs review
StatusFileSize
new7.17 KB
new738 bytes

Tried to fix custom commands failures.

Status: Needs review » Needs work

The last submitted patch, 55: 2510394-55.patch, failed testing. View results

skylord’s picture

Thanks a lot! Great patch for migrated sites!

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

artusamak’s picture

You 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.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

larowlan’s picture

Category: Bug report » Feature request
Issue tags: +Bug Smash Initiative

At this point, this feels more like a feature request than a bug

wim leers’s picture

Title: [PP-1] Allow entering raw src attribute when inline image uploading enabled; and ensure pasted images can still be edited » [drupalImage] Setting to still allow linking to an image by URL even when uploads are enabled
Component: editor.module » ckeditor5.module
Priority: Major » Normal
Issue tags: -Bug Smash Initiative +Needs product manager review
Related issues: +#3306584: [11.x] Remove EditorLinkDialog, EditorImageDialog and EditorMediaDialog in Drupal 11, +#3222756: Allow using images from external source

EditorImageDialog is 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.

wim leers’s picture

Status: Needs work » Closed (outdated)

But … 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:

- 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.

  1. Media + Media Library in core combined with the CKEditor 5 integration have solved that since then
  2. Linking to theme-level assets seems very edge-casey. External assets ("Digital Asset Management" systems or "DAMs") are common but … they are nowadays typically integrated with Drupal's Media Library 🥳
  3. This is the only reason to do this. But then there's security reasons to not do that: it's always safer to download and upload it to this site itself.

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! 😊

drupaldope’s picture

Status: Closed (outdated) » Active
drupaldope’s picture

re-opened.
see https://www.drupal.org/project/drupal/issues/3439275#comment-15558438

forcing every single image to be uploaded in media library ? really ?

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

ehlovader’s picture

Was 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.

diff --git a/core/modules/ckeditor5/ckeditor5.ckeditor5.yml b/core/modules/ckeditor5/ckeditor5.ckeditor5.yml
--- a/core/modules/ckeditor5/ckeditor5.ckeditor5.yml
+++ b/core/modules/ckeditor5/ckeditor5.ckeditor5.yml	(date 1771447225731)
@@ -633,7 +633,6 @@
     label: Image URL
     elements: false
     conditions:
-      imageUploadStatus: false
       plugins: [ckeditor5_image]

 ckeditor5_imageResize:
diff --git a/core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/Image.php b/core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/Image.php
--- a/core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/Image.php
+++ b/core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/Image.php	(date 1771449175090)
@@ -39,6 +39,7 @@
         ],
       ];
       $config['image']['insert']['integrations'][] = 'upload';
+      $config['image']['insert']['integrations'][] = 'url';
     }
     else {
       $config['image']['insert']['integrations'][] = 'url';

Which makes me wonder why the decision was made to only allow one of these? why not allow both?