FILE_EXISTS_REPLACE and file_prepare_directory() is removed from Drupal 10 must be replaced

Created on 13 June 2023, over 1 year ago
Updated 8 August 2023, over 1 year ago

Problem/Motivation

FILE_EXISTS_REPLACE and file_prepare_directory() have been deprecated in drupal:8.7.0 and removed from drupal:9.0.0.

🐛 Bug report
Status

Closed: works as designed

Version

1.0

Component

Code

Created by

🇮🇳India Harshita mehra

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

Comments & Activities

  • Issue created by @Harshita mehra
  • Status changed to Needs review over 1 year ago
  • 🇮🇳India Harshita mehra

    I have uploaded a patch for the issue.
    Please review.
    Thanks!

  • Status changed to Closed: works as designed over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
     				if (((int) \Drupal::VERSION) < 9) {
    -					if (file_prepare_directory($location, FILE_CREATE_DIRECTORY)) {
    +					if (\Drupal::service('file_system')->prepareDirectory($location, FileSystemInterface::CREATE_DIRECTORY)) {
     						$files = file_unmanaged_copy($droot . '/themes/moksu/content/' . $alias . '.html.twig', $location);
     						$test = rename($droot . '/themes/moksu/templates/' . $alias . '.html.twig', $droot . '/themes/moksu/templates/page--node--' . $node->id() . '.html.twig');
     					}
    

    Since that function is called only with Drupal 8 (See the if (((int) \Drupal::VERSION) < 9) { control statement that wraps those lines) that is fine.
    Since the same branch aims to work with Drupal 8 and Drupal 9, that is the only possibility.

Production build 0.71.5 2024