|
|
(15 intermediate revisions by 6 users not shown) |
Line 1: |
Line 1: |
| {{Moodle 2.0}} | | {{Template:Migrated|newDocId=/docs/apis/plugintypes/mod/visibility}} |
| | |
| The features described here are available since Moodle 2.0.2.
| |
| | |
| == Summary ==
| |
| | |
| A new API allows you to customise how your module displays on the main course page:
| |
| | |
| * You can display custom HTML below the link to your module.
| |
| | |
| * If your module does not have a link (like Label, where it is only for display on the main page) then you can remove the link from the main page and from all navigation etc.
| |
| | |
| * You can display HTML next to the link to your module that indicates dynamic information (like Forum, where it displays information about unread messages).
| |
| | |
| * You can display additional icons next to the other module editing icons when the user is editing the page.
| |
| | |
| In addition, existing things you could already do (like change the icon on the main page) are still available when using the new API.
| |
| | |
| == Backward compatibility == | |
| | |
| All modules and code written for Moodle 2.0 should continue to behave in exactly the same manner. There is no need to change existing modules for this API.
| |
| | |
| == Customising module display, in course cache: <tt>_get_coursemodule_info</tt> ==
| |
| | |
| The first place you can customise your module display is in the existing <tt>_get_coursemodule_info</tt> API function. This function obtains information about the module which will be stored in the course cache (the <tt>modinfo</tt> field of the course table).
| |
| | |
| The course cache is only updated when somebody edits a module, so it can't be used for dynamic information - but it's okay if it takes a few database queries to calculate the data because it will be cached for future use.
| |
| | |
| The function should return a value of class <tt>cached_cm_info</tt>. For example:
| |
| | |
| <code php>
| |
| function mod_frog_get_coursemodule_info($cm) {
| |
| $info = new cached_cm_info;
| |
| $info->content = '<p>This will display below the module.</p>';
| |
| return $info;
| |
| } | |
| </code php>
| |
| | |
| You can change several properties which are documented in that class definition. If you don't change a property, its value remains default.
| |
| | |
| * <tt>name</tt> - name of activity (text of the link on course page).
| |
| * <tt>icon</tt>, <tt>iconcomponent</tt> - name and component name of icon to display by the link.
| |
| * <tt>content</tt> - extra HTML content to display below the module link on course page (not shown in navigation etc).
| |
| * <tt>customdata</tt> - arbitrary extra PHP data to store in modinfo cache; useful if, for performance reasons, your module needs to store data that should be accessible very quickly from other parts of the course.
| |
| * <tt>extraclasses</tt> - extra CSS class or classes that will be added to the activity on the main page, so that you can alter the styling.
| |
| * <tt>onclick</tt> - already-escaped HTML that will be inserted as the value of the onclick attribute.
| |