Problem/Motivation
Image files are tracked using data-entity-uuid and data-entity-type attributes, and those are only assigned when the file entity is saved, which only happens after uploading the image. However if we include an image using the URL text input, the file is not saved neither received values for uuid and type, so it is not tracked, even if that image is in the file system.
Also, not having data-entity-uuid and data-entity-type attributes makes the image unable to be edited using the drupalimage plugin button.
Proposed resolution
Save images added by URL from the file system as entities, assigning uuid and type in order to be tracked and to be able to be edited.
Comment | File | Size | Author |
---|---|---|---|
#28 | 2828048-nr-bot.txt | 1.59 KB | needs-review-queue-bot |
#26 | reroll_diff_21-26.txt | 1.89 KB | pooja saraah |
#26 | 2828048-26.patch | 2.44 KB | pooja saraah |
| |||
#25 | 2828048-nr-bot.txt | 2.03 KB | needs-review-queue-bot |
#21 | allow_tracking_images-2828048-21.patch | 2.46 KB | Nuuou |
Comments
Comment #2
juanolalla CreditAttribution: juanolalla at Lullabot commentedAdding the patch.
Comment #5
joelpittetTestbot failure, resetting status due to https://www.drupal.org/node/2828045
Comment #6
m4oliveiLooking good @juanolalla. Couple nit picks:
src should be surrounded in single quotes.
file_save_data returns either a FileInterface instance or FALSE on error. Change this so the assignment is in the if statement and get rid of the instanceof check
Should probably use $file->getEntityTypeId() instead to be more correct.
Comment #7
juanolalla CreditAttribution: juanolalla at Lullabot commentedThanks for your suggestions! Uploading new patch.
Comment #8
m4oliveiLooking good to me. I've just merged the site we're working on. Not sure if this needs tests or not to reach the bar for core contrib. Also, haven't tested on 8.3.x. Otherwise RTBC for me.
Comment #9
Wim LeersThe raw
src
attribute is designed for just pasting image URLs from anywhere. What you want, is the ability to reuse images. +100000 for that. But this is not the right way to achieve that. The proper way to achieve that would be to have a UI to allow images to be selected, and then once you have a file selected,EditorImageDialog
would indeed set those attributes.And that's really something
'#type' => 'managed_file'
(i.e.\Drupal\file\Element\ManagedFile
) should support, then it'll work automatically inEditorImageDialog
:)Comment #10
juanolalla CreditAttribution: juanolalla at Lullabot commentedSo we have a simple raw src form for pasting URLs, and we might need that images introduced by relative URLs would be managed as file entities. Why we would need a UI for selection to accomplish that?
Please, look at this this way, there could be other contrib modules that provide a UI for selection on top of the single URL raw src form, as you're suggesting. That is what IMCE does, through adding a "Open File Browser" link on that URL field. IMCE allows you to manage your files directory and select one image, but in the end what we have is a raw src returned, because that is what this form was designed to do. Those files won't be registered as entities unless we implement that in EditorImageDialog, as I'm proposing in my patch.
That could be nice, although what I've done for consistency is the same that was already done for uploaded images, see lines 208-217 in EditorImageDialog:
I think changing both uploaded images and relative URL images to use somehow a field type 'manage_file" would be out of the scope of this issue
Comment #11
juanolalla CreditAttribution: juanolalla at Lullabot commentedComment #21
Nuuou CreditAttribution: Nuuou commentedWe've been using patch #7 for pretty much our entire duration of Drupal 8.
Since it's kind of grandfathered in to our setup, we decided to keep it around.
Had to make some modifications for D9 compatibility, as some methods were removed or deprecated.
Comment #25
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #26
pooja saraah CreditAttribution: pooja saraah at Srijan | A Material+ Company for Drupal India Association commentedFixed failed commands on #21
Attached patch against Drupal 10.1.x
Comment #27
nod_Comment #28
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.