From 36b865b3d90f1a0561b01c88b0be59d662a8598d Mon Sep 17 00:00:00 2001 From: Amaia Anabitarte Date: Fri, 28 Jul 2023 13:00:20 +0200 Subject: [PATCH 1/2] MDL-78746 formslib: add variables to addHelpButton() addHelpButton() function should allow to get variables to pass to get_string to improve help button text. --- lib/formslib.php | 13 +++++++++++-- lib/outputcomponents.php | 14 +++++++++++--- lib/outputrenderers.php | 8 +++++--- lib/upgrade.txt | 2 ++ 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/lib/formslib.php b/lib/formslib.php index bba17179d20..2eb2f78bd0d 100644 --- a/lib/formslib.php +++ b/lib/formslib.php @@ -2354,12 +2354,21 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless { * @param string $component component name to look the help string in * @param string $linktext optional text to display next to the icon * @param bool $suppresscheck set to true if the element may not exist + * @param string|object|array|int $a An object, string or number that can be used + * within translation strings */ - function addHelpButton($elementname, $identifier, $component = 'moodle', $linktext = '', $suppresscheck = false) { + public function addHelpButton( + $elementname, + $identifier, + $component = 'moodle', + $linktext = '', + $suppresscheck = false, + $a = null + ) { global $OUTPUT; if (array_key_exists($elementname, $this->_elementIndex)) { $element = $this->_elements[$this->_elementIndex[$elementname]]; - $element->_helpbutton = $OUTPUT->help_icon($identifier, $component, $linktext); + $element->_helpbutton = $OUTPUT->help_icon($identifier, $component, $linktext, $a); } else if (!$suppresscheck) { debugging(get_string('nonexistentformelements', 'form', $elementname)); } diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php index a9090f21ab9..73480ad18e2 100644 --- a/lib/outputcomponents.php +++ b/lib/outputcomponents.php @@ -456,6 +456,11 @@ class help_icon implements renderable, templatable { */ public $linktext = null; + /** + * @var mixed An object, string or number that can be used within translation strings + */ + public $a = null; + /** * Constructor * @@ -463,10 +468,13 @@ class help_icon implements renderable, templatable { * string with _help suffix is used for the actual help text. * string with _link suffix is used to create a link to further info (if it exists) * @param string $component + * @param string|object|array|int $a An object, string or number that can be used + * within translation strings */ - public function __construct($identifier, $component) { + public function __construct($identifier, $component, $a = null) { $this->identifier = $identifier; $this->component = $component; + $this->a = $a; } /** @@ -491,7 +499,7 @@ class help_icon implements renderable, templatable { public function export_for_template(renderer_base $output) { global $CFG; - $title = get_string($this->identifier, $this->component); + $title = get_string($this->identifier, $this->component, $this->a); if (empty($this->linktext)) { $alt = get_string('helpprefix2', '', trim($title, ". \t")); @@ -499,7 +507,7 @@ class help_icon implements renderable, templatable { $alt = get_string('helpwiththis'); } - $data = get_formatted_help_string($this->identifier, $this->component, false); + $data = get_formatted_help_string($this->identifier, $this->component, false, $this->a); $data->alt = $alt; $data->icon = (new pix_icon('help', $alt, 'core', ['class' => 'iconhelp']))->export_for_template($output); diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index b1cbf57c290..59bfce5ce7d 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -2521,13 +2521,15 @@ class core_renderer extends renderer_base { * @param string $identifier The keyword that defines a help page * @param string $component component name * @param string|bool $linktext true means use $title as link text, string means link text value + * @param string|object|array|int $a An object, string or number that can be used + * within translation strings * @return string HTML fragment */ - public function help_icon($identifier, $component = 'moodle', $linktext = '') { - $icon = new help_icon($identifier, $component); + public function help_icon($identifier, $component = 'moodle', $linktext = '', $a = null) { + $icon = new help_icon($identifier, $component, $a); $icon->diag_strings(); if ($linktext === true) { - $icon->linktext = get_string($icon->identifier, $icon->component); + $icon->linktext = get_string($icon->identifier, $icon->component, $a); } else if (!empty($linktext)) { $icon->linktext = $linktext; } diff --git a/lib/upgrade.txt b/lib/upgrade.txt index d3b98f88f60..25aa49ddf9d 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -71,6 +71,8 @@ information provided here is intended especially for developers. * The moodle-core-notification-confirm module, found under the M.core.confirm namespace, has been deprecated. Any code using it should be rewritten as an ESM and use the core/notification module instead. See MDL-77174 for further information. +* addHelpButton() function has a new optional $a parameter to allow variables with translation strings. +* help_icon constructor has a new optional $a parameter to allow variables with translation strings. === 4.2 === From 040a27fb7605d20a1b511899d8ef8c7c032dc368 Mon Sep 17 00:00:00 2001 From: Amaia Anabitarte Date: Tue, 1 Aug 2023 12:22:22 +0200 Subject: [PATCH 2/2] MDL-78746 core_completion: Improve completion reminder information --- completion/classes/form/form_trait.php | 5 +++-- lang/en/completion.php | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/completion/classes/form/form_trait.php b/completion/classes/form/form_trait.php index 166f010d23c..e539767d74c 100644 --- a/completion/classes/form/form_trait.php +++ b/completion/classes/form/form_trait.php @@ -207,8 +207,9 @@ trait form_trait { $completionexpectedel = 'completionexpected' . $suffix; $mform->addElement('date_time_selector', $completionexpectedel, get_string('completionexpected', 'completion'), ['optional' => true]); - $mform->addHelpButton($completionexpectedel, 'completionexpected', 'completion'); - $mform->hideIf($completionexpectedel, $completionel, 'eq', COMPLETION_TRACKING_NONE); + $a = get_string('pluginname', $modname); + $mform->addHelpButton($completionexpectedel, 'completionexpected', 'completion', '', false, $a); + $mform->hideIf($completionexpectedel, 'completion', 'eq', COMPLETION_TRACKING_NONE); } /** diff --git a/lang/en/completion.php b/lang/en/completion.php index e0a51ec14db..2dd328ef491 100644 --- a/lang/en/completion.php +++ b/lang/en/completion.php @@ -90,8 +90,8 @@ $string['completionactivitydefault'] = 'Use activity default'; $string['completiondefault'] = 'Default completion tracking'; $string['completiondisabled'] = 'Disabled, not shown in activity settings'; $string['completionenabled'] = 'Enabled, control via completion and activity settings'; -$string['completionexpected'] = 'Expect completed on'; -$string['completionexpected_help'] = 'This setting specifies the date when the activity is expected to be completed. When the date is upcoming, the activity is listed in the Timeline block on the Dashboard.'; +$string['completionexpected'] = 'Set reminder in Timeline'; +$string['completionexpected_help'] = 'This allows you to set a reminder for students to work on this activity. It will appear on the Timeline block in their Dashboard as "{$a} requires action"'; $string['completionexpecteddesc'] = 'Completion expected on {$a}'; $string['completionexpectedfor'] = '{$a->instancename} should be completed'; $string['completionicons'] = 'Completion tick boxes';