Skip to content

Commit 7875a10

Browse files
authored
Merge pull request #1634 from sarjona/linearnav
[docs] Add developer documentation for course linear navigation support
2 parents e8875cb + 0ca97eb commit 7875a10

3 files changed

Lines changed: 150 additions & 1 deletion

File tree

‎docs/apis/plugintypes/format/index.md‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ You must define `$string['sectionname']` if your language file even if the forma
197197
| `core_courseformat\base` Overridable method | Description |
198198
|---|---|
199199
| `uses_sections()` | returns true or false if the format uses sections or not. There is a global function <br/> `course_format_uses_sections()` that invokes it. It affects default navigation tree building. Various modules and reports may call this function to know whether to display the section name for the particular module or not. |
200+
| `uses_linear_navigation()` | Returns true if the course format explicitly supports the sequential linear navigation footer. If it returns false, linear navigation is completely deactivated for the format. |
200201
| `get_default_section_name()` | This method gets the default section name if the user has not provided a value for the section name. In format_base, it basically calls `get_section_name()`, which returns the `$string['sectionname']` + the section number of the current section, if available, or blank, otherwise. It can be used in conjunction with your course format's `get_section_name()` implementation. For reference, please refer to the implementations in format_topics and format_weeks classes. |
201202
| `get_section_name()` | Returns the name for a particular section. This function may be called often so it should use only fields cached in section_info object (field course_sections.name is always cached) <br/> In 3.0+, it checks if the `$string['sectionname']` is available in the lang file. If the section name string is not available, it returns an empty string. |
202203
| `get_view_url()` | Returns the URL for a particular section, it can be either anchored on course view page or separate page. See parent function PHPdocs for more details |
@@ -236,7 +237,7 @@ Webservices expect course format options to be passed in additional entities but
236237

237238
| `core_courseformat\base` Overridable method | Description |
238239
|---|---|
239-
| `course_format_options()` | By overriding this method course format specifies which additional options it has for course |
240+
| `course_format_options()` | By overriding this method course format specifies which additional options it has for course. It can also be used to inject linear navigation defaults using `\core_courseformat\local\linearnavigationsettings::get_course_format_options_default()`. |
240241
| `section_format_options()` | By overriding this method course format specifies which additional options it has for course section. Note that since section information is cached you may want to cache some additional options as well. See PHPdocs for more information |
241242
| `get_format_options()` | (usually no need to override) low level function to retrieve course format options values. It is more convenient to use methods get_course() and get_section() |
242243
| `create_edit_form_elements()` | This function is called to alter course edit form and standard section edit form. The default implementation creates simple form elements for each option defined in either `course_format_options()` or `section_format_options()`. Overwrite it if you want to have more comprehensive form elements or if you do not want options to appear in edit forms, etc. |
@@ -263,6 +264,10 @@ The format base class is used for all the core_courseformat integrations, from s
263264
| `is_section_current()` | Returns if a specific section is marked as current (highlighted) or not. |
264265
| `show_editor()` | Do all the user and page validations to know if the current course display has to include editor options or not. This includes both page editing mode and user capabilities. You can pass an array of capabilities which should be checked. If none specified, will default to `moodle/course:manageactivities`. |
265266

267+
:::tip[Linear navigation feature integration]
268+
For a comprehensive integration guide, structural configuration examples, and admin `settings.php` file entry setups, see the [Linear navigation support guide](./linear_navigation.md).
269+
:::
270+
266271
## Rendering a course {/* #rendering-a-course */}
267272

268273
Each format plugin is responsible for rendering the course in the format.php file, this means each plugin can choose how to render the course content. However, there are some conventions on how a course should be rendered to integrate the plugin with the existing components.
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
---
2+
title: Linear navigation support
3+
tags:
4+
- Plugins
5+
- Format
6+
- Linear navigation
7+
---
8+
9+
<Since version="5.3" issueNumber="MDL-84921" />
10+
11+
The linear course navigation feature provides an intuitive, forward-and-backward navigation footer within courses. It allows users to cycle through sections or activities sequentially without returning to the main page.
12+
13+
By default, third-party course formats do not display the linear navigation elements. To enable and support this feature within a custom course format, your plugin's format class must explicitly opt in.
14+
15+
## Opting into linear navigation
16+
17+
To support linear navigation, your course format must override the `uses_linear_navigation()` method in its format class (extending `\core_courseformat\base`).
18+
19+
```php title="course/format/mycustomformat/lib.php"
20+
/**
21+
* Custom course format class.
22+
*/
23+
class format_mycustomformat extends \core_courseformat\base {
24+
/**
25+
* Determines whether the course format supports linear navigation.
26+
*
27+
* @return bool True if linear navigation is supported, false otherwise.
28+
*/
29+
public static function uses_linear_navigation(): bool {
30+
// Return true to unconditionally enable it.
31+
return true;
32+
}
33+
}
34+
```
35+
36+
## Adding format-level configuration
37+
38+
If your course format requires configuration at the course settings level (similar to how `format_topics` and `format_weeks` handle it), you should integrate it into your format's native settings framework (`course_format_options`).
39+
40+
```php title="course/format/mycustomformat/lib.php"
41+
/**
42+
* Define the format options for a course.
43+
*
44+
* @param bool $foreditform True if it's being requested for the course edit form.
45+
* @return array Array of options.
46+
*/
47+
public function course_format_options($foreditform = false) {
48+
static $courseformatoptions = false;
49+
// Initialise the course format options array if it hasn't been done yet with the default values.
50+
if ($courseformatoptions === false) {
51+
// Get course format's settings.
52+
$courseformatoptions = [];
53+
54+
// Add linear navigation settings if enabled for the format.
55+
$courseformatoptions = array_merge(
56+
\core_courseformat\local\linearnavigationsettings::get_course_format_options_default(self::get_format()),
57+
$courseformatoptions,
58+
);
59+
60+
}
61+
62+
if ($foreditform) {
63+
// Get the edit form options for the format.
64+
$courseformatoptionsedit = [];
65+
66+
// Add course format settings.
67+
68+
// Append your format's explicit linear navigation setting override if desired,
69+
// or rely on the core 'enablelinearnav' setting configuration.
70+
$courseformatoptions = array_merge_recursive(
71+
$courseformatoptionsedit,
72+
\core_courseformat\local\linearnavigationsettings::get_course_format_options_edit_form(self::get_format()),
73+
);
74+
}
75+
return $courseformatoptions;
76+
}
77+
```
78+
79+
:::info[Adding site-wide administration settings]
80+
81+
To allow administrators to enable, disable, or define the default state for linear navigation within your custom format, add the configuration option to your plugin's settings.php file.
82+
83+
```php title="course/format/mycustomformat/settings.php"
84+
$options = [
85+
1 => get_string('yes'),
86+
0 => get_string('no'),
87+
];
88+
89+
$settings->add(new admin_setting_configselect(
90+
'format_mycustomformat/enablelinearnav',
91+
new lang_string('linearnavigationsettings', 'core_courseformat'),
92+
new lang_string('linearnavigationsettings_help', 'core_courseformat'),
93+
1,
94+
$options
95+
));
96+
```
97+
98+
:::
99+
100+
## Controlling the page state rendering
101+
102+
The core output requirements verify format capabilities during execution. If you need to programmatically suppress or alter the navigation footer layout from specific views or custom renderers inside your format, utilise the page output control methods:
103+
104+
```php title="course/format/mycustomformat/mypluginpage.php"
105+
// Explicitly suppress the navigation footer on a specific layout template
106+
$PAGE->set_show_navigation_footer(false);
107+
```
108+
109+
The following methods can be used to check the state of linear navigation and control the rendering of the navigation footer on a per-page basis:
110+
111+
```php title="course/format/mycustomformat/mypluginpage.php"
112+
113+
// Query if the navigation footer should be shown on the page.
114+
if (\core_courseformat\local\linearnavigationsettings::show_navigation_footer($PAGE)) {
115+
// Custom structural adjustments
116+
}
117+
118+
// Check if linear navigation is enabled for the course.
119+
// It only checks the course format and the linear navigation format option, regardless of any
120+
// page-level state. It is useful for activities that need to adapt their output (for example,
121+
// hiding navigation controls of their own) when linear navigation is enabled.
122+
$linearnavigationenabled = \core_courseformat\local\linearnavigationsettings::is_linear_navigation_enabled($course);
123+
if ($linearnavigationenabled) {
124+
// Custom structural adjustments
125+
}
126+
```
127+
128+
## Behat integration
129+
130+
The navigation feature includes dedicated steps to validate the execution layer within your functional test suites:
131+
132+
```gherkin
133+
And the course linear navigation should be visible
134+
# Or to verify the disabled state:
135+
And the course linear navigation should not be visible
136+
```

‎docs/devupdate.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,11 @@ tags:
88
{/* <!-- markdownlint-disable no-inline-html --> */}
99

1010
This page highlights the important changes that are coming in Moodle 5.3 for developers.
11+
12+
## Linear navigation support
13+
14+
<Since version="5.3" issueNumber="MDL-84921" />
15+
16+
Moodle 5.3 introduces support for sequential linear navigation controls within course views. By default, third-party course formats do not display linear navigation elements. To explicitly opt in and declare support for this feature, course formats must override the `uses_linear_navigation()` method.
17+
18+
For a comprehensive integration guide, structural configuration examples, and page-state API controls, see the [Linear navigation support guide](./apis/plugintypes/format/linear_navigation.md).

0 commit comments

Comments
 (0)