Skip to content

Commit

Permalink
MDL-75337 core: Single button - core changes
Browse files Browse the repository at this point in the history
    * Change all core calls toward single_button to use single_button::BUTTON_PRIMARY
    when needed
  • Loading branch information
Laurent David committed Jan 24, 2023
1 parent 377c962 commit fc72a1d
Show file tree
Hide file tree
Showing 39 changed files with 96 additions and 60 deletions.
2 changes: 1 addition & 1 deletion admin/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public function upgrade_plugin_check_page(core_plugin_manager $pluginman, \core\
$output .= $this->container_end();
}

$button = new single_button($continueurl, get_string('upgradestart', 'admin'), 'get', true);
$button = new single_button($continueurl, get_string('upgradestart', 'admin'), 'get', single_button::BUTTON_PRIMARY);
$button->class = 'continuebutton';
$output .= $this->render($button);
$output .= $this->footer();
Expand Down
2 changes: 1 addition & 1 deletion admin/searchareas.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
$cancelurl = new moodle_url('/admin/searchareas.php');
echo $OUTPUT->header();
echo $OUTPUT->confirm(get_string('confirm_' . $action, 'search', $a),
new single_button($actionurl, get_string('continue'), 'post', true),
new single_button($actionurl, get_string('continue'), 'post', single_button::BUTTON_PRIMARY),
new single_button($cancelurl, get_string('cancel'), 'get'));
echo $OUTPUT->footer();
exit;
Expand Down
2 changes: 1 addition & 1 deletion admin/searchreindex.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
// Display confirmation prompt.
echo $OUTPUT->confirm(get_string('gradualreindex_confirm', 'search', html_writer::tag('strong', $areaname)),
new single_button(new moodle_url('/admin/searchreindex.php', ['areaid' => $areaid,
'sesskey' => sesskey()]), get_string('continue'), 'post', true),
'sesskey' => sesskey()]), get_string('continue'), 'post', single_button::BUTTON_PRIMARY),
new single_button(new moodle_url('/admin/searchareas.php'), get_string('cancel'), 'get'));
}

Expand Down
2 changes: 1 addition & 1 deletion admin/tool/brickfield/classes/output/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public function analysisbutton(int $courseid) : string {
$link,
get_string('schedule:requestanalysis', manager::PLUGINNAME),
'post',
true,
\single_button::BUTTON_PRIMARY,
['class' => $classname]
);

Expand Down
2 changes: 1 addition & 1 deletion admin/webservice/tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
echo $OUTPUT->heading(get_string('managetokens', 'core_webservice'));

echo html_writer::div($OUTPUT->render(new single_button(new moodle_url($PAGE->url, ['action' => 'create']),
get_string('createtoken', 'core_webservice'), 'get', true)), 'my-3');
get_string('createtoken', 'core_webservice'), 'get', single_button::BUTTON_PRIMARY)), 'my-3');

$filter->display();

Expand Down
5 changes: 4 additions & 1 deletion analytics/classes/bulk_action.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public function __construct($actionname, \moodle_url $actionurl, \pix_icon $icon
$this->url = new \moodle_url('/report/insights/action.php', $params);

$label = $OUTPUT->render($icon) . $this->text;
$this->actionlink = new \single_button($this->url, $label, 'get', $primary, $attributes);
$this->actionlink = new \single_button($this->url, $label,
'get',
$primary ? \single_button::BUTTON_PRIMARY : \single_button::BUTTON_SECONDARY,
$attributes);
}
}
2 changes: 1 addition & 1 deletion backup/util/ui/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ public function continue_button($url, $method = 'post') {
if ($method != 'post') {
$method = 'get';
}
$button = new single_button($url, get_string('continue'), $method, true);
$button = new single_button($url, get_string('continue'), $method, single_button::BUTTON_PRIMARY);
$button->class = 'continuebutton';
return $this->render($button);
}
Expand Down
2 changes: 1 addition & 1 deletion badges/classes/output/recipients_action_bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function export_for_template(renderer_base $output): array {
if ($this->badge->has_manual_award_criteria()
&& has_capability('moodle/badges:awardbadge', $this->page->context) && $this->badge->is_active()) {
$url = new moodle_url('/badges/award.php', ['id' => $this->badge->id]);
$button = new single_button($url, get_string('award', 'badges'), 'post', true);
$button = new single_button($url, get_string('award', 'badges'), 'post', single_button::BUTTON_PRIMARY);
$elements['awardbutton'] = $button->export_for_template($output);
}
$thirdpartynav = $this->get_third_party_nav_action($output);
Expand Down
2 changes: 1 addition & 1 deletion badges/classes/output/standard_action_bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function export_for_template(renderer_base $output): array {

if ($this->showaddbadge && has_capability('moodle/badges:createbadge', $this->page->context)) {
$buttons[] = new single_button(new moodle_url('/badges/newbadge.php', $params),
get_string('newbadge', 'core_badges'), 'post', true);
get_string('newbadge', 'core_badges'), 'post', single_button::BUTTON_PRIMARY);
}

foreach ($buttons as $key => $button) {
Expand Down
2 changes: 1 addition & 1 deletion blocks/accessreview/block_accessreview.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function get_content() {

$button = new single_button(
new moodle_url(accessibility::get_plugin_url(), ['action' => 'requestanalysis', 'courseid' => $COURSE->id]),
get_string('schedule:requestanalysis', manager::PLUGINNAME), 'post', true,
get_string('schedule:requestanalysis', manager::PLUGINNAME), 'post', single_button::BUTTON_PRIMARY,
['class' => 'block_accessreview_analysisbutton']);
$this->content->text .= html_writer::tag('div', $OUTPUT->render($button),
['class' => 'block_accessreview_analysisbutton']);
Expand Down
6 changes: 3 additions & 3 deletions blocks/myoverview/classes/output/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ public function export_for_zero_state_template(renderer_base $output) {
new \moodle_url('/course/request.php', ['category' => $category->id]),
get_string('requestcourse'),
'post',
true
\single_button::BUTTON_PRIMARY
);
return $this->generate_zero_state_data($nocoursesimg, [$button], 'request');
}
Expand All @@ -523,7 +523,7 @@ public function export_for_zero_state_template(renderer_base $output) {
new \moodle_url('/course/edit.php', ['category' => $category->id]),
get_string('createcourse', 'block_myoverview'),
'post',
true
\single_button::BUTTON_PRIMARY
);
$buttons[] = $createbutton->export_for_template($output);
return $this->generate_zero_state_data($nocoursesimg, $buttons, 'nocourses');
Expand All @@ -534,7 +534,7 @@ public function export_for_zero_state_template(renderer_base $output) {
new \moodle_url('/course/edit.php', ['category' => $categorytocreate->id]),
get_string('createcourse', 'block_myoverview'),
'post',
true
\single_button::BUTTON_PRIMARY
);
$buttons = [$createbutton->export_for_template($output)];
if ($categorytomanage = \core_course_category::get_nearest_editable_subcategory($coursecat, ['manage'])) {
Expand Down
4 changes: 2 additions & 2 deletions calendar/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,10 @@ public function course_filter_selector(moodle_url $returnurl, $label = null, $co
*/
public function render_subscriptions_header(): string {
$importcalendarbutton = new single_button(new moodle_url('/calendar/import.php', calendar_get_export_import_link_params()),
get_string('importcalendar', 'calendar'), 'get', true);
get_string('importcalendar', 'calendar'), 'get', single_button::BUTTON_PRIMARY);
$importcalendarbutton->class .= ' float-sm-right float-right';
$exportcalendarbutton = new single_button(new moodle_url('/calendar/export.php', calendar_get_export_import_link_params()),
get_string('exportcalendar', 'calendar'), 'get', true);
get_string('exportcalendar', 'calendar'), 'get', single_button::BUTTON_PRIMARY);
$exportcalendarbutton->class .= ' float-sm-right float-right';
$output = $this->output->heading(get_string('managesubscriptions', 'calendar'));
$output .= html_writer::start_div('header d-flex flex-wrap mt-5');
Expand Down
2 changes: 1 addition & 1 deletion enrol/manual/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public function get_manual_enrol_button(course_enrolment_manager $manager) {

$button = new enrol_user_button($link, get_string('enrolusers', 'enrol_manual'), 'get');
$button->class .= ' enrol_manual_plugin';
$button->primary = true;
$button->type = single_button::BUTTON_PRIMARY;

$context = context_course::instance($instance->courseid);
$arguments = array('contextid' => $context->id);
Expand Down
2 changes: 1 addition & 1 deletion enrol/otherusers.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
// Check we have a search button to render.
$searchbuttonrender = null;
if ($searchbutton = $table->get_user_search_button()) {
$searchbutton->primary = true;
$searchbutton->type = single_button::BUTTON_PRIMARY;
$searchbuttonrender = $OUTPUT->render($searchbutton);
}

Expand Down
15 changes: 9 additions & 6 deletions enrol/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@ class core_enrol_renderer extends plugin_renderer_base {
* @return string XHTML
*/
protected function render_enrol_user_button(enrol_user_button $button) {
$attributes = array('type' => 'submit',
'value' => $button->label,
'disabled' => $button->disabled ? 'disabled' : null,
'title' => $button->tooltip,
'class' => 'btn ' . ($button->primary ? 'btn-primary' : 'btn-secondary'));

$buttoninfo = $button->export_for_template($this->output);

$attributes = [
'type' => 'submit',
'value' => $buttoninfo->label,
'disabled' => $buttoninfo->disabled ? 'disabled' : null,
'title' => $buttoninfo->tooltip,
'class' => 'btn ' . "btn-{$buttoninfo->type}",
];
if ($button->actions) {
$id = html_writer::random_id('single_button');
$attributes['id'] = $id;
Expand Down
2 changes: 1 addition & 1 deletion grade/classes/output/course_outcomes_action_bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function export_for_template(\renderer_base $output): array {
// Add a button to the action bar with a link to the 'manage outcomes' page.
$manageoutcomeslink = new moodle_url('/grade/edit/outcome/index.php', ['id' => $courseid]);
$manageoutcomesbutton = new \single_button($manageoutcomeslink, get_string('manageoutcomes', 'grades'),
'get', true);
'get', \single_button::BUTTON_PRIMARY);
$data['manageoutcomesbutton'] = $manageoutcomesbutton->export_for_template($output);
}

Expand Down
2 changes: 1 addition & 1 deletion grade/classes/output/export_key_manager_action_bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function export_for_template(\renderer_base $output): array {
// Add a button to the action bar with a link to the 'add user key' page.
$adduserkeylink = new moodle_url('/grade/export/key.php', ['courseid' => $courseid]);
$adduserkeybutton = new \single_button($adduserkeylink, get_string('adduserkey', 'userkey'),
'get', true);
'get', \single_button::BUTTON_PRIMARY);
$data['adduserkeybutton'] = $adduserkeybutton->export_for_template($output);

return $data;
Expand Down
2 changes: 1 addition & 1 deletion grade/classes/output/grade_letters_action_bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function export_for_template(\renderer_base $output): array {
}
// Add a button to the action bar with a link to the 'edit grade letters' page.
$editbuttonlink = new moodle_url('/grade/edit/letter/index.php', ['id' => $this->context->id, 'edit' => 1]);
$editbutton = new \single_button($editbuttonlink, get_string('edit'), 'get', true);
$editbutton = new \single_button($editbuttonlink, get_string('edit'), 'get', \single_button::BUTTON_PRIMARY);
$data['editbutton'] = $editbutton->export_for_template($output);

return $data;
Expand Down
2 changes: 1 addition & 1 deletion grade/classes/output/import_key_manager_action_bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function export_for_template(\renderer_base $output): array {
// Add a button to the action bar with a link to the 'add user key' page.
$adduserkeylink = new moodle_url('/grade/import/key.php', ['courseid' => $courseid]);
$adduserkeybutton = new \single_button($adduserkeylink, get_string('adduserkey', 'userkey'),
'get', true);
'get', \single_button::BUTTON_PRIMARY);
$data['adduserkeybutton'] = $adduserkeybutton->export_for_template($output);

return $data;
Expand Down
2 changes: 1 addition & 1 deletion grade/classes/output/manage_outcomes_action_bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function export_for_template(\renderer_base $output): array {
// Add a button to the action bar with a link to the 'add new outcome' page.
$addoutcomelink = new moodle_url('/grade/edit/outcome/edit.php', ['courseid' => $courseid]);
$addoutcomebutton = new \single_button($addoutcomelink, get_string('outcomecreate', 'grades'),
'get', true);
'get', \single_button::BUTTON_PRIMARY);
$data['addoutcomebutton'] = $addoutcomebutton->export_for_template($output);

if ($this->hasoutcomes) {
Expand Down
2 changes: 1 addition & 1 deletion grade/classes/output/scales_action_bar.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function export_for_template(\renderer_base $output): array {
// Add a button to the action bar with a link to the 'add new scale' page.
$addnewscalelink = new moodle_url('/grade/edit/scale/edit.php', ['courseid' => $courseid]);
$addnewscalebutton = new \single_button($addnewscalelink, get_string('scalescustomcreate'),
'get', true);
'get', \single_button::BUTTON_PRIMARY);
$data['addnewscalebutton'] = $addnewscalebutton->export_for_template($output);

return $data;
Expand Down
22 changes: 14 additions & 8 deletions lib/outputrenderers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2051,12 +2051,16 @@ public function confirm($message, $continue, $cancel, array $displayoptions = []
$displayoptions['cancelstr'] = $displayoptions['cancelstr'] ?? get_string('cancel');

if ($continue instanceof single_button) {
// ok
$continue->primary = true;
// Continue button should be primary if set to secondary type as it is the fefault.
if ($continue->type === single_button::BUTTON_SECONDARY) {
$continue->type = single_button::BUTTON_PRIMARY;
}
} else if (is_string($continue)) {
$continue = new single_button(new moodle_url($continue), $displayoptions['continuestr'], 'post', true);
$continue = new single_button(new moodle_url($continue), $displayoptions['continuestr'], 'post',
$displayoptions['type'] ?? single_button::BUTTON_PRIMARY);
} else if ($continue instanceof moodle_url) {
$continue = new single_button($continue, $displayoptions['continuestr'], 'post', true);
$continue = new single_button($continue, $displayoptions['continuestr'], 'post',
$displayoptions['type'] ?? single_button::BUTTON_PRIMARY);
} else {
throw new coding_exception('The continue param to $OUTPUT->confirm() must be either a URL (string/moodle_url) or a single_button instance.');
}
Expand Down Expand Up @@ -3120,7 +3124,7 @@ public function continue_button($url) {
if (!($url instanceof moodle_url)) {
$url = new moodle_url($url);
}
$button = new single_button($url, get_string('continue'), 'get', true);
$button = new single_button($url, get_string('continue'), 'get', single_button::BUTTON_PRIMARY);
$button->class = 'continuebutton';

return $this->render($button);
Expand Down Expand Up @@ -5567,11 +5571,13 @@ public function confirm($message, $continue, $cancel, array $displayoptions = []
// We need plain styling of confirm boxes on upgrade because we don't know which stylesheet we have (it could be
// from any previous version of Moodle).
if ($continue instanceof single_button) {
$continue->primary = true;
$continue->type = single_button::BUTTON_PRIMARY;
} else if (is_string($continue)) {
$continue = new single_button(new moodle_url($continue), get_string('continue'), 'post', true);
$continue = new single_button(new moodle_url($continue), get_string('continue'), 'post',
$displayoptions['type'] ?? single_button::BUTTON_PRIMARY);
} else if ($continue instanceof moodle_url) {
$continue = new single_button($continue, get_string('continue'), 'post', true);
$continue = new single_button($continue, get_string('continue'), 'post',
$displayoptions['type'] ?? single_button::BUTTON_PRIMARY);
} else {
throw new coding_exception('The continue param to $OUTPUT->confirm() must be either a URL' .
' (string/moodle_url) or a single_button instance.');
Expand Down
2 changes: 1 addition & 1 deletion mod/assign/classes/output/override_actionmenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function export_for_template(\renderer_base $output): array {
} else if ($action === 'adduser' && !$this->show_useroverride()) {
$options = ['disabled' => 'true'];
}
$overridebutton = new single_button($url, $text, 'post', true, $options);
$overridebutton = new single_button($url, $text, 'post', single_button::BUTTON_PRIMARY, $options);

$urlselect = $this->get_select_menu();
return [
Expand Down
16 changes: 13 additions & 3 deletions mod/assign/classes/output/user_submission_actionmenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,12 @@ public function export_for_template(\renderer_base $output): array {
'help' => $help->export_for_template($output)
];
$url = new moodle_url('/mod/assign/view.php', ['id' => $this->cmid, 'action' => 'editsubmission']);
$newattemptbutton = new single_button($url, get_string('addnewattempt', 'mod_assign'), 'get', true);
$newattemptbutton = new single_button(
$url,
get_string('addnewattempt', 'mod_assign'),
'get',
single_button::BUTTON_PRIMARY
);
$newattempthelp = new help_icon('addnewattempt', 'mod_assign');
$data['edit']['button'] = $newattemptbutton->export_for_template($output);
$data['edit']['help'] = $newattempthelp->export_for_template($output);
Expand All @@ -143,15 +148,20 @@ public function export_for_template(\renderer_base $output): array {
$data['edit']['begin'] = true;
$data['edit']['help'] = '';
} else {
$newattemptbutton = new single_button($url, get_string('addsubmission', 'mod_assign'), 'get', true);
$newattemptbutton = new single_button(
$url,
get_string('addsubmission', 'mod_assign'),
'get',
single_button::BUTTON_PRIMARY
);
$data['edit']['button'] = $newattemptbutton->export_for_template($output);
$data['edit']['help'] = '';
}
}
}
if ($this->showsubmit) {
$url = new moodle_url('/mod/assign/view.php', ['id' => $this->cmid, 'action' => 'submit']);
$button = new single_button($url, get_string('submitassignment', 'mod_assign'), 'get', true);
$button = new single_button($url, get_string('submitassignment', 'mod_assign'), 'get', single_button::BUTTON_PRIMARY);
$help = new help_icon('submitassignment', 'mod_assign');
$data['submit'] = [
'button' => $button->export_for_template($output),
Expand Down
2 changes: 1 addition & 1 deletion mod/bigbluebuttonbn/mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ private function bigbluebuttonbn_mform_add_block_user_role_mapping(MoodleQuickFo
$action = new single_button(new moodle_url(qualified_me()),
get_string('mod_form_field_participant_list_action_add', 'bigbluebuttonbn'),
'post',
false,
single_button::BUTTON_SECONDARY,
['name' => 'bigbluebuttonbn_participant_selection_add']
);
$pformcontext = [
Expand Down
2 changes: 1 addition & 1 deletion mod/data/classes/output/add_entries_action.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function export_for_template(\renderer_base $output): ?\stdClass {

if (data_user_can_add_entry($database, $currentgroup, $groupmode, $PAGE->context)) {
$addentrylink = new moodle_url('/mod/data/edit.php', ['d' => $this->id, 'backto' => $PAGE->url->out(false)]);
$button = new \single_button($addentrylink, get_string('add', 'mod_data'), 'get', true);
$button = new \single_button($addentrylink, get_string('add', 'mod_data'), 'get', \single_button::BUTTON_PRIMARY);
return $button->export_for_template($output);
}

Expand Down
Loading

0 comments on commit fc72a1d

Please sign in to comment.