Call to a member function isEmpty() on null in filefield_path.module function filefield_paths_file_presave

Created on 6 February 2023, over 2 years ago

Problem/Motivation

If you import data using:

    $file_data = file_get_contents($url);
    $file_repository = \Drupal::service('file.repository');
    $file = $file_repository
      ->writeData($file_data,
                  "public:/{$urlPath}",
                  FileSystemInterface::EXISTS_REPLACE);
  }

You will get the following error on the writeData method call:

Error: Call to a member function isEmpty() on null in /app/docroot/modules/contrib/filefield_paths/filefield_paths.module on line 364 #0 [internal function]: filefield_paths_file_presave(Object(Drupal\file\Entity\File))

Steps to reproduce

Use the above code to try to import a file.

Proposed resolution

The presave function should handle cases where the originname parameter does not exist.

Remaining tasks

Create a patch

User interface changes

None

API changes

None

Data model changes

None

πŸ› Bug report
Status

Active

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States cgmonroe

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024