Note: You are currently viewing documentation for Moodle 1.9. Up-to-date documentation for the latest stable version is available here: Modules.

Development:Modules: Difference between revisions

From MoodleDocs
(→‎See also: link added)
(Fixed obsolete information, added actual module structure)
Line 1: Line 1:
'''Activity modules''' reside in the 'mod' directory. Each module is in a separate subdirectory and consists of the following mandatory elements (plus extra scripts unique to each module):
'''Activity modules''' reside in the 'mod' directory. Each module is in a separate subdirectory and consists of the following mandatory elements (plus extra scripts unique to each module):


* ''mod.html'' - a form to set up or update an instance of this module
* ''mod_form.php'' - a form to set up or update an instance of this module
* ''version.php'' - defines some meta-info and provides upgrading code
* ''version.php'' - defines some meta-info
* ''icon.gif'' - a 16x16 icon for the module
* ''icon.gif'' - a 16x16 icon for the module
* ''db/'' - SQL dumps of all the required db tables and data (for each database type)
* ''db/install.xml'' - defines the structure of db tables for all database types. Is used during module installation
* ''db/upgrade.php'' - defines changes in the structure of db tables. Is used during module upgrade
* ''db/access.php'' - defines module capabilities
* ''index.php'' - a page to list all instances in a course
* ''index.php'' - a page to list all instances in a course
* ''view.php'' - a page to view a particular instance
* ''view.php'' - a page to view a particular instance
Line 19: Line 21:
:** [[Development:Implementing Reset course functionality in a module|widget_reset_course_form() and widget_delete_userdata()]] - used to implement [[Reset course]] feature.
:** [[Development:Implementing Reset course functionality in a module|widget_reset_course_form() and widget_delete_userdata()]] - used to implement [[Reset course]] feature.
:* To avoid possible conflict, any module functions should be named starting with widget_ and any constants you define should start with WIDGET_
:* To avoid possible conflict, any module functions should be named starting with widget_ and any constants you define should start with WIDGET_
* ''config.html'' - (optional) a form to set up or update global settings of this module
* ''backuplib.php'' and ''restorelib.php'' (optional)
* ''lang/en_utf8/resource_widget.php'' - (optional) Lastly, each module will have some language files that contain strings for that module.
* ''settings.php'' - (optional) a form definition to set up or update global settings of this module
* ''lang/en_utf8/widget.php'' - (optional) Lastly, each module will have some language files that contain strings for that module.


IMPORTANT: When creating a new module, the new name of the module must not contain numbers or other special characters!  
IMPORTANT: When creating a new module, the new name of the module must not contain numbers or other special characters!  

Revision as of 14:36, 2 March 2008

Activity modules reside in the 'mod' directory. Each module is in a separate subdirectory and consists of the following mandatory elements (plus extra scripts unique to each module):

  • mod_form.php - a form to set up or update an instance of this module
  • version.php - defines some meta-info
  • icon.gif - a 16x16 icon for the module
  • db/install.xml - defines the structure of db tables for all database types. Is used during module installation
  • db/upgrade.php - defines changes in the structure of db tables. Is used during module upgrade
  • db/access.php - defines module capabilities
  • index.php - a page to list all instances in a course
  • view.php - a page to view a particular instance
  • lib.php - any/all functions defined by the module should be in here. If the modulename is called widget, then the required functions include:
  • widget_install() - will be called during the installation of the module
  • widget_add_instance() - code to add a new instance of widget
  • widget_update_instance() - code to update an existing instance
  • widget_delete_instance() - code to delete an instance
  • widget_user_outline() - given an instance, return a summary of a user's contribution
  • widget_user_complete() - given an instance, print details of a user's contribution
  • Other functions available but not required are:
  • To avoid possible conflict, any module functions should be named starting with widget_ and any constants you define should start with WIDGET_
  • backuplib.php and restorelib.php (optional)
  • settings.php - (optional) a form definition to set up or update global settings of this module
  • lang/en_utf8/widget.php - (optional) Lastly, each module will have some language files that contain strings for that module.

IMPORTANT: When creating a new module, the new name of the module must not contain numbers or other special characters!

You should also make sure that your activity module provides appropriate support for groups and metacourses.

See also