Problem/Motivation
When one image is used in two nodes, the files management page (admin/content/files) shows as expected "Used in 2 places". However the file usage detail view (admin/content/files/usage/[fid]) shows four lines.
Steps to reproduce
Here is some code to reproduce the issue (if you use the same file in 2 nodes, you will have 4 rows on the file usage page; if you use the same file in 3 nodes, you will have 9 rows on the file usage page; if you use the same file in 4 nodes, you will have 16 rows on the file usage page, etc.):
$file = \Drupal\file\Entity\File::create([
'uri' => 'public://test.png',
]);
$file->save();
$node = \Drupal\node\Entity\Node::create([
'type' => 'article',
'title' => 'Test 1',
'field_image' => ['target_id' => $file->id()],
]);
$node->save();
$node = \Drupal\node\Entity\Node::create([
'type' => 'article',
'title' => 'Test 2',
'field_image' => ['target_id' => $file->id()],
]);
$node->save();
drupal_flush_all_caches();
Proposed resolution
Add a 'distinct' to the file usage view.
Remaining tasks
- Discuss the solution
- Make a patch
- Review the patch
h3 id="summary-ui-changes">User interface changes
None. Using a different default configuration value.
API changes
none
Data model changes
none
Comment | File | Size | Author |
---|---|---|---|
#4 | core-views-file-usage-2560937-2.patch | 843 bytes | Sutharsan |
Comments
Comment #2
Sutharsan CreditAttribution: Sutharsan as a volunteer commentedThis patch adds the proposed 'distinct' to the view.
Comment #3
dawehnerA bug should be fixed against 8.0.x, shouldn't it?
Comment #4
Sutharsan CreditAttribution: Sutharsan as a volunteer commentedIgnore the #1 patch. This patch has the distinct applied to the right view.
Comment #15
jb044We see the same behaviour in Drupal 8 (8.9.13) when files are used in multiple entities, the probleem seems to be the double JOIN in the views query:
Comment #16
jb044We see the same behaviour in Drupal 8 (8.9.13) when files are used in multiple entities, the probleem seems to be the double JOIN in the views query:
Comment #19
darvanenThis came up as the Bug Smash Initiative target of the day.
I'm unsure how to replicate this issue on a fresh standard install as the file and image field widgets don't allow for re-use. Are you using media library or similar here? Please provide steps to reproduce.
Comment #20
darvanenThank you for reporting and working on this bug. We rely on issue reports like this one to resolve bugs and improve Drupal core.
Since we need more information to move forward with this issue, I am making the status Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.
Comment #21
mfbAdded some reproduce code to the issue summary.
Comment #22
mfbComment #25
quietone CreditAttribution: quietone at PreviousNext commentedI found a duplicate of this problem, #2632372: Repeated file_usages when listing them. It is later but it has more discussion and patches.
I am closing this as a duplicate and moving credit.