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

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

solideogloria created an issue. See original summary.

solideogloria’s picture

Issue summary: View changes
solideogloria’s picture

Issue summary: View changes
solideogloria’s picture

Status: Active » Needs review

liam morland made their first commit to this issue’s fork.

solideogloria’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.

liam morland’s picture

Status: Reviewed & tested by the community » Needs review

I have adjusted it to allow for zero size.

solideogloria’s picture

Status: Needs review » Reviewed & tested by the community

Nice. I didn't think of that.

liam morland’s picture

Status: Reviewed & tested by the community » Fixed

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.

Status: Fixed » Closed (fixed)

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