Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
For example, the Entity Embed module embeds files using the data attributes data-entity-type="file" and data-entity-uuid. It would be nice if we could support Editor's tracking of file usage simply by implementing an alter hook, rather than having to duplicate all the code from editor module.
Comment | File | Size | Author |
---|---|---|---|
#13 | editor-entity_embed_data_attributes-2350327-13.patch | 19.54 KB | PieterDC |
Comments
Comment #1
Dave ReidComment #2
Wim LeersBut then it's no longer just file UUIDs… it's really just "referenced entity UUIDs", right?
Therefore, we might want to rename the
data-editor-file-uuid
attribute todata-entity-uuid
, just like Entity Embed uses, plus adata-entity-type
attribute, also just like Entity Embed uses. Then Editor would only register file usages for file entities. And everything would be using the samedata-
attributes.Comment #3
Dave ReidYeah, I didn't know if we should just add an alter hook, or if we should change Editor to use our data attributes. I think it would better if we have the alter hook, because forcing one standard data attribute could mean we start to have conflicts about who is responsible for rendering. This remains flexible for contrib, so I think this may be the better path forward for now.
Comment #4
Wim LeersBut Entity Embed uses a custom tag, right? So there's no potential for confusion over who should render it?
Comment #5
slashrsm CreditAttribution: slashrsm commentedBoth solutions should work fine. Using standard data- attributes across all systems would probably bring other benefits also (tracking WYSIWYG usage for all entity types?). Could we do both; change data- attributes and expose an alter hook?
Comment #6
Wim LeersMy thoughts exactly!
Yes, except that we only do "file usage" tracking.
Comment #7
Wim LeersThis was discussed at DrupalCon Amsterdam with Dave Reid and Devin Carlson. We agreed that it'd be better to change the
data-
attribute thateditor.module
uses to the same ones as used byentity_embed
, while we still can, before RC.This will greatly enhance consistency during the Drupal 8 lifecycle and hence also improve usability (no more WTFs about why files embedded by
editor.module
aren't treated the same as those embedded byentity_embed.module
).Comment #8
Wim LeersComment #9
PieterDCWim Leers just introduced me to this issue.
I'll have a go and will report when I stop working on this.
Comment #10
PieterDCMade a new patch, based of the conclusion of comment #7.
Replaced data-editor-file-uuid with data-entity-uuid and added data-entity-type.
Also extended the related, already existing automated tests a little bit. They succeed on my local.
Comment #11
Wim LeersWow, awesome work, PieterDC, thank you very much!
I have only nitpicks :)
s/attribute/attributes/
Why not just hardcode this?No, no! Scratch that! What you did is much better! :) What you did, allows contrib modules to have images that come from entities other than file entities! This is even better!
From Dave Reid's writing in the issue summary:
Hence we shouldn't restrict this to only handle files, but it should simply handle any entity type.
In other words: we should indeed require a
data-entity-type
attribute to present, but we shouldn't require them to have the value'file'
.Yes, an extra test case that is now needed to test this new permutations, excellent! :)
Modifying either the
data-entity-type
attribute or thedata-entity-uuid
attribute should be sufficient. And we should test both.E.g. first modify the
data-entity-type
attribute, then the number of usages should decrease to 2. Then modify thedata-entity-uuid
attribute in the older revision, which should further decrease the number of usages to 1.Comment #12
PieterDCComment #13
PieterDCThanks for the thorough review.
Comment #14
Wim LeersThanks, Pieter! :)
Tagging with D8 upgrade path, since this 1) affects existing D8 sites, 2) would require an upgrade path once Drupal 8 officially supports beta-to-beta upgrades. I'm not sure whether this patch should provide an upgrade path or not, so: dear committer, I defer to your judgement in that area.
Comment #15
alexpottWell we need an 8.x to 8.x change record - so people can work out how to upgrade their sites - and know that something has changed.
Comment #16
alexpottwhat would the hook_update_N do?
Comment #17
PieterDCThe hook_update_N would loop over all saved field (?) data in the database and replace all ' data-editor-file-uuid="X"' occurences with ' data-entity-uuid="X" data-entity-type="file"'.
Comment #18
Wim Leers#15: Done: https://www.drupal.org/node/2381651.
#16: #17 is right.
Comment #19
alexpottThis issue addresses a critical bug and is allowed per https://www.drupal.org/core/beta-changes. Committed 3c6f8b8 and pushed to 8.0.x. Thanks!
Correct the spelling mistakes.
Comment #21
yched CreditAttribution: yched commentedLooks like this broke the widget : #2381719: Image CKE widget is lost on submit, plain img instead
Comment #22
Wim LeersActually, looks like we were both bitten by aggressive caching in the browser :)
Comment #23
yched CreditAttribution: yched commentedHm, yeah, looks like weird browser cache behavior, sorry about that.
Looking at the code that got in, though :
Looks weird that upcast does stuff about data-entity-type & data-entity-uuid, but downcast only places the latter ? When would data-entity-type ever be present then ?