Error when uploading a remote video

Created on 18 July 2023, over 1 year ago
Updated 3 January 2024, over 1 year ago

Problem

Error: Call to a member function getChangedTime() on bool in Drupal\static_asset_cache_buster\Entity\ImageStyle->buildUrl() (line 29 of /code/web/modules/contrib/static_asset_cache_buster/src/Entity/ImageStyle.php)

Steps to reproduce

1. Go to Admin > Content > Media
2. Add a new remote video (eg. YouTube link)

πŸ› Bug report
Status

Postponed: needs info

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States cindytwilliams Nashville, TN

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @cindytwilliams
  • First commit to issue fork.
  • Status changed to Postponed: needs info over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States Chris Burge

    @cindytwilliams, can you double check the steps to reproduce? When I add a YouTube video, the media entity is created without error.

    Here's the code in question:

      /**
       * {@inheritdoc}
       *
       * Add timestamp query parameter to derivative images.
       */
      public function buildUrl($path, $clean_urls = NULL) {
        $file_url = parent::buildUrl($path, $clean_urls);
    
        // Get the file object from its path.
        /** @var \Drupal\file\FileInterface[] $files */
        $files = \Drupal::entityTypeManager()
          ->getStorage('file')
          ->loadByProperties(['uri' => $path]);
        /** @var \Drupal\file\FileInterface$file */
        $file = reset($files);
    
        $changed = $file->getChangedTime();
        $timestamp_query = _static_asset_cache_buster_get_cache_buster_query($changed);
        $file_url .= (strpos($file_url, '?') !== FALSE ? '&' : '?') . UrlHelper::buildQuery($timestamp_query);
    
        return $file_url;
      }
    

    reset($files) would return FALSE if ->loadByProperties returns an empty array, but that would only happen if the image file doesn't exist in the first place, which shouldn't be possible if code execution has made it this far.

Production build 0.71.5 2024