Skip to content

Commit aea3c4c

Browse files
authored
Merge pull request #9 from moodlemobile/MOBILE-4323
MOBILE-4323 enrol: Document CoreEnrolDelegate for plugins
2 parents a4fd6cd + 08f2452 commit aea3c4c

File tree

1 file changed

+65
-0
lines changed
  • general/app/development/plugins-development-guide

1 file changed

+65
-0
lines changed

general/app/development/plugins-development-guide/index.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,17 @@ In the previous section, we learned about some of the existing options for handl
597597
- Any other value — Your block will immediately call the method specified in `mobile.php` and it will use the template to render the block.
598598
- `fallback` (optional) — This option allows you to specify a block to use in the app instead of your block. For example, you can make the app display the "My overview" block instead of your block in the app by setting `'fallback' => 'myoverview'`. The fallback will only be used if you don't specify a `method` and the `type` is different to `'title'` or `'prerendered'`. Supported from the 3.9.0 version of the app.
599599

600+
### Options only for CoreEnrolDelegate
601+
602+
- `enrolmentAction` (optional): The type of action done by the enrolment plugin. Defaults to 'browser'. Possible values:
603+
- `browser` — When the user clicks to enrol, open a browser to perform the enrol in the browser. It doesn't require any JavaScript to work in the app.
604+
- `self` — The user can self enrol in the app. Requires implementing the 'enrol' function in your JavaScript code.
605+
- `guest` — Allows the user to enter the course as guest in the app. Requires implementing the 'canAccess' and 'validateAccess' functions in your JavaScript code.
606+
- `infoIcons` (optional) — Icons related to the enrolment to display next to the course. If the icons need to be calculated dynamically based on the course you need to implement the function 'getInfoIcons' in your JavaScript code. Properties for each icon:
607+
- `icon` (required) — The icon name. E.g. 'fas-credit-card'.
608+
- `label` (required) — The label of the icon (for accessibility).
609+
- `className` (optional) — A CSS class to add to the icon element.
610+
600611
## Delegates
601612

602613
Delegates can be classified by type of plugin. For more info about type of plugins, please see the [Types of plugins](#types-of-plugins) section.
@@ -678,6 +689,7 @@ These delegates require JavaScript to be supported. See [Initialisation](#initia
678689
- `CoreFileUploaderDelegate`
679690
- `CorePluginFileDelegate`
680691
- `CoreFilterDelegate`
692+
- `CoreEnrolDelegate` (added in 4.3 version of the app)
681693

682694
## Available components and directives
683695

@@ -1631,6 +1643,59 @@ class AddonSingleActivityFormatHandler {
16311643
this.CoreCourseFormatDelegate.registerHandler(new AddonSingleActivityFormatHandler());
16321644
```
16331645

1646+
##### Self enrol plugin
1647+
1648+
The `CoreEnrolDelegate` handler allows you to support enrolment plugins in the app. This example will show how to support a self enrol plugin, you can find an example of each type of plugin in the issue [MOBILE-4323](https://tracker.moodle.org/browse/MOBILE-4323).
1649+
1650+
Here's an example on how to create a prefetch handler using the JS returned by the main method:
1651+
1652+
```javascript
1653+
const getEnrolmentInfo = (id) => {
1654+
// Get enrolment info for the enrol instance.
1655+
// Used internally, you can use any name, parameters and return data in here.
1656+
};
1657+
1658+
const selfEnrol = (method, info) => {
1659+
// Self enrol the user in the course.
1660+
// Used internally, you can use any name, parameters and return data in here.
1661+
};
1662+
1663+
var result = {
1664+
getInfoIcons: (courseId) => {
1665+
return this.CoreEnrolService.getSupportedCourseEnrolmentMethods(courseId, 'selftest').then(enrolments => {
1666+
if (!enrolments.length) {
1667+
return [];
1668+
}
1669+
1670+
// Since this code is for testing purposes just use the first one.
1671+
return getEnrolmentInfo(enrolments[0].id).then(info => {
1672+
if (!info.enrolpassword) {
1673+
return [{
1674+
label: 'plugin.enrol_selftest.pluginname',
1675+
icon: 'fas-right-to-bracket',
1676+
}];
1677+
} else {
1678+
return [{
1679+
label: 'plugin.enrol_selftest.pluginname',
1680+
icon: 'fas-key',
1681+
}];
1682+
}
1683+
});
1684+
});
1685+
},
1686+
enrol: (method) => {
1687+
return getEnrolmentInfo(method.id).then(info => {
1688+
return selfEnrol(method, info);
1689+
});
1690+
},
1691+
invalidate: (method) => {
1692+
// Invalidate WS data.
1693+
},
1694+
};
1695+
1696+
result;
1697+
```
1698+
16341699
### Using the JavaScript API
16351700

16361701
The JavaScript API is only supported by the delegates specified in the [Templates downloaded on login and rendered using JS data](#templates-downloaded-on-login-and-rendered-using-js-data) section. This API allows you to override any of the functions of the default handler.

0 commit comments

Comments
 (0)