Difference between revisions of "Plugin contribution"

Jump to: navigation, search
(Does the code follow the Coding Guidelines?)
(Does the code follow the Coding Guidelines?)
Line 110: Line 110:
=== Does the code follow the [[Coding|Coding Guidelines]]? ===
=== Does the code follow the [[Coding|Coding Guidelines]]? ===
The CONTRIB Coordinator will look at the code for general readability and point out any obvious deviations from the [[Coding|Coding Guidelines]]. While not all code needs to conform with each and every guideline, maintainers are encouraged to follow those guidelines as closely as possible. One useful tool for Moodle 2.0 is the [[http://moodle.org/mod/data/view.php?d=13&rid=4682|Code checker local plugin]] which helps to identify many issues.
The CONTRIB Coordinator will look at the code for general readability and point out any obvious deviations from the [[Coding|Coding Guidelines]]. While not all code needs to conform with each and every guideline, maintainers are encouraged to follow those guidelines as closely as possible. One useful tool for Moodle 2.0 is the [http://moodle.org/mod/data/view.php?d=13&rid=4682|Code checker local plugin] which helps to identify many issues.
==See also==
==See also==

Revision as of 07:23, 15 June 2011

This page describes the various ways to share and work collaboratively on contributed code. In the past, Moodle CONTRIB code was often stored on the Moodle CVS server. As Moodle code transitions to Git, CONTRIB code will also be transitioning with a goal of having all code maintained via git repositories by August 2011. Don't worry if you have code on CVS and do not know Git as there are many people willing to help you with the transition especially Anthony Borrow.

For those neither familiar with CVS nor Git, it is recommended that you learn Git basics. The nice thing about using Git is that it will leave control of the code in the hands of contributor.

  • Sharing code - Contributed code will be shared and maintained using a public Git repository (i.e. github.com, gitorious.org, etc.).
  • Reviewing code - If you would like your code to be tested and reviewed, please create an issue in the Moodle Tracker under CONTRIB.
  • Documenting code - You can maintain helpful documentation of the features and installation instructions in Moodle Docs
  • Distributing code - You can help others find your code by adding an entry to the Modules and Plugins database
  • Discussing the code - You can discuss the functionality and answer questions about how to use your code in the Using Moodle forums. Users can ask questions, discuss possible ideas for improvement, etc. Once the discussion matures to a point where you may want to take action, then you can create an issue in the Moodle Tracker.
  • Maintaining code - You can further develop your code by fixing issues, adding features, and responding to other issues with the Moodle Tracker. Each plugin or patch can have its own component in the CONTRIB project; however, you will need to request that the component be created in the CONTRIB project. Once created, users can easily create issues related to your contributed code. The primary maintainer of the code will be assigned as the component lead and have their tracker privileges bumped so that they can manage issues related to their contributed code. Those issues will automatically be assigned to the component lead/primary maintainer.

The CONTRIB Frequently Asked Question (FAQ)

Question: I have written a new block, activity, patch or theme to share with the Moodle community. What is the process for contributing the code?

Answer: First, thank you for your generosity and desire to share your work with the rest of the Moodle community. Code contributions are highly valued and Moodle wants to encourage creativity and generosity in keeping with Moodle's social constructionist pedagogy.

As mentioned, there are various tools to help you share and support your contribution. By using a consistent methodology, your Moodle related code will be more easily found, tested, used, maintained, documented, and evaluated by fellow Moodlers and developers. Learning to use the various tools common among Moodle developers will help you to efficiently and effectively develop, share and maintain your contributed code.

How to submit code

You have created some code that you would like to contribute to the Moodle community. The first step is to choose which Git code hosting site you want to use. Both github.com and gitorious.org are popular. Follow the instructions for creating a public repository for your code. This will allow others to download your code as well as suggest possible patches. As you become more familiar with collaborating with others you can also control who else you want to be able to push changes into your repository (i.e. write access).

In order to facilitate a common naming convention of Moodle related repositories, it is suggested that you use the following format: moodle-{plugintype}_{pluginname}. For example, the birthday block has a repository name of moodle-block_birthday and is located at https://github.com/arborrow/moodle-block_birthday. Other developers can fork the code and work from their repositories.

How to request that your code be tested/reviewed

  1. If you do not already have an account on the [1] Moodle Tracker], create one and login.
  2. Create a new "Task" issue in the "Non-core contributed modules" project. Your issue will be a request that the code be tested and reviewed.
  3. Provide the link to the repository (i.e. https://github.com/arborrow/moodle-block_birthday)
  4. Provide a clear description of what the code does and the functionality that it adds to Moodle.
  5. Provide any other links to supporting documentation

The Contrib Coordinator will then work directly with the code contributor via the Tracker to help evaluate the code, work on resolving any questions/issues found, etc.

  • Contributors are encouraged to follow Moodle's coding guidelines Coding.
  • Contributors are encouraged to maintain a branch for each major Moodle release (i.e. 1.8, 1.9, etc.). The HEAD branch should be used as the development branch.
  • Contributors are encouraged to associate each change made to an issue in the tracker. This practice is done by Moodle core developers and it is a good habit to get into so that you can go back and see why various changes were made to the code. Simple practices like these help to create good documentation of the code as it develops and matures. Commits should begin with the Moodle tracker issue number followed by a brief description of the change.

How to provide documentation

Having great code available to the community is wonderful. It is also important to educate users about how to use the code with documentation in Moodle Docs. See guidelines for contributors for more help.

A documentation page for a contributed module should have some basic elements. A brief introduction of what the code does, a "Features" heading, perhaps a "Installation", "Tips and tricks" and "See also" headings, all with content of course. Sometimes a screenshot is worth 1000 words. In the "See also" put a link to the Modules and Plug database, with a note that this is the place to download versions, and the forum where questions can be answered at moodle.org.

Other information might include: Languages Supported, Known Issues, Supported Versions (for Moodle 1.8, 1.9), and maybe which are being actively supported. The page should be added to the contributed code category by typing
[[Category:Contributed code]]
at the bottom of the page.

Possible format for a contributed code Moodle Docs page

You can copy and paste the below into your Moodle documentation page. Please add the URL links. This is only a suggestion.

Start with a 2-4 line introduction. The Plug In Name works with the activity module. 
It makes the life of the teacher easier by ... 
* Add features list or overview description here <br>
 [[Image:Sample_screen_shot|thumb|500px|center|Title of screenshot]]
Place install instructions here
==Tips and tricks==
*Optional section, usually added by users later
==See also==
*[Place http_address_for_M&P_entry_here  Name of Entry here] is a Modules and plugins database page that has download links and more information.
*Discussions: [Place http_address_for_moodle_forum_or_thread_here Name of forum]

When no thread or forum exists for discussion, put a link to the Contributed Code forum.

*Discussions: Please create or find a discussion topic in the [http://moodle.org/mod/forum/view.php?id=44  Contributed Code forum]

Share code with modules and plugins database

Now you have a place for users to get your code, how will they know it exists? Moodle users can easily find information about contributed code in the Modules and Plugins database. When you add an entry to this database, remember that it is searchable by any field. Every field is not required, but providing as much information as possible will help people who would like to find, read about, and then install your contribution. In particular, the name of the module and the description of its function are important. Screen shots are helpful (but please, not larger than 350px wide!). Links to discussion (on Moodle.org or other forum) and documentation (link to your page in the Moodle docs or another location) should be included if possible.

Users may leave comments on your entry, so please check it periodically for questions and bug reports. If you include contact information or a link to a discussion, your users may be able to contact you more directly. The comments are not emailed automatically.

Keep in mind that entries added to the Modules and Plugins database require approval by a moderator before they will be visible to other Moodle users.

Support code and get feedback with forums

As users become familiar with the contributed code, discussions about the code are likely to emerge. We strongly urge you to place links to at least one forum at moodle.org in your Modules and Plugins entry as well as in MoodleDocs.

It is important to respond to users who have questions about how to use the code, suggestions for how to make it better, etc. If it looks like there is sufficient need for some contributed code to have its own forum, please create a request via the tracker in the MDL-SITE section. Moodle has included many contributed code projects and ideas into its core.

Maintain and refine code with Tracker

In order to facilitate keeping track of feature requests, bugs, and other code issues, the contributor may request that a component be created in the CONTRIB section of the Moodle tracker. (This is the section where you initially made the request to have code included in CVS.moodle.org.)

The contributor can be added to the group of CONTRIB developers in the tracker to manage the issues assigned to them and better coordinate with other developers. Users of the contributed code can then add issues which can be assigned directly to the maintainer. The tracker helps to manage the work flow involved in fixing bugs, working through feature requests, and maintaining the code. When committing changes, maintainers are strongly encouraged to begin the commit comment with a tracker number.

We strongly encourage users to involve themselves in the process of creating a useful issue in tracker. For the developer and code contributor, describing the fix can help clarify the need for the code change. Further, it helps to establish good documentation about how the code developed. Others will be able to identify the issues addressed and understand why a particular decision was made.


It is hoped that following this procedure, will help guide contributors of code in the process of learning the tools and skills used by the Moodle developers. Learning to submit code by using the tracker, work the code with CVS, support the code by providing documentation, share code in Modules and Plugins, maintain the code by using the tracker, and evolve the code by using the Moodle.org forums will assist you in successfully contributing to the Moodle community and working with Moodle's developers.

Throughout this process, the CONTRIB Coordinator is here to encourage and support those contributing code to the Moodle community and fostering the development of tomorrow's Moodle developers.

Eventually, the community may wish for the code to become part of the Moodle core. By following the steps above, the developers will be able to evaluate the merit of the contributed code, understand how users have used the code, see the issues that have emerged and thus have more information to make an informed decision about whether or not to incorporate the contributed code into core.

Most common recommendations for contributed code

There are several small issues that the CONTRIB Coordinator will typically check for when reviewing the code prior to committing to the CVS server. These issues help to ensure consistency and quality of code. Any suggestions made by the CONTRIB Coordinator should be considered recommendations aimed to help folks new to the Moodle community collaborate in a way consistent with standard practices within the Moodle community. The suggestions are meant to help avoid potential issues and facilitate the acceptance of your code.

Does the file structure conform to Moodle standards?

Generally speaking, each file should have an appropriate extension (i.e. php, html, css, txt, etc.). To avoid issues with case sensitivity, folders and files are normally lower case; however, there are exceptions to this. Another common recommendation is to place the lang folder within the block or module rather than asking the user to copy files into the main lang folder. Changes made in the get_string function for Moodle 1.9 and onward make it possible to do this which goes a long way in keeping things modular. Similarly, to respect the modular nature of Moodle if a block requires a library it is usually preferred to keep it as a subdirectory in the block's folder. This can be especially helpful if your code is dependent upon a particular version of an external library.

Does the code work without any obvious errors?

The CONTRIB Coordinator will try to install the block or module on a fresh Moodle installation and report back any errors. This testing is done with Debugging set to show All PHP notices and errors (not developer mode). The most common notices have to do with attempting to use a variable that has not been initialized or checked for existence.

Does the code use the config_plugins table?

Contributed blocks and modules are encouraged to make use of the config_plugins table rather than the config table. Maintainers are encouraged to read the documentation provided for the get_config() and set_config()] functions in the /lib/moodlelib.php file to help ensure that the footprint for the global $CFG variable does not become bloated.

Does the code follow the Coding Guidelines?

The CONTRIB Coordinator will look at the code for general readability and point out any obvious deviations from the Coding Guidelines. While not all code needs to conform with each and every guideline, maintainers are encouraged to follow those guidelines as closely as possible. One useful tool for Moodle 2.0 is the checker local plugin which helps to identify many issues.

See also