forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-80746 core_course: fix user_selector rendering
This change: - Moved the user selector button content out into its own named_templatable renderable + updates calling code
- Loading branch information
Showing
2 changed files
with
96 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?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_course\output\actionbar; | ||
|
||
use core\output\named_templatable; | ||
use core\output\renderable; | ||
use core\output\renderer_base; | ||
use core\url; | ||
use stdClass; | ||
|
||
/** | ||
* Renderable class for the user_selector_button. | ||
* | ||
* This is the button content for the user_selector renderable, which itself is an extension of the comboboxsearch component. | ||
* {@see initials_selector}. | ||
* | ||
* @package core_course | ||
* @copyright 2024 Jake Dallimore <[email protected]> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class user_selector_button implements renderable, named_templatable { | ||
|
||
/** | ||
* The class constructor. | ||
*/ | ||
public function __construct( | ||
private stdClass $course, | ||
private url $resetlink, | ||
private ?int $userid = null, | ||
private ?int $groupid = null, | ||
private string $usersearch = '', | ||
private ?int $instanceid = null | ||
) { | ||
// If the user ID is set, it indicates that a user has been selected. In this case, override the user search | ||
// string with the full name of the selected user. | ||
if ($this->userid) { | ||
$this->usersearch = fullname(\core_user::get_user($this->userid)); | ||
} | ||
} | ||
|
||
public function export_for_template(renderer_base $output) { | ||
return [ | ||
'currentvalue' => $this->usersearch, | ||
'courseid' => $this->course->id, | ||
'instance' => $this->instanceid ?? rand(), | ||
'resetlink' => $this->resetlink->out(false), | ||
'group' => $this->groupid ?? 0, | ||
'name' => 'usersearch', | ||
'value' => json_encode([ | ||
'userid' => $this->userid, | ||
'search' => $this->usersearch, | ||
]), | ||
]; | ||
} | ||
|
||
public function get_template_name(renderer_base $renderer): string { | ||
return 'core_user/comboboxsearch/user_selector'; | ||
} | ||
} |