Use FileRepositoryInterface in \Drupal\file\Upload\FileUploadHandler::loadByUri

Created on 28 January 2023, over 1 year ago
Updated 9 September 2023, 9 months ago

Problem/Motivation

In 📌 [META] Fix @todo items referencing closed issues Active we discovered that there's a @todo in \Drupal\file\Upload\FileUploadHandler::loadByUri which references a d.o. issue that is already closed; #3223209: deprecate file_save_data, file_copy and file_move and replace with a service

Here's the @todo:

  /**
   * Loads the first File entity found with the specified URI.
   *
   * @param string $uri
   *   The file URI.
   *
   * @return \Drupal\file\FileInterface|null
   *   The first file with the matched URI if found, NULL otherwise.
   *
   * @todo replace with https://www.drupal.org/project/drupal/issues/3223209
   */
  protected function loadByUri(string $uri): ?FileInterface {

Steps to reproduce

Proposed resolution

The current code in \Drupal\file\Upload\FileUploadHandler::loadByUri is almost similar to code that was changed here.

Let's apply the same changes to \Drupal\file\Upload\FileUploadHandler::loadByUri to keep consistent.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

📌 Task
Status

Fixed

Version

10.1

Component
File module 

Last updated 3 days ago

Created by

🇳🇱Netherlands Spokje

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

Comments & Activities

  • Issue created by @Spokje
  • @spokje opened merge request.
  • Status changed to Needs review over 1 year ago
  • Status changed to RTBC over 1 year ago
  • 🇺🇸United States smustgrave

    Change looks good and doesn't cause any issues so seems like a valid cleanup/update.

  • Status changed to Needs work over 1 year ago
  • 🇬🇧United Kingdom alexpott 🇪🇺🌍

    Added review to MR - we need to use dependency injection here.

  • First commit to issue fork.
  • Status changed to Needs review over 1 year ago
  • Status changed to Needs work over 1 year ago
  • 🇺🇸United States smustgrave

    Now that the service has a new parameter it will need a change record.

    Also new parameter should default to NULL and throw a trigger_error

  • 🇧🇷Brazil paulocs Belo Horizonte

    don't we need to deprecate it first?

  • 🇺🇸United States smustgrave

    So this is adding a parameter so would need something like

          @trigger_error('Calling ' . __CLASS__ . '::__construct() with the $migration argument is deprecated in drupal:10.1.0 and is removed in drupal:11.0.0. See https://www.drupal.org/node/3323212', E_USER_DEPRECATED);
    

    With the URL being to the change record created here.

    Then the test is maybe a Kernel test that shows you get that trigger_error when passing nothing in that last parameter spot.

  • @paulocs opened merge request.
  • Status changed to Needs review over 1 year ago
  • 🇧🇷Brazil paulocs Belo Horizonte

    Oh yes. I have read 'thrown error' instead of 'trigger_error' :)

    I have created the deprecation notice. I have also created a new branch and MR as I can not change the target branch of MR !3316.

  • Status changed to RTBC over 1 year ago
  • 🇺🇸United States smustgrave

    Looks good!

    • catch committed 283d9be7 on 10.1.x
      Issue #3337162 by Spokje, paulocs, _pratik_, smustgrave, alexpott: Use...
  • Status changed to Fixed about 1 year ago
  • 🇬🇧United Kingdom catch

    Made this change on commit, otherwise looks great.

    diff --git a/core/modules/file/src/Upload/FileUploadHandler.php b/core/modules/file/src/Upload/FileUploadHandler.php
    index a79e757c67..ac997bcefa 100644
    --- a/core/modules/file/src/Upload/FileUploadHandler.php
    +++ b/core/modules/file/src/Upload/FileUploadHandler.php
    @@ -120,7 +120,7 @@ public function __construct(FileSystemInterface $fileSystem, EntityTypeManagerIn
         $this->currentUser = $currentUser;
         $this->requestStack = $requestStack;
         if ($fileRepository === NULL) {
    -      @trigger_error('Calling ' . __METHOD__ . ' without the $fileRepository argument is deprecated in drupal:10.1.5 and will be required in drupal:11.0.0. See https://www.drupal.org/node/3346839', E_USER_DEPRECATED);
    +      @trigger_error('Calling ' . __METHOD__ . ' without the $fileRepository argument is deprecated in drupal:10.1.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/3346839', E_USER_DEPRECATED);
           $fileRepository = \Drupal::service('file.repository');
         }
         $this->fileRepository = $fileRepository;
    

    Committed 283d9be and pushed to 10.1.x. Thanks!

    • catch committed 64d0d7e8 on 10.1.x
      Issue #3337162 by Spokje, _pratik_, paulocs, smustgrave, alexpott: Use...
  • Automatically closed - issue fixed for 2 weeks with no activity.

  • Status changed to Fixed 9 months ago
  • 🇳🇿New Zealand quietone New Zealand

    Published the CR

Production build 0.69.0 2024