MDL-78885 comboboxesearch: Comboboxes should have a name and value

- core_grades_renderer::group_selector() was changed previously, but it
  was providing redundant context data to
core_group/comboboxsearch/group_selector and on the other hand, it was
not providing 'name' and 'value' for core/comboboxsearch
- The $groupactionbaseurl parameter of
  core_grades_renderer::group_selector() is now deprecated as it was not
used.
- a bug is fixed: if only a lastname initial was set, the clear search
  button was not being displayed.
This commit is contained in:
Shamim Rezaie 2023-10-25 03:17:38 +11:00
parent e9ec450668
commit b4bb1cde97
6 changed files with 70 additions and 32 deletions

View file

@ -45,12 +45,18 @@ class core_grades_renderer extends plugin_renderer_base {
* Renders the group selector trigger element.
*
* @param object $course The course object.
* @param string|null $groupactionbaseurl The base URL for the group action.
* @param string|null $groupactionbaseurl This parameter has been deprecated since 4.4 and should not be used anymore.
* @return string|null The raw HTML to render.
*/
public function group_selector(object $course, ?string $groupactionbaseurl = null): ?string {
global $USER;
if ($groupactionbaseurl !== null) {
debugging(
'The $groupactionbaseurl argument has been deprecated. Please remove it from your method calls.',
DEBUG_DEVELOPER,
);
}
// Make sure that group mode is enabled.
if (!$groupmode = $course->groupmode) {
return null;
@ -61,15 +67,9 @@ class core_grades_renderer extends plugin_renderer_base {
'currentvalue' => optional_param('groupsearchvalue', '', PARAM_NOTAGS),
]);
$label = $groupmode == VISIBLEGROUPS ? get_string('selectgroupsvisible') :
get_string('selectgroupsseparate');
$label = $groupmode == VISIBLEGROUPS ? get_string('selectgroupsvisible') : get_string('selectgroupsseparate');
$data = [
'name' => 'group',
'label' => $label,
'courseid' => $course->id,
'groupactionbaseurl' => $groupactionbaseurl
];
$buttondata = ['label' => $label];
$context = context_course::instance($course->id);
@ -80,22 +80,26 @@ class core_grades_renderer extends plugin_renderer_base {
}
$activegroup = groups_get_course_group($course, true, $allowedgroups);
$data['group'] = $activegroup;
$buttondata['group'] = $activegroup;
if ($activegroup) {
$group = groups_get_group($activegroup);
$data['selectedgroup'] = format_string($group->name, true, ['context' => $context]);
$buttondata['selectedgroup'] = format_string($group->name, true, ['context' => $context]);
} else if ($activegroup === 0) {
$data['selectedgroup'] = get_string('allparticipants');
$buttondata['selectedgroup'] = get_string('allparticipants');
}
$groupdropdown = new comboboxsearch(
false,
$this->render_from_template('core_group/comboboxsearch/group_selector', $data),
$this->render_from_template('core_group/comboboxsearch/group_selector', $buttondata),
$sbody,
'group-search',
'groupsearchwidget',
'groupsearchdropdown overflow-auto',
null,
true,
'group',
$activegroup
);
return $this->render_from_template($groupdropdown->get_template(), $groupdropdown->export_for_template($this));
}

View file

@ -80,6 +80,10 @@ class action_bar extends \core_grades\output\action_bar {
$this->context,
'/grade/report/grader/index.php'
);
$firstnameinitial = $SESSION->gradereport["filterfirstname-{$this->context->id}"] ?? '';
$lastnameinitial = $SESSION->gradereport["filtersurname-{$this->context->id}"] ?? '';
$initialselector = new comboboxsearch(
false,
$initialscontent->buttoncontent,
@ -88,6 +92,12 @@ class action_bar extends \core_grades\output\action_bar {
'initialswidget',
'initialsdropdown',
$initialscontent->buttonheader,
true,
'nameinitials',
json_encode([
'first' => $firstnameinitial,
'last' => $lastnameinitial,
])
);
$data['initialselector'] = $initialselector->export_for_template($output);
$data['groupselector'] = $gradesrenderer->group_selector($course);
@ -123,6 +133,7 @@ class action_bar extends \core_grades\output\action_bar {
'collapsecolumndropdown p-3 flex-column ' . $collapsemenudirection,
null,
true,
'collapsedcolumns'
);
$data['collapsedcolumns'] = [
'classes' => 'd-none',
@ -135,10 +146,12 @@ class action_bar extends \core_grades\output\action_bar {
$allowedgroups = groups_get_all_groups($course->id, $USER->id, $course->defaultgroupingid);
}
if (!empty($SESSION->gradereport["filterfirstname-{$this->context->id}"]) ||
!empty($SESSION->gradereport["filterlastname-{$this->context->id}"]) ||
if (
$firstnameinitial ||
$lastnameinitial ||
groups_get_course_group($course, true, $allowedgroups) ||
$this->usersearch) {
$this->usersearch
) {
$reset = new moodle_url('/grade/report/grader/index.php', [
'id' => $courseid,
'group' => 0,

View file

@ -131,7 +131,7 @@ class singleview extends grade_report {
protected function setup_groups() {
parent::setup_groups();
$this->group_selector = static::groups_course_menu($this->course, $this->pbarurl);
$this->group_selector = static::groups_course_menu($this->course);
}
/**
@ -139,19 +139,13 @@ class singleview extends grade_report {
* so all reports would automatically use it.
*
* @param stdClass $course
* @param moodle_url $urlroot
* @return string
*/
protected static function groups_course_menu(stdClass $course, moodle_url $urlroot) {
protected static function groups_course_menu(stdClass $course) {
global $PAGE;
$renderer = $PAGE->get_renderer('core_grades');
$params = $urlroot->params();
if ($params['item'] == 'user') {
$params['item'] = 'user_select';
$urlroot->params($params);
}
return $renderer->group_selector($course, $urlroot->out());
return $renderer->group_selector($course);
}
/**

View file

@ -100,6 +100,10 @@ class gradereport_singleview_renderer extends plugin_renderer_base {
'grade-search h-100',
'gradesearchwidget h-100',
'gradesearchdropdown overflow-auto',
null,
true,
'itemid',
$gradeitemid
);
return $this->render_from_template($dropdown->get_template(), $dropdown->export_for_template($this));
}

View file

@ -54,6 +54,12 @@ class comboboxsearch implements renderable, templatable {
/** @var boolean $usesbutton Whether to provide a A11y button. */
protected $usesbutton;
/** @var null|string $name The name of the input element representing the combobox. */
protected $name;
/** @var null|string $value The value of the input element representing the combobox. */
protected $value;
/**
* The class constructor.
*
@ -64,7 +70,9 @@ class comboboxsearch implements renderable, templatable {
* @param ?string $buttonclasses Any special classes that may be needed.
* @param ?string $dropdownclasses Any special classes that may be needed.
* @param ?string $buttonheader If the button item in the tertiary nav needs an extra top header for context.
* @param bool $usebutton If we want the mustache to add the button roles for us or do we have another aria role node?
* @param ?bool $usebutton If we want the mustache to add the button roles for us or do we have another aria role node?
* @param ?string $name The name of the input element representing the combobox.
* @param ?string $value The value of the input element representing the combobox.
* @throws moodle_exception If the implementor incorrectly call this module.
*/
public function __construct(
@ -75,7 +83,9 @@ class comboboxsearch implements renderable, templatable {
?string $buttonclasses = null,
?string $dropdownclasses = null,
?string $buttonheader = null,
?bool $usebutton = true
?bool $usebutton = true,
?string $name = null,
?string $value = null
) {
// Ensure implementors cant request to render the content now and not provide us any to show.
if (!$renderlater && empty($dropdowncontent)) {
@ -87,6 +97,13 @@ class comboboxsearch implements renderable, templatable {
);
}
if ($usebutton && !$name) {
debugging(
'You have requested to use the button but have not provided a name for the input element.',
DEBUG_DEVELOPER
);
}
$this->renderlater = $renderlater;
$this->buttoncontent = $buttoncontent;
$this->dropdowncontent = $dropdowncontent;
@ -95,6 +112,8 @@ class comboboxsearch implements renderable, templatable {
$this->dropdownclasses = $dropdownclasses;
$this->buttonheader = $buttonheader;
$this->usesbutton = $usebutton;
$this->name = $name;
$this->value = $value;
}
/**
@ -115,6 +134,8 @@ class comboboxsearch implements renderable, templatable {
'buttonheader' => $this->buttonheader,
'usebutton' => $this->usesbutton,
'instance' => rand(), // Template uniqid is per render out so sometimes these conflict.
'name' => $this->name,
'value' => $this->value,
];
}

View file

@ -17,6 +17,8 @@
Combobox search selector dropdown.
Context variables required for this template:
* name - The name of the input element representing the combobox.
* value - The value of the input element representing the combobox.
* rtl - Is this dropdown being used in a RTL case? if so, we need to ensure it drops down in the right place.
* renderlater - This determines if we show a placeholder whilst fetching content to replace within the placeholder region
* buttoncontent - The string to be shown to users to trigger the dropdown
@ -29,6 +31,8 @@
Example context (json):
{
"name": "input-1",
"value": "0",
"rtl": false,
"renderlater": false,
"usebutton": true,
@ -43,10 +47,7 @@
{{#buttonheader}}
<small>{{.}}</small>
{{/buttonheader}}
<div class="{{#parentclasses}}{{.}}{{/parentclasses}} dropdown"
{{^usebutton}}
data-input-element="input-{{uniqid}}"
{{/usebutton}}>
<div class="{{#parentclasses}}{{.}}{{/parentclasses}} dropdown">
{{#usebutton}}
<div tabindex="0"
@ -57,9 +58,10 @@
aria-controls="dialog-{{instance}}-{{uniqid}}"
class="{{#buttonclasses}}{{.}}{{/buttonclasses}} btn dropdown-toggle keep-open d-flex text-left align-items-center p-0 font-weight-bold"
aria-label="{{#cleanstr}} aria-toggledropdown, core {{/cleanstr}}"
data-input-element="input-{{uniqid}}">
data-input-element="input-{{instance}}-{{uniqid}}">
{{{buttoncontent}}}
</div>
<input type="hidden" name="{{name}}" value="{{value}}" id="input-{{instance}}-{{uniqid}}"/>
{{/usebutton}}
{{^usebutton}}{{{buttoncontent}}}{{/usebutton}}