MDL-78308 output: better parsing of custom menu item configuration.

Previously certain values would cause deprecation notices in PHP8.1.
This commit is contained in:
Paul Holden 2023-05-18 08:54:27 +01:00
parent 017a3274fe
commit 5c871bff29
No known key found for this signature in database
GPG Key ID: A81A96D6045F6164

View File

@ -3492,7 +3492,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;
@ -3769,7 +3772,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, '-');