From 66fe5efdc3a1e5e0cb988f538166181de433cd54 Mon Sep 17 00:00:00 2001 From: Daniel Ziegenberg Date: Fri, 25 Jul 2025 12:03:38 +0200 Subject: [PATCH] MDL-31071 blocks: replace deprecated file_encode_url Signed-off-by: Daniel Ziegenberg --- public/blocks/private_files/renderer.php | 13 ++++++++++++- .../behat/block_private_files_activity.feature | 2 ++ .../tests/behat/block_private_files_course.feature | 2 ++ .../behat/block_private_files_dashboard.feature | 2 ++ .../behat/block_private_files_frontpage.feature | 2 ++ 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/public/blocks/private_files/renderer.php b/public/blocks/private_files/renderer.php index ef6815a000a..83488014f5f 100644 --- a/public/blocks/private_files/renderer.php +++ b/public/blocks/private_files/renderer.php @@ -24,6 +24,9 @@ defined('MOODLE_INTERNAL') || die(); +use core\output\html_writer; +use core\url; + class block_private_files_renderer extends plugin_renderer_base { /** @@ -78,8 +81,16 @@ class block_private_files_renderer extends plugin_renderer_base { } } foreach ($dir['files'] as $file) { - $url = file_encode_url("$CFG->wwwroot/pluginfile.php", '/'.$tree->context->id.'/user/private'.$file->get_filepath().$file->get_filename(), true); $filename = $file->get_filename(); + $url = url::make_pluginfile_url( + contextid: $tree->context->id, + component: 'user', + area: 'private', + itemid: null, + pathname: $file->get_filepath(), + filename: $filename, + forcedownload: true + )->out(); $image = $this->output->pix_icon(file_file_icon($file), ''); $result .= '
  • '.html_writer::link($url, $image.$filename, ['tabindex' => -1]).'
  • '; } diff --git a/public/blocks/private_files/tests/behat/block_private_files_activity.feature b/public/blocks/private_files/tests/behat/block_private_files_activity.feature index f88bb751175..1eb3d6a6452 100644 --- a/public/blocks/private_files/tests/behat/block_private_files_activity.feature +++ b/public/blocks/private_files/tests/behat/block_private_files_activity.feature @@ -26,3 +26,5 @@ Feature: The private files block allows users to store files privately in moodle And I upload "blocks/private_files/tests/fixtures/testfile.txt" file to "Files" filemanager And I press "Save changes" Then I should see "testfile.txt" in the "Private files" "block" + And following "testfile.txt" should download a file that: + | contains text | This is a test file | diff --git a/public/blocks/private_files/tests/behat/block_private_files_course.feature b/public/blocks/private_files/tests/behat/block_private_files_course.feature index 7261d6d55df..bb4fb8005a2 100644 --- a/public/blocks/private_files/tests/behat/block_private_files_course.feature +++ b/public/blocks/private_files/tests/behat/block_private_files_course.feature @@ -24,3 +24,5 @@ Feature: The private files block allows users to store files privately in moodle And I upload "blocks/private_files/tests/fixtures/testfile.txt" file to "Files" filemanager And I press "Save changes" Then I should see "testfile.txt" in the "Private files" "block" + And following "testfile.txt" should download a file that: + | contains text | This is a test file | diff --git a/public/blocks/private_files/tests/behat/block_private_files_dashboard.feature b/public/blocks/private_files/tests/behat/block_private_files_dashboard.feature index 1cb284a9517..45a7fd5f411 100644 --- a/public/blocks/private_files/tests/behat/block_private_files_dashboard.feature +++ b/public/blocks/private_files/tests/behat/block_private_files_dashboard.feature @@ -18,3 +18,5 @@ Feature: The private files block allows users to store files privately in moodle And I upload "blocks/private_files/tests/fixtures/testfile.txt" file to "Files" filemanager And I press "Save changes" Then I should see "testfile.txt" in the "Private files" "block" + And following "testfile.txt" should download a file that: + | contains text | This is a test file | diff --git a/public/blocks/private_files/tests/behat/block_private_files_frontpage.feature b/public/blocks/private_files/tests/behat/block_private_files_frontpage.feature index 93509fd1432..0357f1e35b1 100644 --- a/public/blocks/private_files/tests/behat/block_private_files_frontpage.feature +++ b/public/blocks/private_files/tests/behat/block_private_files_frontpage.feature @@ -30,3 +30,5 @@ Feature: The private files block allows users to store files privately in moodle And I upload "blocks/private_files/tests/fixtures/testfile.txt" file to "Files" filemanager And I press "Save changes" Then I should see "testfile.txt" in the "Private files" "block" + And following "testfile.txt" should download a file that: + | contains text | This is a test file |