+
{{#pix}}t/stealth, core{{/pix}}{{#str}}hiddenoncoursepage{{/str}}
{{/modstealth}}
diff --git a/course/format/upgrade.txt b/course/format/upgrade.txt
index 6bd026461a2..84ab8791254 100644
--- a/course/format/upgrade.txt
+++ b/course/format/upgrade.txt
@@ -45,6 +45,8 @@ Some considerations about the activitybadge feature:
* New core_courseformat\base::get_format_string() to get strings that can be overridden by the format plugin.
The method will check first the string in the format_PLUGINNAME.php lang file and, if not, it will return the
core_courseformat string instead.
+* New course format output classes:
+ - core_courseformat\output\local\content\cm\visibility to display the activity availability.
=== 4.1 ===
* New \core_courseformat\stateupdates methods add_section_remove() and add_cm_remove() have been added to replace
diff --git a/course/lib.php b/course/lib.php
index 2fe83a0eaf2..f3373a97b02 100644
--- a/course/lib.php
+++ b/course/lib.php
@@ -1661,8 +1661,8 @@ function course_get_cm_edit_actions(cm_info $mod, $indent = -1, $sr = null) {
if (!isset($str)) {
$str = get_strings(
[
- 'delete', 'move', 'moveright', 'moveleft', 'editsettings', 'duplicate', 'modhide',
- 'makeavailable', 'makeunavailable', 'modshow', 'modshowcmtitle', 'makeavailablecmtitle',
+ 'delete', 'move', 'moveright', 'moveleft', 'editsettings',
+ 'duplicate', 'availability'
],
'moodle'
);
@@ -1759,76 +1759,16 @@ function course_get_cm_edit_actions(cm_info $mod, $indent = -1, $sr = null) {
// Hide/Show/Available/Unavailable.
if (has_capability('moodle/course:activityvisibility', $modcontext)) {
- $allowstealth = !empty($CFG->allowstealth) && $courseformat->allow_stealth_module_visibility($mod, $sectioninfo);
-
- $sectionvisible = $sectioninfo->visible;
- // The module on the course page may be in one of the following states:
- // - Available and displayed on the course page ($displayedoncoursepage);
- // - Not available and not displayed on the course page ($unavailable);
- // - Available but not displayed on the course page ($stealth) - this can also be a visible activity in a hidden section.
- $displayedoncoursepage = $mod->visible && $mod->visibleoncoursepage && $sectionvisible;
- $unavailable = !$mod->visible;
- $stealth = $mod->visible && (!$mod->visibleoncoursepage || !$sectionvisible);
- if ($displayedoncoursepage) {
- $actions['hide'] = new action_menu_link_secondary(
- new moodle_url($baseurl, array('hide' => $mod->id)),
- new pix_icon('t/hide', '', 'moodle', array('class' => 'iconsmall')),
- $str->modhide,
- [
- 'class' => 'editing_hide',
- 'data-action' => ($usecomponents) ? 'cmHide' : 'hide',
- 'data-id' => $mod->id,
- ]
- );
- } else if (!$displayedoncoursepage && $sectionvisible) {
- // Offer to "show" only if the section is visible.
- $actions['show'] = new action_menu_link_secondary(
- new moodle_url($baseurl, array('show' => $mod->id)),
- new pix_icon('t/show', '', 'moodle', array('class' => 'iconsmall')),
- $str->modshow,
- [
- 'class' => 'editing_show',
- 'data-action' => ($usecomponents) ? 'cmShow' : 'show',
- 'data-id' => $mod->id,
- // Title is needed mostly for behat tests. Otherwise it will follow any link with "show".
- 'title' => $str->modshowcmtitle,
- ]
- );
- }
-
- if ($stealth) {
- // When making the "stealth" module unavailable we perform the same action as hiding the visible module.
- $actions['hide'] = new action_menu_link_secondary(
- new moodle_url($baseurl, array('hide' => $mod->id)),
- new pix_icon('t/unblock', '', 'moodle', array('class' => 'iconsmall')),
- $str->makeunavailable,
- [
- 'class' => 'editing_makeunavailable',
- 'data-action' => ($usecomponents) ? 'cmHide' : 'hide',
- 'data-sectionreturn' => $sr,
- 'data-id' => $mod->id,
- ]
- );
- } else if ($unavailable && (!$sectionvisible || $allowstealth) && $mod->has_view()) {
- // Allow to make visually hidden module available in gradebook and other reports by making it a "stealth" module.
- // When the section is hidden it is an equivalent of "showing" the module.
- // Activities without the link (i.e. labels) can not be made available but hidden on course page.
- $action = $sectionvisible ? 'stealth' : 'show';
- if ($usecomponents) {
- $action = 'cm' . ucfirst($action);
- }
- $actions[$action] = new action_menu_link_secondary(
- new moodle_url($baseurl, array('stealth' => $mod->id)),
- new pix_icon('t/block', '', 'moodle', array('class' => 'iconsmall')),
- $str->makeavailable,
- [
- 'class' => 'editing_makeavailable',
- 'data-action' => $action,
- 'data-sectionreturn' => $sr,
- 'data-id' => $mod->id,
- // Title is needed mostly for behat tests. Otherwise it will follow any link with "make available".
- 'title' => $str->makeavailablecmtitle,
- ]
+ $availabilityclass = $courseformat->get_output_classname('content\\cm\\visibility');
+ /** @var core_courseformat\output\local\content\cm\visibility */
+ $availability = new $availabilityclass($courseformat, $sectioninfo, $mod);
+ $availabilitychoice = $availability->get_choice_list();
+ if ($availabilitychoice->count_options() > 1) {
+ $actions['availability'] = new action_menu_subpanel(
+ $str->availability,
+ $availabilitychoice,
+ ['class' => 'editing_availability'],
+ new pix_icon('t/hide', '', 'moodle', array('class' => 'iconsmall'))
);
}
}
diff --git a/lang/en/deprecated.txt b/lang/en/deprecated.txt
index a030d457c9f..8e825710064 100644
--- a/lang/en/deprecated.txt
+++ b/lang/en/deprecated.txt
@@ -84,3 +84,5 @@ backpackemail,core_badges
backpackemail_help,core_badges
editcoursecompletionsettings,core_completion
clicktochangeinbrackets,core
+modshowcmtitle,core
+makeavailablecmtitle,core
diff --git a/lang/en/moodle.php b/lang/en/moodle.php
index bcf6fbb02ff..c4dceb445f9 100644
--- a/lang/en/moodle.php
+++ b/lang/en/moodle.php
@@ -1248,7 +1248,6 @@ $string['mailteachers'] = 'Inform teachers';
$string['maincoursepage'] = 'Main course page';
$string['makeafolder'] = 'Create folder';
$string['makeavailable'] = 'Make available';
-$string['makeavailablecmtitle'] = 'Make activity available';
$string['makeeditable'] = 'If you make \'{$a}\' editable by the web server process (eg apache) then you could edit this file directly from this page';
$string['makethismyhome'] = 'Make this my home page';
$string['makeunavailable'] = 'Make unavailable';
@@ -1350,7 +1349,6 @@ $string['missingusername'] = 'Missing username';
$string['moddoesnotsupporttype'] = 'Module {$a->modname} does not support uploads of type {$a->type}';
$string['modhide'] = 'Hide';
$string['modshow'] = 'Show';
-$string['modshowcmtitle'] = 'Show activity';
$string['modvisible'] = 'Availability';
$string['modvisible_help'] = '* Show on course page: Available to students (subject to any access restrictions which may be set).
* Hide on course page: Not available to students.';
@@ -2452,3 +2450,5 @@ $string['supplyinfo'] = 'More details';
// Deprecated since Moodle 4.3.
$string['clicktochangeinbrackets'] = '{$a} (Click to change)';
+$string['modshowcmtitle'] = 'Show activity';
+$string['makeavailablecmtitle'] = 'Make activity available';
diff --git a/lib/classes/output/choicelist.php b/lib/classes/output/choicelist.php
index 6f3a032507c..ae38e786329 100644
--- a/lib/classes/output/choicelist.php
+++ b/lib/classes/output/choicelist.php
@@ -83,6 +83,14 @@ class choicelist implements renderable, named_templatable {
}
}
+ /**
+ * Get the number of options added to the choice list.
+ * @return int
+ */
+ public function count_options(): int {
+ return count($this->options);
+ }
+
/**
* Set the selected option.
*