diff --git a/public/lang/en/deprecated.txt b/public/lang/en/deprecated.txt
index a857c67f778..ac089b4c3bb 100644
--- a/public/lang/en/deprecated.txt
+++ b/public/lang/en/deprecated.txt
@@ -92,3 +92,5 @@ hiddensections_help,core
privacy:metadata:schedule:message,core_reportbuilder
privacy:metadata:schedule:reportempty,core_reportbuilder
privacy:metadata:schedule:subject,core_reportbuilder
+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 0266d8dd183..e277b2b127f 100644
--- a/public/lib/classes/hub/site_registration_form.php
+++ b/public/lib/classes/hub/site_registration_form.php
@@ -77,10 +77,14 @@ class site_registration_form extends \moodleform {
$mform->addElement('header', 'moodle', get_string('registrationinfo', 'hub'));
- $mform->addElement('text', 'name', get_string('sitename', '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', 'sitename', 'hub');
+ $mform->addHelpButton('name', 'organisationname', 'hub');
$organisationtypes = registration::get_site_organisation_type_options();
\core_collator::asort($organisationtypes);
@@ -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,30 +137,61 @@ 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');
- $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.
$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', $privacyurl->out()),
+ );
$mform->addRule('policyagreed', $strrequired, 'required', null, 'client');
$mform->addElement('header', 'sitestats', get_string('sendfollowinginfo', 'hub'));
@@ -166,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) {
@@ -183,12 +222,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'] = '';
}
@@ -196,60 +236,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
*
@@ -261,11 +247,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 +263,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)) {
+ // Ensure emailalert values are sent to the hub (when checkbox is unticked).
+ if (!isset($data->emailalert)) {
+ $data->emailalert = 0;
+ }
+
+ // 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->emailalertnewemail);
- if (empty($data->commnews) || empty($data->commnewsnewemail)) {
+ unset($data->emailalertdifferentemail);
+
+ // Reset the commnewsemail email address if commnewsdifferentemail is not ticked.
+ if (empty($data->commnewsdifferentemail)) {
$data->commnewsemail = '';
}
- unset($data->commnewsnewemail);
+ unset($data->commnewsdifferentemail);
+
+ // Reset contact details if commnews is not ticked.
+ if (empty($data->commnews)) {
+ $data->commnewsfirstname = '';
+ $data->commnewslastname = '';
+ }
if (debugging('', DEBUG_DEVELOPER)) {
// Display debugging message for developers who added fields to the form and forgot to add them to registration::FORM_FIELDS.