Problem/Motivation

Discovered in #3117217: Decouple core theme dependency on functions in stable.theme
Claro's file-link template always displays file_size, but this should not always be displayed
<span{{ attributes }}>{{ link }} <span class="file__size">({{ file_size }})</span></span>

When file-link used by image_widget, file_size should always be displayed, but there are other uses for this template such as by the file_table formatter, which displays file size in a separate column.

The default file-link template in file module already has logic to not add the file size span when the file_size variable is empty. See #3482024: 'file_table' formatter shows file size twice to provide logic for disabling file size when building a file link.

Proposed resolution

Fix Claro's file-link template to not add the file size span when file_size is empty. This ensures that file links will not display empty parentheses.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3117430

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

bnjmnm created an issue. See original summary.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

niranjan_panem’s picture

In drupal 11 claro theme suffix for file-size is not added in preprocess_image_widget. Below is the screen shot of it.
preprocess-image-widget

bnjmnm’s picture

@niranjan_panem that is correct because, as the issue summary states Claro's file-link template always displays file_size

The template is where the issue lies

The preprocess in the issue summary was explaining how other themes addressed this in the past.

dafeder’s picture

What is the argument against wrapping the whole span in a conditional to check if file_size is set? This is how it is handled in the core twig template for file module. There are other contexts when that variable might be empty, and you wouldn't want to show the parentheses if there's nothing between them. Likewise, if you want to hide it you could just unset that variable via preprocess.

avpaderno’s picture

What is the argument against wrapping the whole span in a conditional to check if file_size is set?

There are cases where file_size is already shown in a different place, for example in a different table column. It is not a matter of checking whether file_size is set, but showing the same information twice.

mfb’s picture

I incorporated a fix for this Claro bug in a MR for #3482024: 'file_table' formatter shows file size twice, which resolves the related issue re: file module needing logic to turn off file size display when it's already displayed elsewhere.

mfb’s picture

Status: Active » Needs review

Never mind, moved the fix here in hopes of faster reviews

smustgrave’s picture

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

This one also needs an issue summary updates, IS mentions stable_preprocess_image_widget but we know stable has been removed so is there a different hook causing this?

Find a way to target Claro's file-link templates within image widgets so they display file_size. If this can be achieved without #suffix, apply this to all core themes and remove the preprocess functions with @todo items pointing to this issue.

This is the current proposed solution but the MR appears to be wrapping the template. Hard to tell but comments #10-12 seem to be discussing if this is the approach that should be taken

mfb’s picture

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

I removed the obsolete verbiage.

mfb’s picture

Issue summary: View changes

Template variables don't have a $

avpaderno’s picture

The issue summary says:

When file-link used by image_widget, file_size should always be displayed, but there are other uses for this template such as by the file_table formatter, which displays file size in a separate column.

It does not seem a matter of checking the value of file_size in the template file, but rather to know which formatter is using that template file, or use two different template files.

avpaderno’s picture

(I am interested in this as maintainer of the Seven theme, now removed from Drupal core, and maintained as contributed project.)

mfb’s picture

It does not seem a matter of checking the value of file_size in the template file, but rather to know which formatter is using that template file, or use two different template files.

See the following paragraph of the issue summary - this should be handled by #3482024: 'file_table' formatter shows file size twice (a new size toggle available to formatters or other callers).

smustgrave’s picture

Priority: Major » Normal
Status: Needs review » Needs work
Issue tags: -Needs issue summary update +Needs change record

As a template change will need a CR as contrib themes (like seven) will need to be informed.

mfb’s picture

Status: Needs work » Needs review
Issue tags: -Needs change record

Added a draft CR

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

smustgrave’s picture

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

Believe this one is good to go. Also think change is small enough to not need test coverage

longwave’s picture

Version: main » 10.6.x-dev
Status: Reviewed & tested by the community » Fixed

Backported down to 10.6.x as an eligible bug fix. I'm also not convinced this needed a change record as it's only a bug fix and other themes can make their own decisions independent of this, but we have one so I'll publish it.

Committed and pushed f33a27a30e4 to main and 0cb6f05cbda to 11.x and f50606671d8 to 11.3.x and 5ea9949c2cd to 10.6.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.

  • longwave committed 5ea9949c on 10.6.x
    fix: #3117430 file-link template should not always display file_size
    
    By...

  • longwave committed f5060667 on 11.3.x
    fix: #3117430 file-link template should not always display file_size
    
    By...

  • longwave committed 0cb6f05c on 11.x
    fix: #3117430 file-link template should not always display file_size
    
    By...

  • longwave committed f33a27a3 on main
    fix: #3117430 file-link template should not always display file_size
    
    By...
longwave’s picture

Actually no, I'm hiding the change record, it doesn't add anything useful.

Status: Fixed » Closed (fixed)

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