Problem/Motivation
If an image widget's file has no size returned from $file->getSize(), a fatal error occurs, causing a "white screen of death".
Steps to reproduce
Proposed resolution
In Drupal core, they added an IF statement to only show the file size span if the size exists. See #3117430: file-link template should not always display file_size. Bartik should do the same in bartik_preprocess_image_widget()
function bartik_preprocess_image_widget(&$variables) {
if (!empty($variables['element']['fids']['#value'])) {
$file = reset($variables['element']['#files']);
if ($size = $file->getSize()) {
$variables['data']["file_{$file->id()}"]['filename']['#suffix'] = ' <span class="file-size">(' . ByteSizeMarkup::create($size) . ')</span> ';
}
}
}
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork bartik-3575247
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
Comment #2
solideogloria commentedComment #3
solideogloria commentedComment #4
solideogloria commentedComment #7
solideogloria commentedLooks good to me.
Comment #8
liam morlandI have adjusted it to allow for zero size.
Comment #9
solideogloria commentedNice. I didn't think of that.
Comment #11
liam morlandThanks!