Skip to content
Advertisement

Moodle custom fields API for course page

Unfortunately I can’t quite follow how the custom field API works. What I actually want are additional fields for the custom course format such as address, directions and other (hybrid courses). And no, I don’t want to use the web interface for this.

As I understand it, two files are needed, myFormatPlugin/classes/customfields/course_handler.php and myFormatPlugin/customfield.php

Do I need to register the customfield.php file somewhere or does it work via autoload?

Do I need to create a separate database table for this?

What am I missing?

Could someone make an example for just one field? I don’t find the github links in the documentation helpful either.

Advertisement

Answer

Hope you want to add some custom fields for your custom course format. To add custom fields for the format plugin you don’t want to use the custom field API.

The course format plugin contains options to add your custom fields using the function course_format_options in your course/format/PLUGINNAME/lib.php.

Moodle will automatically store these custom course format options in the database table course_format_options.

Please have look at the designer course format plugin.

https://github.com/bdecentgmbh/moodle-format_designer/blob/master/lib.php#L241

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement