-
Notifications
You must be signed in to change notification settings - Fork 638
[docs] Add developer documentation for course linear navigation support #1634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| --- | ||
| title: Linear navigation support | ||
| tags: | ||
| - Plugins | ||
| - Format | ||
| - Linear navigation | ||
| --- | ||
|
|
||
| <Since version="5.3" issueNumber="MDL-84921" /> | ||
|
sarjona marked this conversation as resolved.
|
||
|
|
||
| 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. | ||
|
|
||
| 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. | ||
|
|
||
| ## Opting into linear navigation | ||
|
|
||
| To support linear navigation, your course format must override the `uses_linear_navigation()` method in its format class (extending `\core_courseformat\base`). | ||
|
|
||
| ```php title="course/format/mycustomformat/lib.php" | ||
| /** | ||
| * Custom course format class. | ||
| */ | ||
| class format_mycustomformat extends \core_courseformat\base { | ||
| /** | ||
| * Determines whether the course format supports linear navigation. | ||
| * | ||
| * @return bool True if linear navigation is supported, false otherwise. | ||
| */ | ||
| public static function uses_linear_navigation(): bool { | ||
| // Return true to unconditionally enable it. | ||
| return true; | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Adding format-level configuration | ||
|
|
||
| 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`). | ||
|
|
||
| ```php title="course/format/mycustomformat/lib.php" | ||
| /** | ||
| * Define the format options for a course. | ||
| * | ||
| * @param bool $foreditform True if it's being requested for the course edit form. | ||
| * @return array Array of options. | ||
| */ | ||
| public function course_format_options($foreditform = false) { | ||
| static $courseformatoptions = false; | ||
| // Initialise the course format options array if it hasn't been done yet with the default values. | ||
| if ($courseformatoptions === false) { | ||
| // Get course format's settings. | ||
| $courseformatoptions = []; | ||
|
|
||
| // Add linear navigation settings if enabled for the format. | ||
| $courseformatoptions = array_merge( | ||
| \core_courseformat\local\linearnavigationsettings::get_course_format_options_default(self::get_format()), | ||
| $courseformatoptions, | ||
| ); | ||
|
|
||
| } | ||
|
|
||
| if ($foreditform) { | ||
| // Get the edit form options for the format. | ||
| $courseformatoptionsedit = []; | ||
|
|
||
| // Add course format settings. | ||
|
|
||
| // Append your format's explicit linear navigation setting override if desired, | ||
| // or rely on the core 'enablelinearnav' setting configuration. | ||
| $courseformatoptions = array_merge_recursive( | ||
| $courseformatoptionsedit, | ||
| \core_courseformat\local\linearnavigationsettings::get_course_format_options_edit_form(self::get_format()), | ||
| ); | ||
| } | ||
| return $courseformatoptions; | ||
| } | ||
| ``` | ||
|
|
||
| :::info[Adding site-wide administration settings] | ||
|
|
||
| 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. | ||
|
|
||
| ```php title="course/format/mycustomformat/settings.php" | ||
| $options = [ | ||
| 1 => get_string('yes'), | ||
| 0 => get_string('no'), | ||
| ]; | ||
|
|
||
| $settings->add(new admin_setting_configselect( | ||
| 'format_mycustomformat/enablelinearnav', | ||
| new lang_string('linearnavigationsettings', 'core_courseformat'), | ||
| new lang_string('linearnavigationsettings_help', 'core_courseformat'), | ||
| 1, | ||
| $options | ||
| )); | ||
| ``` | ||
|
|
||
| ::: | ||
|
|
||
| ## Controlling the page state rendering | ||
|
|
||
| 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: | ||
|
|
||
| ```php title="course/format/mycustomformat/mypluginpage.php" | ||
| // Explicitly suppress the navigation footer on a specific layout template | ||
| $PAGE->set_show_navigation_footer(false); | ||
| ``` | ||
|
|
||
| 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: | ||
|
|
||
| ```php title="course/format/mycustomformat/mypluginpage.php" | ||
|
|
||
| // Query if the navigation footer should be shown on the page. | ||
| if (\core_courseformat\local\linearnavigationsettings::show_navigation_footer($PAGE)) { | ||
| // Custom structural adjustments | ||
| } | ||
|
|
||
| // Check if linear navigation is enabled for the course. | ||
| // It only checks the course format and the linear navigation format option, regardless of any | ||
| // page-level state. It is useful for activities that need to adapt their output (for example, | ||
| // hiding navigation controls of their own) when linear navigation is enabled. | ||
| $linearnavigationenabled = \core_courseformat\local\linearnavigationsettings::is_linear_navigation_enabled($course); | ||
| if ($linearnavigationenabled) { | ||
| // Custom structural adjustments | ||
| } | ||
| ``` | ||
|
aanabit marked this conversation as resolved.
|
||
|
|
||
| ## Behat integration | ||
|
|
||
| The navigation feature includes dedicated steps to validate the execution layer within your functional test suites: | ||
|
|
||
| ```gherkin | ||
| And the course linear navigation should be visible | ||
| # Or to verify the disabled state: | ||
| And the course linear navigation should not be visible | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.