From 01b12e91ac89e9d6b7f83107fb87acbf7e4e38b0 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Thu, 18 May 2023 08:54:27 +0100 Subject: [PATCH] MDL-78308 output: better parsing of custom menu item configuration. Previously certain values would cause deprecation notices in PHP8.1. --- lib/outputcomponents.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index 02f6cbe13fa..8418e581443 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -3493,7 +3493,10 @@ class custom_menu_item implements renderable, templatable { */ public function __construct($text, moodle_url $url = null, $title = null, $sort = null, custom_menu_item $parent = null, array $attributes = []) { - $this->text = $text; + + // Use class setter method for text to ensure it's always a string type. + $this->set_text($text); + $this->url = $url; $this->title = $title; $this->sort = (int)$sort; @@ -3770,7 +3773,7 @@ class custom_menu extends custom_menu_item { $settings = explode('|', $line); foreach ($settings as $i => $setting) { $setting = trim($setting); - if (!empty($setting)) { + if ($setting !== '') { switch ($i) { case 0: // Menu text. $itemtext = ltrim($setting, '-');