MDL-86416 navigation: Render the more menu only when it's not empty

Co-authored-by: Jun Pataleta <[email protected]>
This commit is contained in:
Stefan Topfstedt
2025-12-09 11:17:10 +08:00
committed by Jun Pataleta
co-authored by Jun Pataleta
parent d58091724b
commit 12968cd829
2 changed files with 50 additions and 0 deletions
@@ -83,6 +83,10 @@ class more_menu implements renderable, templatable {
$data['nodecollection'] = $this->content;
} else {
$data['nodearray'] = (array) $this->content;
// If there is no node array to render then return an empty array.
if (empty($data['nodearray'])) {
return [];
}
}
$data['moremenuid'] = uniqid();
@@ -0,0 +1,46 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace core\navigation\output;
use basic_testcase;
use core\output\renderer_base;
use stdClass;
/**
* More menu navigation renderable test.
*
* @package core
* @category navigation
* @copyright Stefan Topfstedt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \core\navigation\output\more_menu
*/
final class more_menu_test extends basic_testcase {
/**
* Checks that export_for_template() returns an empty array if the given content is empty.
* See MDL-86416.
*
* @return void
*/
public function test_export_for_template_returns_empty_array(): void {
$moremenu = new more_menu(new stdClass(), 'whatever', false, false);
$output = $this->createStub(renderer_base::class);
$data = $moremenu->export_for_template($output);
$this->assertIsArray($data);
$this->assertEmpty($data);
}
}