Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image files added to the "Description" field of taxonomy terms or the "Block content" field in custom blocks do not get a usage count #5016

Open
klonos opened this issue Mar 20, 2021 · 4 comments

Comments

@klonos
Copy link
Member

klonos commented Mar 20, 2021

This issue here is related to #5007

Steps To Reproduce

To reproduce the behavior:

  1. In a vanilla installation of Backdrop, go to admin/content/files and use the "+ Add file" link to upload an image.
  2. After uploading the image successfully, you are redirected to the file listing page, where you notice that the file status is set to "Permanent", and its usage count is 1 👍🏼
  3. Start creating a post node (node/add/post)
  4. Add a title.
  5. Click the "Insert image" button in the WYSIWYG.
  6. Switch to the "Select from library" tab.
  7. Select the image file you uploaded in step 1 -> click "insert"
  8. Save the node.
  9. Head to the file listing page (admin/content/files) -> notice that the image usage count has now increased to 2 👍🏼
  10. Edit the post node you created in steps 3 to 8.
  11. Click the "Select existing file" button in the "Image" field.
  12. Select the image file you uploaded in step 1 -> click "insert"
  13. Save the node.
  14. Head to the file listing page -> notice that the image usage count has now increased to 3 👍🏼
  15. View the post node you created, and scroll to the bottom of the page to add a comment.
  16. In the comment field, click the "Insert image" button in the WYSIWYG.
  17. Switch to the "Select from library" tab.
  18. Select the image file you uploaded in step 1 -> click "insert"
  19. Save the comment.
  20. Head to the file listing page -> notice that the image usage count has now increased to 4 👍🏼
  21. Go to admin/structure/taxonomy/tags/add, to add a taxonomy term in the "Tags" vocabulary.
  22. Add a title for the term.
  23. In the "Description" field of the term, click the "Insert image" button in the WYSIWYG (there is no "Upload" tab in the dialog, but that's a separate issue: Taxonomy terms "Description" field: "The "Insert image" dialog does not provide the option to upload an image #5007 - ignore this)
  24. Select the image file you uploaded in step 1 -> click "insert"
  25. Save the term.
  26. Head to the file listing page -> notice that the image usage count is still 4 👎🏼
  27. Edit the default layout, and add a custom block to the sidebar region.
  28. Click the "Insert image" button in the WYSIWYG of the "Block content" field.
  29. Switch to the "Select from library" tab.
  30. Select the image file you uploaded in step 1 -> click "insert"
  31. Save the block (you may leave the display title of the block blank)
  32. Save the layout.
  33. Head to the file listing page -> notice that the image usage count is still 4 👎🏼

Actual behavior

Image files added to the taxonomy term "Description" field or the "Block content" field in custom blocks do not get a usage count. If you add existing images, their usage count doesn't get incremented.

Expected behavior

Image files added to these fields should get their usage count added/incremented.


** Additional WTF!! 😅 **

Go back and:

  1. Delete the comment you added to the post you created.
  2. Head to the file listing page -> notice that the image usage count has been decreased to 3 👍🏼
  3. Edit the post node, and remove the image from the "Image" field -> save the node.
  4. Head to the file listing page -> notice that the image usage count has been decreased to 2 👍🏼
  5. Edit the post node again, and remove the image from the "Body" field -> save the node.
  6. Head to the file listing page -> notice that the image usage count has been decreased to 1 👍🏼

At this point, novice users that do not know exactly how files and media/file entities work in Drupal/Backdrop, will wonder where that single file usage is coming from. Expected WTF?! (separate issue)

Experienced Backdrop/Drupal users will think that this usage count is coming from the file entity, so they might head there and delete the file.

  1. Head to admin/content/files and use the "Delete" action on the image file.
  2. After deleting the image successfully, you are redirected to the file listing page, where you are told that there are "No files available." ...at this point, you would expect that the site would have ended up with a broken term description, and a broken block. Right?
  3. Head to the term listing for the "Tags" vocabulary (admin/structure/taxonomy/tags).
  4. Click the link to view the term you have added earlier -> both the image in the term description, as well as in the custom block you added in the sidebar are there!!:

@klonos klonos changed the title Image files added to the "Description" field of taxonomy terms or custom blocks do not get a usage count Image files added to the "Description" field of taxonomy terms or the "Block content" field in custom blocks do not get a usage count Mar 20, 2021
@indigoxela
Copy link
Member

@klonos let's try to drill this down a bit.

Re "left over" usage count when a file has been uploaded via "add file" link: That's correct behavior IMO. Ironically the PR was from you. 😉 #4017
The "File" is self-referencing, otherwise it couldn't be used at all.

Re images inserted into custom blocks: This might need some more testing. There's an older issue that claims to have fixed that.
#1373

Re image usage recording in taxonomy term description pseudo fields: that's a real problem and probably the main thing we should fix here. Currently the taxonomy module does not bother at all, but it should as it provides the field.

@klonos
Copy link
Member Author

klonos commented Mar 21, 2021

Re images inserted into custom blocks: This might need some more testing.

You can confirm this easily:

  1. Upload an image file to the site via "+Add file" (file/add)
  2. Confirm that the file is added to admin/content/files as permanent, with usage count 1 👍🏼
  3. Create a custom block, either from a layout, or from admin/structure/block/add.
  4. Add the image you've uploaded in step 1 to the "Block content" field, and save the block.
  5. Go to admin/content/files and see that the image file count is still 1 👎🏼
  6. Click the "Manage" action for the file, and switch to the "Usage" tab -> the custom block is not listed as a place where the file is being used 👎🏼
  7. Delete the managed file, and confirm that there are no files listed in admin/content/files.
  8. Go to admin/structure/block and edit the custom block -> the image is still there in the "Block content field"

So you basically have images added to the custom block content field, that are not added to the managed files, and do not get their usage count incremented/decreased as they are being added/removed to custom blocks.

This is the exact same behavior as with the "Description" field in taxonomy terms.

@indigoxela
Copy link
Member

indigoxela commented Mar 21, 2021

Re blocks: I wonder, why this file_usage_add fails to do the job in this case.

Ah, I do have a suspicion already... Yeah, this probably also has to be done in a cleaner way.

BTW: although both modules show the same (or very similar) behavior, I'm not sure yet, if we should cover both of them (Layout Block and Taxonomy) in the same issue.

@klonos
Copy link
Member Author

klonos commented Mar 21, 2021

although both modules show the same (or very similar) behavior, I'm not sure yet, if we should cover both of them (Layout and Taxonomy) in the same issue.

Agreed, if this turns out to be a completely different fix for these 2 cases, then we should split this. If it is either a fix implemented in a single place, or the same fix applied to two places, then I think that we should fix it in a single PR, in one go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants