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.
Currently, the file size is added to file-link used by image_widget via stable_preprocess_image_widget()
.
Adding this markup in a #suffix is not ideal.
function stable_preprocess_image_widget(&$variables) {
if (!empty($variables['element']['fids']['#value'])) {
$file = reset($variables['element']['#files']);
$variables['data']['file_' . $file->id()]['filename']['#suffix'] = ' <span class="file-size">(' . format_size($file->getSize()) . ')</span> ';
}
}
(In the near future Drupal 9 core themes will add their own preprocess_image_widget()
, and there will be @todo's pointing to this issue.)
Unless there's no possible way to do it otherwise, the solution for Claro should not add this markup in a #suffix. If a solution is found that does not use #suffix, this issue can be re-scoped and the solution can be applied to all themes and possibly the core file-link template .
Proposed resolution
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.
If the solution can't be applied to all core themes, create a followup to find a non-#suffix solution and change the @todo items to point to that.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet