From 1dd574efd8bd41a3e02b583c3e7c21b368a5dd2e Mon Sep 17 00:00:00 2001 From: Peter Dias Date: Wed, 28 Apr 2021 10:04:07 +0800 Subject: [PATCH] MDL-71460 hub: Use checkboxes instead of dropdowns Change the yes/no dropdowns to a checkbox. Defaults to unchecked. --- lang/en/hub.php | 2 +- lib/classes/hub/site_registration_form.php | 51 +++++++++++++++++----- 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/lang/en/hub.php b/lang/en/hub.php index d083fd2c252..893a11fc8d6 100644 --- a/lang/en/hub.php +++ b/lang/en/hub.php @@ -120,7 +120,7 @@ $string['roleassignmentsnumber'] = 'Number of role assignments ({$a})'; $string['search'] = 'Search'; $string['sendingsize'] = 'Please wait the course file is uploading ({$a->total}Mb)...'; $string['sendfollowinginfo'] = 'More information'; -$string['sendfollowinginfo_help'] = 'The following information will be sent to contribute to overall statistics only. It will not be made public on any site listing.'; +$string['sendfollowinginfo_help'] = 'The following information will be sent to Moodle each time your site registration is updated (by default weekly, when the \'Site registration\' scheduled task is run). The information contributes to overall statistics only and will not be made public on any site listing.'; $string['sent'] = '...finished'; $string['siteadmin'] = 'Administrator'; $string['siteadmin_help'] = 'The full name of the site administrator.'; diff --git a/lib/classes/hub/site_registration_form.php b/lib/classes/hub/site_registration_form.php index f58f9ef9560..2121b714c14 100644 --- a/lib/classes/hub/site_registration_form.php +++ b/lib/classes/hub/site_registration_form.php @@ -63,8 +63,8 @@ class site_registration_form extends \moodleform { 'regioncode' => '-', // Not supported yet. 'language' => explode('_', current_language())[0], 'geolocation' => '', - 'emailalert' => 1, - 'commnews' => 1, + 'emailalert' => 0, + 'commnews' => 0, 'policyagreed' => 0 ]); @@ -138,15 +138,14 @@ class site_registration_form extends \moodleform { $mform->hideIf('contactable', 'privacy', 'eq', registration::HUB_SITENOTPUBLISHED); unset($options); - $this->add_select_with_email('emailalert', 'siteregistrationemail', [ - 0 => get_string('registrationno'), - 1 => get_string('registrationyes'), - ]); + $this->add_checkbox_with_email('emailalert', 'siteregistrationemail', false, get_string('registrationyes')); - $this->add_select_with_email('commnews', 'sitecommnews', [ - 0 => get_string('sitecommnewsno', 'hub'), - 1 => get_string('sitecommnewsyes', 'hub'), - ], in_array('commnews', $highlightfields)); + $this->add_checkbox_with_email( + 'commnews', + 'sitecommnews', + in_array('commnews', $highlightfields), + get_string('sitecommnewsyes', 'hub') + ); // TODO site logo. $mform->addElement('hidden', 'imageurl', ''); // TODO: temporary. @@ -228,6 +227,38 @@ class site_registration_form extends \moodleform { } + /** + * Add yes/no checkbox with additional checkbox allowing to specify another email + * + * @param string $elementname + * @param string $stridentifier + * @param bool $highlight highlight as a new field + * @param string $checkboxtext The text to show after the text. + */ + protected function add_checkbox_with_email($elementname, $stridentifier, $highlight = false, string $checkboxtext = '') { + $mform = $this->_form; + + $group = [ + $mform->createElement('advcheckbox', $elementname, '', $checkboxtext, ['class' => 'pt-2']), + $mform->createElement('static', $elementname . 'sep', '', '
'), + $mform->createElement('advcheckbox', $elementname . 'newemail', '', get_string('usedifferentemail', 'hub'), + ['onchange' => "this.form.elements['{$elementname}email'].focus();"]), + $mform->createElement('text', $elementname . 'email', get_string('email')) + ]; + + $element = $mform->addElement('group', $elementname . 'group', get_string($stridentifier, 'hub'), $group, '', false); + if ($highlight) { + $element->setAttributes(['class' => $element->getAttribute('class') . ' needsconfirmation mark']); + } + $mform->hideif($elementname . 'email', $elementname, 'eq', 0); + $mform->hideif($elementname . 'newemail', $elementname, 'eq', 0); + $mform->hideif($elementname . 'email', $elementname . 'newemail', 'notchecked'); + $mform->setType($elementname, PARAM_INT); + $mform->setType($elementname . 'email', PARAM_RAW_TRIMMED); // E-mail will be validated in validation(). + $mform->addHelpButton($elementname . 'group', $stridentifier, 'hub'); + + } + /** * Validation of the form data *