Skip to content

Commit

Permalink
Upgrade: Adopt changes from MDL-81960 and use new \core\url class, at…
Browse files Browse the repository at this point in the history
… least in our own / non-adopted code.
  • Loading branch information
abias committed Oct 22, 2024
1 parent 84d95b3 commit fe5b0dd
Show file tree
Hide file tree
Showing 23 changed files with 135 additions and 134 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Changes

### Unreleased

* 2024-10-14 - Upgrade: Adopt changes from MDL-81960 and use new \core\url class, at least in our own / non-adopted code.
* 2024-10-14 - Upgrade: Adopt changes from MDL-81920 and use new \core\lang_string class.
* 2024-10-14 - Upgrade: Adopt changes from MDL-81031 and use new \core\user class.
* 2024-10-14 - Upgrade: Adopt changes from MDL-66903 and use new \core\component class.
Expand Down
6 changes: 3 additions & 3 deletions classes/output/core_renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function favicon() {
$hasflavourfavicon = true;

// Compose the URL to the flavour's favicon.
$flavourfaviconurl = moodle_url::make_pluginfile_url(
$flavourfaviconurl = \core\url::make_pluginfile_url(
context_system::instance()->id,
'theme_boost_union',
'flavours_look_favicon',
Expand Down Expand Up @@ -167,7 +167,7 @@ public function get_logo_url($maxwidth = null, $maxheight = 200) {
$hasflavourlogo = true;

// Compose the URL to the flavour's logo.
$flavourlogourl = core\url::make_pluginfile_url(
$flavourlogourl = \core\url::make_pluginfile_url(
context_system::instance()->id,
'theme_boost_union',
'flavours_look_logo',
Expand Down Expand Up @@ -264,7 +264,7 @@ public function get_compact_logo_url($maxwidth = 300, $maxheight = 300) {
$hasflavourlogo = true;

// Compose the URL to the flavour's compact logo.
$flavourlogourl = core\url::make_pluginfile_url(
$flavourlogourl = \core\url::make_pluginfile_url(
context_system::instance()->id,
'theme_boost_union',
'flavours_look_logocompact',
Expand Down
2 changes: 1 addition & 1 deletion classes/output/navigation/primary.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public function get_user_menu(renderer_base $output): array {
'text' => get_string('setpreferredlanglink', 'theme_boost_union'),
'link' => true,
'isactive' => false,
'url' => new \moodle_url('/user/language.php'),
'url' => new \core\url('/user/language.php'),
];
$sm->items[] = $spfnode;

Expand Down
2 changes: 1 addition & 1 deletion classes/output/tool_policy_renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class tool_policy_renderer extends \tool_policy\output\renderer {
*/
public function header() {
// Check that only the /admin/tool/policy/viewall.php page is affected.
$pageurl = new \moodle_url('/admin/tool/policy/viewall.php');
$pageurl = new \core\url('/admin/tool/policy/viewall.php');
if ($pageurl->compare($this->page->url, URL_MATCH_BASE) == true) {

// If the admin wants to show navigation on the policy page.
Expand Down
8 changes: 4 additions & 4 deletions classes/smartmenu_item.php
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ public function get_itemimage($itemid) {
// Get the first file.
$file = reset($files);

$url = \moodle_url::make_pluginfile_url(
$url = \core\url::make_pluginfile_url(
$file->get_contextid(),
$file->get_component(),
$file->get_filearea(),
Expand Down Expand Up @@ -625,13 +625,13 @@ protected function generate_heading() {
}

/**
* Generate the item as static menu item, Send the custom URL to moodle_url to make this work with relative URL.
* Generate the item as static menu item, Send the custom URL to core\url to make this work with relative URL.
*
* @return string
*/
protected function generate_static_item() {

$staticurl = new \moodle_url($this->item->url);
$staticurl = new \core\url($this->item->url);

return $this->generate_node_data(
$this->item->title, // Title.
Expand Down Expand Up @@ -704,7 +704,7 @@ protected function generate_dynamic_item() {
$items = [];
// Build the items data into nodes.
foreach ($records as $record) {
$url = new \moodle_url('/course/view.php', ['id' => $record->id]);
$url = new \core\url('/course/view.php', ['id' => $record->id]);
$rkey = 'item-'.$this->item->id.'-dynamic-'.$record->id;
// Get the course image from overview files.
$itemimage = $this->get_course_image($record);
Expand Down
8 changes: 4 additions & 4 deletions classes/table/flavours_overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function col_updown($data) {
global $OUTPUT;

// Prepare action URL.
$actionurl = new \moodle_url('/theme/boost_union/flavours/overview.php');
$actionurl = new \core\url('/theme/boost_union/flavours/overview.php');

// Initialize column value.
$updown = '';
Expand Down Expand Up @@ -182,22 +182,22 @@ public function col_actions($data) {

// Preview.
$actions[] = [
'url' => new \moodle_url('/theme/boost_union/flavours/preview.php', ['id' => $data->id]),
'url' => new \core\url('/theme/boost_union/flavours/preview.php', ['id' => $data->id]),
'icon' => new \pix_icon('i/search', get_string('flavoursedit', 'theme_boost_union')),
'attributes' => ['class' => 'action-preview'],
];

// Edit.
$actions[] = [
'url' => new \moodle_url('/theme/boost_union/flavours/edit.php',
'url' => new \core\url('/theme/boost_union/flavours/edit.php',
['action' => 'edit', 'id' => $data->id, 'sesskey' => sesskey()]),
'icon' => new \pix_icon('t/edit', get_string('flavoursedit', 'theme_boost_union')),
'attributes' => ['class' => 'action-edit'],
];

// Delete.
$actions[] = [
'url' => new \moodle_url('/theme/boost_union/flavours/edit.php',
'url' => new \core\url('/theme/boost_union/flavours/edit.php',
['action' => 'delete', 'id' => $data->id, 'sesskey' => sesskey()]),
'icon' => new \pix_icon('t/delete', get_string('flavourspreview', 'theme_boost_union')),
'attributes' => ['class' => 'action-delete'],
Expand Down
14 changes: 7 additions & 7 deletions classes/table/smartmenus_items.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public function col_updown($data) {
global $OUTPUT;

// Prepare action URL.
$actionurl = new \moodle_url('/theme/boost_union/smartmenus/items.php');
$actionurl = new \core\url('/theme/boost_union/smartmenus/items.php');

// Initialize column value.
$updown = '';
Expand Down Expand Up @@ -283,44 +283,44 @@ public function col_actions($data) {
global $OUTPUT;

// Prepare action URL.
$actionurl = new \moodle_url('/theme/boost_union/smartmenus/items.php');
$actionurl = new \core\url('/theme/boost_union/smartmenus/items.php');

// Initialize actions.
$actions = [];

// Show/Hide.
if ($data->visible) {
$actions[] = [
'url' => new \moodle_url($actionurl, ['action' => 'hide', 'id' => $data->id, 'sesskey' => sesskey()]),
'url' => new \core\url($actionurl, ['action' => 'hide', 'id' => $data->id, 'sesskey' => sesskey()]),
'icon' => new \pix_icon('t/hide', get_string('hide')),
'attributes' => ['class' => 'action-hide'],
];
} else {
$actions[] = [
'url' => new \moodle_url($actionurl, ['action' => 'show', 'id' => $data->id, 'sesskey' => sesskey()]),
'url' => new \core\url($actionurl, ['action' => 'show', 'id' => $data->id, 'sesskey' => sesskey()]),
'icon' => new \pix_icon('t/show', get_string('show')),
'attributes' => ['class' => 'action-show'],
];
}

// Edit.
$actions[] = [
'url' => new \moodle_url('/theme/boost_union/smartmenus/edit_items.php',
'url' => new \core\url('/theme/boost_union/smartmenus/edit_items.php',
['id' => $data->id, 'sesskey' => sesskey()]),
'icon' => new \pix_icon('t/edit', get_string('edit')),
'attributes' => ['class' => 'action-edit'],
];

// Duplicate.
$actions[] = [
'url' => new \moodle_url($actionurl, ['action' => 'copy', 'id' => $data->id, 'sesskey' => sesskey()]),
'url' => new \core\url($actionurl, ['action' => 'copy', 'id' => $data->id, 'sesskey' => sesskey()]),
'icon' => new \pix_icon('t/copy', get_string('smartmenusmenuitemduplicate', 'theme_boost_union')),
'attributes' => ['class' => 'action-copy'],
];

// Delete.
$actions[] = [
'url' => new \moodle_url($actionurl, ['action' => 'delete', 'id' => $data->id, 'sesskey' => sesskey()]),
'url' => new \core\url($actionurl, ['action' => 'delete', 'id' => $data->id, 'sesskey' => sesskey()]),
'icon' => new \pix_icon('t/delete', get_string('delete')),
'attributes' => ['class' => 'action-delete'],
'confirm' => new \confirm_action(get_string('smartmenusmenuitemdeleteconfirm', 'theme_boost_union')),
Expand Down
16 changes: 8 additions & 8 deletions classes/table/smartmenus_menus.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function col_updown($data) {
global $OUTPUT;

// Prepare action URL.
$actionurl = new \moodle_url('/theme/boost_union/smartmenus/menus.php');
$actionurl = new \core\url('/theme/boost_union/smartmenus/menus.php');

// Initialize column value.
$updown = '';
Expand Down Expand Up @@ -202,50 +202,50 @@ public function col_actions($data) {
global $OUTPUT;

// Prepare action URL.
$actionurl = new \moodle_url('/theme/boost_union/smartmenus/menus.php');
$actionurl = new \core\url('/theme/boost_union/smartmenus/menus.php');

// Initialize actions.
$actions = [];

// Show/Hide.
if ($data->visible) {
$actions[] = [
'url' => new \moodle_url($actionurl, ['action' => 'hide', 'id' => $data->id, 'sesskey' => sesskey()]),
'url' => new \core\url($actionurl, ['action' => 'hide', 'id' => $data->id, 'sesskey' => sesskey()]),
'icon' => new \pix_icon('t/hide', get_string('hide')),
'attributes' => ['class' => 'action-hide'],
];
} else {
$actions[] = [
'url' => new \moodle_url($actionurl, ['action' => 'show', 'id' => $data->id, 'sesskey' => sesskey()]),
'url' => new \core\url($actionurl, ['action' => 'show', 'id' => $data->id, 'sesskey' => sesskey()]),
'icon' => new \pix_icon('t/show', get_string('show')),
'attributes' => ['class' => 'action-show'],
];
}

// Edit.
$actions[] = [
'url' => new \moodle_url('/theme/boost_union/smartmenus/edit.php', ['id' => $data->id, 'sesskey' => sesskey()]),
'url' => new \core\url('/theme/boost_union/smartmenus/edit.php', ['id' => $data->id, 'sesskey' => sesskey()]),
'icon' => new \pix_icon('t/edit', get_string('edit')),
'attributes' => ['class' => 'action-edit'],
];

// Duplicate.
$actions[] = [
'url' => new \moodle_url($actionurl, ['action' => 'copy', 'id' => $data->id, 'sesskey' => sesskey()]),
'url' => new \core\url($actionurl, ['action' => 'copy', 'id' => $data->id, 'sesskey' => sesskey()]),
'icon' => new \pix_icon('t/copy', get_string('smartmenusmenuduplicate', 'theme_boost_union')),
'attributes' => ['class' => 'action-copy'],
];

// List items.
$actions[] = [
'url' => new \moodle_url('/theme/boost_union/smartmenus/items.php', ['menu' => $data->id]),
'url' => new \core\url('/theme/boost_union/smartmenus/items.php', ['menu' => $data->id]),
'icon' => new \pix_icon('e/bullet_list', get_string('list')),
'attributes' => ['class' => 'action-list-items'],
];

// Delete.
$actions[] = [
'url' => new \moodle_url($actionurl, ['action' => 'delete', 'id' => $data->id, 'sesskey' => sesskey()]),
'url' => new \core\url($actionurl, ['action' => 'delete', 'id' => $data->id, 'sesskey' => sesskey()]),
'icon' => new \pix_icon('t/delete', get_string('delete')),
'attributes' => ['class' => 'action-delete'],
'confirm' => new \confirm_action(get_string('smartmenusmenudeleteconfirm', 'theme_boost_union')),
Expand Down
18 changes: 9 additions & 9 deletions flavours/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@

// Prepare the page.
$PAGE->set_context($context);
$PAGE->set_url(new moodle_url('/theme/boost_union/flavours/edit.php', ['action' => $action]));
$PAGE->set_url(new core\url('/theme/boost_union/flavours/edit.php', ['action' => $action]));
$PAGE->set_cacheable(false);
$PAGE->navbar->add(get_string('pluginname', 'theme_boost_union'), new moodle_url('/admin/category.php',
$PAGE->navbar->add(get_string('pluginname', 'theme_boost_union'), new core\url('/admin/category.php',
['category' => 'theme_boost_union']));
$PAGE->navbar->add(get_string('flavoursflavours', 'theme_boost_union'), new moodle_url('/theme/boost_union/flavours/overview.php'));
$PAGE->navbar->add(get_string('flavoursflavours', 'theme_boost_union'), new core\url('/theme/boost_union/flavours/overview.php'));
switch ($action) {
case 'create':
$PAGE->set_title(theme_boost_union_get_externaladminpage_title(get_string('flavourscreateflavour', 'theme_boost_union')));
Expand Down Expand Up @@ -138,12 +138,12 @@
\core\notification::success(get_string('flavoursnotificationcreated', 'theme_boost_union'));

// Redirect to overview page.
redirect(new moodle_url('/theme/boost_union/flavours/overview.php'));
redirect(new core\url('/theme/boost_union/flavours/overview.php'));

// Otherwise if the form was cancelled.
} else if ($form->is_cancelled()) {
// Redirect to overview page.
redirect(new moodle_url('/theme/boost_union/flavours/overview.php'));
redirect(new core\url('/theme/boost_union/flavours/overview.php'));
}

break;
Expand Down Expand Up @@ -212,12 +212,12 @@
\core\notification::success(get_string('flavoursnotificationedited', 'theme_boost_union'));

// Redirect to overview page.
redirect(new moodle_url('/theme/boost_union/flavours/overview.php'));
redirect(new core\url('/theme/boost_union/flavours/overview.php'));

// Otherwise if the form was cancelled.
} else if ($form->is_cancelled()) {
// Redirect to overview page.
redirect(new moodle_url('/theme/boost_union/flavours/overview.php'));
redirect(new core\url('/theme/boost_union/flavours/overview.php'));

// Otherwise if the form was not yet submitted.
} else {
Expand Down Expand Up @@ -295,12 +295,12 @@
\core\notification::success(get_string('flavoursnotificationdeleted', 'theme_boost_union'));

// Redirect to overview page.
redirect(new moodle_url('/theme/boost_union/flavours/overview.php'));
redirect(new core\url('/theme/boost_union/flavours/overview.php'));

// Otherwise if the form was cancelled.
} else if ($form->is_cancelled()) {
// Redirect to overview page.
redirect(new moodle_url('/theme/boost_union/flavours/overview.php'));
redirect(new core\url('/theme/boost_union/flavours/overview.php'));

// Otherwise if the form was not yet submitted.
} else {
Expand Down
2 changes: 1 addition & 1 deletion flavours/flavourslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function theme_boost_union_get_flavour_which_applies() {
// Otherwise.
} else {
// If we are on the preview page.
$previewurl = new moodle_url('/theme/boost_union/flavours/preview.php');
$previewurl = new core\url('/theme/boost_union/flavours/preview.php');
if ($previewurl->compare($PAGE->url, URL_MATCH_BASE) == true) {
// Get the flavour from the URL.
$previewflavourid = required_param('id', PARAM_INT);
Expand Down
4 changes: 2 additions & 2 deletions flavours/overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

// Prepare the page (to make sure that all necessary information is already set even if we just handle the actions as a start).
$PAGE->set_context($context);
$PAGE->set_url(new moodle_url('/theme/boost_union/flavours/overview.php'));
$PAGE->set_url(new core\url('/theme/boost_union/flavours/overview.php'));
$PAGE->set_cacheable(false);

// Process actions.
Expand Down Expand Up @@ -119,7 +119,7 @@
// Prepare 'Create flavours' button.
$createbutton = $OUTPUT->box_start();
$createbutton .= $OUTPUT->single_button(
new \moodle_url('/theme/boost_union/flavours/edit.php', ['action' => 'create', 'sesskey' => sesskey()]),
new \core\url('/theme/boost_union/flavours/edit.php', ['action' => 'create', 'sesskey' => sesskey()]),
get_string('flavourscreateflavour', 'theme_boost_union'), 'get');
$createbutton .= $OUTPUT->box_end();

Expand Down
8 changes: 4 additions & 4 deletions flavours/preview.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@

// Prepare the page.
$PAGE->set_context($context);
$PAGE->set_url(new moodle_url('/theme/boost_union/flavours/preview.php', ['id' => $flavourid]));
$PAGE->set_url(new core\url('/theme/boost_union/flavours/preview.php', ['id' => $flavourid]));
$PAGE->set_cacheable(false);
$PAGE->navbar->add(get_string('pluginname', 'theme_boost_union'), new moodle_url('/admin/category.php',
$PAGE->navbar->add(get_string('pluginname', 'theme_boost_union'), new core\url('/admin/category.php',
['category' => 'theme_boost_union']));
$PAGE->navbar->add(get_string('flavoursflavours', 'theme_boost_union'), new moodle_url('/theme/boost_union/flavours/overview.php'));
$PAGE->navbar->add(get_string('flavoursflavours', 'theme_boost_union'), new core\url('/theme/boost_union/flavours/overview.php'));
$PAGE->set_title(theme_boost_union_get_externaladminpage_title(get_string('flavourspreviewflavour', 'theme_boost_union')));
$PAGE->set_heading(get_string('flavourspreviewflavour', 'theme_boost_union'));
$PAGE->navbar->add(get_string('flavourspreviewflavour', 'theme_boost_union'));
Expand All @@ -60,7 +60,7 @@
// Show back to overview button.
echo $OUTPUT->box_start('text-center');
echo $OUTPUT->single_button(
new \moodle_url('/theme/boost_union/flavours/overview.php'),
new \core\url('/theme/boost_union/flavours/overview.php'),
get_string('flavoursbacktooverview', 'theme_boost_union'), 'get');
echo $OUTPUT->box_end();

Expand Down
2 changes: 1 addition & 1 deletion flavours/styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
// If the flavour has a background image.
if ($flavour->look_backgroundimage != null) {
// Compose the URL to the flavour's background image.
$backgroundimageurl = moodle_url::make_pluginfile_url(
$backgroundimageurl = core\url::make_pluginfile_url(
context_system::instance()->id, 'theme_boost_union', 'flavours_look_backgroundimage', $flavourid,
'/'.theme_get_revision(), '/'.$flavour->look_backgroundimage);

Expand Down
Loading

0 comments on commit fe5b0dd

Please sign in to comment.