From be8adf13735fa1be8dbc462f3898df8552057b8e Mon Sep 17 00:00:00 2001 From: David Woloszyn Date: Thu, 14 Aug 2025 14:24:19 +1000 Subject: [PATCH 1/4] MDL-85672 registration: Added new fields to registration form --- public/lang/en/deprecated.txt | 2 + public/lang/en/hub.php | 12 ++- public/lib/classes/hub/registration.php | 2 +- .../classes/hub/site_registration_form.php | 99 ++++++++++++++----- 4 files changed, 85 insertions(+), 30 deletions(-) diff --git a/public/lang/en/deprecated.txt b/public/lang/en/deprecated.txt index ac8425875da..e621a89ac43 100644 --- a/public/lang/en/deprecated.txt +++ b/public/lang/en/deprecated.txt @@ -88,3 +88,5 @@ activities_help,core resources_help,core unabletomessage,core_message notificationimage,core_message +sitename,core_hub +sitename_help,core_hub diff --git a/public/lang/en/hub.php b/public/lang/en/hub.php index d6f60c898a4..4e57b4d21f1 100644 --- a/public/lang/en/hub.php +++ b/public/lang/en/hub.php @@ -95,6 +95,8 @@ $string['nocheckstatusfromunreghub'] = 'The site is not registered on the hub so $string['nohubselected'] = 'No hub selected'; $string['none'] = 'None'; $string['operation'] = 'Actions'; +$string['organisationname'] = 'Organisation name'; +$string['organisationname_help'] = 'The name of the organisation registering this site. If you choose to have your site listed, this will be the name that is listed.'; $string['participantnumberaverage'] = 'Average number of participants ({$a})'; $string['pluginusagedata'] = 'Plugin usage data collected from: Plugins overview, Manage activities, and Manage blocks'; $string['policyagreed'] = 'Privacy notice and data processing agreement'; @@ -147,8 +149,6 @@ $string['siteemail'] = 'Admin email address'; $string['siteemail_help'] = 'An email address is necessary so that Moodle HQ can contact you if required. It may also be used for other purposes as you allow below. We recommend a generic email address related to a position (eg.: sitemanager@example.com), not a personal address.'; $string['sitelang'] = 'Language'; $string['sitelang_help'] = 'What is the main language used on your Moodle site?'; -$string['sitename'] = 'Name'; -$string['sitename_help'] = 'The name of the site will be shown on the site listing if the hub allows that.'; $string['siteorganisationtype'] = 'Organisation type'; $string['siteorganisationtype:charityornotforprofit'] = 'Charity or Not For Profit'; $string['siteorganisationtype:charterschool'] = 'Charter school'; @@ -174,9 +174,9 @@ $string['sitephone'] = 'Phone'; $string['sitephone_help'] = 'Your phone number will only be seen by the hub administrator.'; $string['siteprivacy'] = 'Site listing'; $string['siteprivacy_help'] = 'You can choose to have your site listed publicly in the list of registered sites, with or without a link to your site.'; +$string['siteprivacylinked'] = 'Display my organisation name with a link'; $string['siteprivacynotpublished'] = 'Do not list my site'; -$string['siteprivacypublished'] = 'Only display my site name'; -$string['siteprivacylinked'] = 'Display my site name with the link'; +$string['siteprivacypublished'] = 'Only display my organisation name'; $string['siteregistrationemail'] = 'Notifications of new Moodle releases, security alerts and other important news'; $string['siteregistrationemail_help'] = 'You have the option of subscribing to our low-volume mailing list for notifications of new Moodle releases, security alerts and other important news. You may unsubscribe at any time.'; $string['siteregistrationupdated'] = 'Site registration updated'; @@ -218,3 +218,7 @@ $string['aiusagestats'] = 'AI usage stats ({$a->timefrom} - {$a->timeto})'; $string['sitecommnews'] = 'Moodle newsletter'; $string['sitecommnews_help'] = 'You have the option of subscribing to our Moodle newsletter. You may unsubscribe at any time.'; $string['sitecommnewsyes'] = 'Yes, I would like to receive the Moodle newsletter'; + +// Deprecated since 5.1. +$string['sitename'] = 'Name'; +$string['sitename_help'] = 'The name of the site will be shown on the site listing if the hub allows that.'; diff --git a/public/lib/classes/hub/registration.php b/public/lib/classes/hub/registration.php index 9c9231be568..7d947457a59 100644 --- a/public/lib/classes/hub/registration.php +++ b/public/lib/classes/hub/registration.php @@ -46,7 +46,7 @@ class registration { const FORM_FIELDS = ['policyagreed', 'language', 'countrycode', 'privacy', 'contactemail', 'emailalert', 'emailalertemail', 'commnews', 'commnewsemail', 'contactname', 'name', 'description', 'imageurl', 'contactphone', 'regioncode', - 'geolocation', 'street', 'organisationtype']; + 'geolocation', 'street', 'organisationtype', 'commnewsfirstname', 'commnewslastname']; /** @var array List of new FORM_FIELDS or siteinfo fields added indexed by the version when they were added. * If site was already registered, admin will be promted to confirm new registration data manually. Until registration is manually confirmed, diff --git a/public/lib/classes/hub/site_registration_form.php b/public/lib/classes/hub/site_registration_form.php index c6d5ab5cb2a..e6b46169328 100644 --- a/public/lib/classes/hub/site_registration_form.php +++ b/public/lib/classes/hub/site_registration_form.php @@ -77,10 +77,10 @@ class site_registration_form extends \moodleform { $mform->addElement('header', 'moodle', get_string('registrationinfo', 'hub')); - $mform->addElement('text', 'name', get_string('sitename', 'hub'), + $mform->addElement('text', 'name', get_string('organisationname', 'hub'), array('class' => 'registration_textfield', 'maxlength' => 255)); $mform->setType('name', PARAM_TEXT); - $mform->addHelpButton('name', 'sitename', 'hub'); + $mform->addHelpButton('name', 'organisationname', 'hub'); $organisationtypes = registration::get_site_organisation_type_options(); \core_collator::asort($organisationtypes); @@ -140,17 +140,47 @@ class site_registration_form extends \moodleform { $mform->setType('contactemail', PARAM_EMAIL); $mform->addHelpButton('contactemail', 'siteemail', 'hub'); - $this->add_checkbox_with_email('emailalert', 'siteregistrationemail', false, get_string('registrationyes')); + $mform->addElement('html', html_writer::empty_tag('hr')); + // Admin notification emails. + $mform->addElement('checkbox', 'emailalert', get_string('siteregistrationemail', 'hub'), get_string('registrationyes')); + $mform->setDefault('emailalert', 1); + $mform->addElement('checkbox', 'emailalertdifferentemail', get_string('email'), + get_string('usedifferentemail', 'hub')); + $mform->hideif('emailalertdifferentemail', 'emailalert', 'notchecked'); + + $mform->addElement('text', 'emailalertemail', '', ['maxlength' => 100]); + $mform->setType('emailalertemail', PARAM_RAW_TRIMMED); + $mform->hideif('emailalertemail', 'emailalertdifferentemail', 'notchecked'); + $mform->hideif('emailalertemail', 'emailalert', 'notchecked'); + + $mform->addElement('html', html_writer::empty_tag('hr')); + + // Communication news emails (expert tips). $privacyurl = new moodle_url('https://moodle.com/privacy-notice/'); $experttipsandinsightsdesc = html_writer::span(get_string('experttipsandinsightsdesc', 'hub', $privacyurl->out())); - $this->add_checkbox_with_email( - elementname: 'commnews', - stridentifier: 'experttipsandinsights', - highlight: in_array('commnews', $highlightfields), - checkboxtext: $experttipsandinsightsdesc, - showhelp: false, - ); + $mform->addElement('checkbox', 'commnews', get_string('experttipsandinsights', 'hub'), $experttipsandinsightsdesc); + + $mform->addElement('text', 'commnewsfirstname', get_string('firstname'), ['maxlength' => 100]); + $mform->setType('commnewsfirstname', PARAM_TEXT); + $mform->hideif('commnewsfirstname', 'commnews', 'notchecked'); + $mform->setDefault('commnewsfirstname', $admin->firstname); + + $mform->addElement('text', 'commnewslastname', get_string('lastname'), ['maxlength' => 100]); + $mform->setType('commnewslastname', PARAM_TEXT); + $mform->hideif('commnewslastname', 'commnews', 'notchecked'); + $mform->setDefault('commnewslastname', $admin->lastname); + + $mform->addElement('checkbox', 'commnewsdifferentemail', get_string('email'), + get_string('usedifferentemail', 'hub')); + $mform->hideif('commnewsdifferentemail', 'commnews', 'notchecked'); + + $mform->addElement('text', 'commnewsemail', '', ['maxlength' => 100]); + $mform->setType('commnewsemail', PARAM_RAW_TRIMMED); + $mform->hideif('commnewsemail', 'commnewsdifferentemail', 'notchecked'); + $mform->hideif('commnewsemail', 'commnews', 'notchecked'); + + $mform->addElement('html', html_writer::empty_tag('hr')); // TODO site logo. $mform->addElement('hidden', 'imageurl', ''); // TODO: temporary. @@ -183,12 +213,13 @@ class site_registration_form extends \moodleform { $mform->setType('returnurl', PARAM_LOCALURL); // Prepare and set data. - $siteinfo['emailalertnewemail'] = !empty($siteinfo['emailalert']) && !empty($siteinfo['emailalertemail']); - if (empty($siteinfo['emailalertnewemail'])) { + // We don't store some checkbox values. Set the checkboxes depending on other stored settings. + $siteinfo['emailalertdifferentemail'] = !empty($siteinfo['emailalert']) && !empty($siteinfo['emailalertemail']); + if (empty($siteinfo['emailalertdifferentemail'])) { $siteinfo['emailalertemail'] = ''; } - $siteinfo['commnewsnewemail'] = !empty($siteinfo['commnews']) && !empty($siteinfo['commnewsemail']); - if (empty($siteinfo['commnewsnewemail'])) { + $siteinfo['commnewsdifferentemail'] = !empty($siteinfo['commnews']) && !empty($siteinfo['commnewsemail']); + if (empty($siteinfo['commnewsdifferentemail'])) { $siteinfo['commnewsemail'] = ''; } @@ -261,11 +292,11 @@ class site_registration_form extends \moodleform { public function validation($data, $files) { $errors = parent::validation($data, $files); // Validate optional emails. We do not use PARAM_EMAIL because it blindly clears the field if it is not a valid email. - if (!empty($data['emailalert']) && !empty($data['emailalertnewemail']) && !validate_email($data['emailalertemail'])) { - $errors['emailalertgroup'] = get_string('invalidemail'); + if (!empty($data['emailalert']) && !empty($data['emailalertdifferentemail']) && !validate_email($data['emailalertemail'])) { + $errors['emailalertemail'] = get_string('invalidemail'); } - if (!empty($data['commnews']) && !empty($data['commnewsnewemail']) && !validate_email($data['commnewsemail'])) { - $errors['commnewsgroup'] = get_string('invalidemail'); + if (!empty($data['commnews']) && !empty($data['commnewsdifferentemail']) && !validate_email($data['commnewsemail'])) { + $errors['commnewsemail'] = get_string('invalidemail'); } return $errors; } @@ -277,15 +308,33 @@ class site_registration_form extends \moodleform { */ public function get_data() { if ($data = parent::get_data()) { - // Never return '*newemail' checkboxes, always return 'emailalertemail' and 'commnewsemail' even if not applicable. - if (empty($data->emailalert) || empty($data->emailalertnewemail)) { - $data->emailalertemail = null; + // Ensure emailalert values are sent to the hub (when checkbox is unticked). + if (!isset($data->emailalert)) { + $data->emailalert = 0; } - unset($data->emailalertnewemail); - if (empty($data->commnews) || empty($data->commnewsnewemail)) { - $data->commnewsemail = null; + + // Ensure commnews values are sent to the hub (when checkbox is unticked). + if (!isset($data->commnews)) { + $data->commnews = 0; + } + + // Reset the emailalertemail email address if emailalertdifferentemail is not ticked. + if (empty($data->emailalertdifferentemail)) { + $data->emailalertemail = ''; + } + unset($data->emailalertdifferentemail); + + // Reset the commnewsemail email address if commnewsdifferentemail is not ticked. + if (empty($data->commnewsdifferentemail)) { + $data->commnewsemail = ''; + } + unset($data->commnewsdifferentemail); + + // Reset contact details if commnews is not ticked. + if (empty($data->commnews)) { + $data->commnewsfirstname = ''; + $data->commnewslastname = ''; } - unset($data->commnewsnewemail); if (debugging('', DEBUG_DEVELOPER)) { // Display debugging message for developers who added fields to the form and forgot to add them to registration::FORM_FIELDS. From 861ae42967a851c02f38ced42e59b3d640d97285 Mon Sep 17 00:00:00 2001 From: David Woloszyn Date: Thu, 14 Aug 2025 14:34:46 +1000 Subject: [PATCH 2/4] MDL-85672 registration: Remove unused methods from form class --- .../classes/hub/site_registration_form.php | 54 ------------------- 1 file changed, 54 deletions(-) diff --git a/public/lib/classes/hub/site_registration_form.php b/public/lib/classes/hub/site_registration_form.php index e6b46169328..1b3ff1ce270 100644 --- a/public/lib/classes/hub/site_registration_form.php +++ b/public/lib/classes/hub/site_registration_form.php @@ -227,60 +227,6 @@ class site_registration_form extends \moodleform { $this->set_data(['policyagreed' => 0] + $siteinfo); } - /** - * @deprecated since Moodle 3.11 - MDL-71460 The form elements using this have been converted to checkboxes - */ - #[\core\attribute\deprecated( - '\core\hub\site_registration_form::add_checkbox_with_email()', - since: '3.11', - mdl: 'MDL-71460', - final: true, - )] - protected function add_select_with_email() { - \core\deprecation::emit_deprecation([self::class, __FUNCTION__]); - } - - /** - * 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. - * @param bool $showhelp Show the help icon. - */ - protected function add_checkbox_with_email( - string $elementname, - string $stridentifier, - bool $highlight = false, - string $checkboxtext = '', - bool $showhelp = true, - ): void { - $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(). - if ($showhelp) { - $mform->addHelpButton($elementname . 'group', $stridentifier, 'hub'); - } - - } - /** * Validation of the form data * From ac9dfd7f857b19aa9c5d86b1f1e8b29d58519238 Mon Sep 17 00:00:00 2001 From: David Woloszyn Date: Wed, 20 Aug 2025 15:17:13 +1000 Subject: [PATCH 3/4] MDL-85672 registration: Fix Cibot format errors --- .../classes/hub/site_registration_form.php | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/public/lib/classes/hub/site_registration_form.php b/public/lib/classes/hub/site_registration_form.php index 1b3ff1ce270..e91ae290cbe 100644 --- a/public/lib/classes/hub/site_registration_form.php +++ b/public/lib/classes/hub/site_registration_form.php @@ -77,8 +77,12 @@ class site_registration_form extends \moodleform { $mform->addElement('header', 'moodle', get_string('registrationinfo', 'hub')); - $mform->addElement('text', 'name', get_string('organisationname', 'hub'), - array('class' => 'registration_textfield', 'maxlength' => 255)); + $mform->addElement( + 'text', + 'name', + get_string('organisationname', 'hub'), + ['class' => 'registration_textfield', 'maxlength' => 255], + ); $mform->setType('name', PARAM_TEXT); $mform->addHelpButton('name', 'organisationname', 'hub'); @@ -95,8 +99,7 @@ class site_registration_form extends \moodleform { $mform->addHelpButton('privacy', 'siteprivacy', 'hub'); unset($options); - $mform->addElement('textarea', 'description', get_string('sitedesc', 'hub'), - array('rows' => 3, 'cols' => 41)); + $mform->addElement('textarea', 'description', get_string('sitedesc', 'hub'), ['rows' => 3, 'cols' => 41]); $mform->setType('description', PARAM_TEXT); $mform->addHelpButton('description', 'sitedesc', 'hub'); @@ -134,8 +137,7 @@ class site_registration_form extends \moodleform { $mform->setType('contactphone', PARAM_TEXT); $mform->addHelpButton('contactphone', 'sitephone', 'hub'); - $mform->addElement('text', 'contactemail', get_string('siteemail', 'hub'), - array('class' => 'registration_textfield')); + $mform->addElement('text', 'contactemail', get_string('siteemail', 'hub'), ['class' => 'registration_textfield']); $mform->addRule('contactemail', $strrequired, 'required', null, 'client'); $mform->setType('contactemail', PARAM_EMAIL); $mform->addHelpButton('contactemail', 'siteemail', 'hub'); @@ -145,8 +147,7 @@ class site_registration_form extends \moodleform { // Admin notification emails. $mform->addElement('checkbox', 'emailalert', get_string('siteregistrationemail', 'hub'), get_string('registrationyes')); $mform->setDefault('emailalert', 1); - $mform->addElement('checkbox', 'emailalertdifferentemail', get_string('email'), - get_string('usedifferentemail', 'hub')); + $mform->addElement('checkbox', 'emailalertdifferentemail', get_string('email'), get_string('usedifferentemail', 'hub')); $mform->hideif('emailalertdifferentemail', 'emailalert', 'notchecked'); $mform->addElement('text', 'emailalertemail', '', ['maxlength' => 100]); @@ -171,8 +172,7 @@ class site_registration_form extends \moodleform { $mform->hideif('commnewslastname', 'commnews', 'notchecked'); $mform->setDefault('commnewslastname', $admin->lastname); - $mform->addElement('checkbox', 'commnewsdifferentemail', get_string('email'), - get_string('usedifferentemail', 'hub')); + $mform->addElement('checkbox', 'commnewsdifferentemail', get_string('email'), get_string('usedifferentemail', 'hub')); $mform->hideif('commnewsdifferentemail', 'commnews', 'notchecked'); $mform->addElement('text', 'commnewsemail', '', ['maxlength' => 100]); @@ -186,8 +186,12 @@ class site_registration_form extends \moodleform { $mform->addElement('hidden', 'imageurl', ''); // TODO: temporary. $mform->setType('imageurl', PARAM_URL); - $mform->addElement('checkbox', 'policyagreed', get_string('policyagreed', 'hub'), - get_string('policyagreeddesc', 'hub', HUB_MOODLEORGHUBURL . '/privacy')); + $mform->addElement( + 'checkbox', + 'policyagreed', + get_string('policyagreed', 'hub'), + get_string('policyagreeddesc', 'hub', HUB_MOODLEORGHUBURL . '/privacy'), + ); $mform->addRule('policyagreed', $strrequired, 'required', null, 'client'); $mform->addElement('header', 'sitestats', get_string('sendfollowinginfo', 'hub')); @@ -196,7 +200,12 @@ class site_registration_form extends \moodleform { $mform->addHelpButton('urlstring', 'siteurl', 'hub'); // Display statistic that are going to be retrieve by the sites directory. - $mform->addElement('static', 'siteinfosummary', get_string('sendfollowinginfo', 'hub'), registration::get_stats_summary($siteinfo)); + $mform->addElement( + 'static', + 'siteinfosummary', + get_string('sendfollowinginfo', 'hub'), + registration::get_stats_summary($siteinfo), + ); // Check if it's a first registration or update. if ($registered) { From 234ea10c038c41b4846be09444590c3a8f74e5ef Mon Sep 17 00:00:00 2001 From: David Woloszyn Date: Mon, 25 Aug 2025 16:22:45 +1000 Subject: [PATCH 4/4] MDL-85672 registration: Agreement privacy notice URL updated --- public/lib/classes/hub/site_registration_form.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/lib/classes/hub/site_registration_form.php b/public/lib/classes/hub/site_registration_form.php index e91ae290cbe..e277b2b127f 100644 --- a/public/lib/classes/hub/site_registration_form.php +++ b/public/lib/classes/hub/site_registration_form.php @@ -190,7 +190,7 @@ class site_registration_form extends \moodleform { 'checkbox', 'policyagreed', get_string('policyagreed', 'hub'), - get_string('policyagreeddesc', 'hub', HUB_MOODLEORGHUBURL . '/privacy'), + get_string('policyagreeddesc', 'hub', $privacyurl->out()), ); $mform->addRule('policyagreed', $strrequired, 'required', null, 'client');