Problem/Motivation

I have added a file field to an article and set the formater to "Table of files" and now it shows the file size twice.

Steps to reproduce

  1. Add field field to content type
  2. Set formater to "Table of files".
  3. Add some files
  4. Show the content type with table.

a

Proposed resolution

Remove the file size appended to the file name and keep the one in the "Size" column, by introducing a new with_size variable for the file_link preprocess function, which defaults to TRUE; but set it to FALSE when building the file_link in the file_table field formatter.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
2024-10-20_173452.png3.98 KBmarc.bau

Issue fork drupal-3482024

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

marc.bau created an issue. See original summary.

marc.bau’s picture

Defect is in core\modules\file\src\Plugin\Field\FieldFormatter\TableFormatter.php that is using '#theme' => 'file_link'. The file-link.html.twig template adds the file size. I guess this requires a file_link theme suggestion without file size as the file_link template can be used in other situations where this file size makes sense.

marc.bau’s picture

Component: Olivero theme » file.module
cilefen’s picture

Indeed it does.

mfb made their first commit to this issue’s fork.

mfb’s picture

Status: Active » Needs review
Related issues: +#3117430: file-link template should not always display file_size

While fixing this issue w/ file module, it seemed like a good time to also fix a related issue with Claro theme, which, unlike the default file link template, was missing the logic to not show the file size if it's empty.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Probably would be good to keep the claro changes separate to not delay the fix here.

But we should probably have test coverage

mfb’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

Can the proposed solution be cleaned up some as it appears we are adding a new variable key and that's not clear in the IS.

Also why set core/modules/file/src/Plugin/Field/FieldFormatter/TableFormatter.php to FALSE? Only concern is if this could be a breaking change for someones existing site.

mfb’s picture

Issue summary: View changes
Status: Needs work » Needs review

Do we need to add a code comment in TableFormatter where we set #with_size to FALSE?

smustgrave’s picture

Comment always could help

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs issue summary update +Needs Review Queue Initiative

Thanks for adding the comment.

Ran the test-only job here https://git.drupalcode.org/issue/drupal-3482024/-/jobs/6705066

Rest of the changes appear to be inline, was wondering if we add to update any templates docs for the new key 'with_size' but hoping we don't need that.

mfb’s picture

I don't see a need to update the template docs because the with_size variable isn't used there. (It /could/ have been used there, if we moved the logic from the preprocess function into the template, but I didn't put the logic there to minimize the need for updating templates.) I assume templates don't need to exhaustively document all possible variables.

catch’s picture

Version: 11.x-dev » 11.3.x-dev
Status: Reviewed & tested by the community » Fixed

Reviewed this a couple of times and went around in circles on documenting vs not but overall agree with @mfb in #14 - we're not using it in the default template and don't particularly intend anyone else to use it, so documenting could be more confusing than not.

Committed/pushed to 11.x and cherry-picked to 11.3.x, thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • catch committed ddab8760 on 11.3.x
    fix: #3482024 'file_table' formatter shows file size twice
    
    By: @marc....

  • catch committed 687501c3 on 11.x
    fix: #3482024 'file_table' formatter shows file size twice
    
    By: @marc....

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.