Multiple file usage records

Created on 1 September 2015, almost 9 years ago
Updated 1 March 2023, over 1 year ago

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

πŸ› Bug report
Status

Closed: duplicate

Version

9.5

Component
ViewsΒ  β†’

Last updated 36 minutes ago

Created by

πŸ‡³πŸ‡±Netherlands Sutharsan

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024