Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

mod form extension specification: Difference between revisions

From MoodleDocs
mNo edit summary
m (Text replacement - "class="nicetable"" to "class="wikitable"")
(One intermediate revision by one other user not shown)
Line 1: Line 1:
This page summarises a way to extend the module creation/editing form for existing mod plugins by defining custom classes in a local plugin for Moodle 2.3 {{Moodle 2.3}}
This page summarises a way to extend the module creation/editing form for existing mod plugins by defining custom classes in a local plugin for Moodle 2.3 {{Moodle 2.3}}


{| class="nicetable" style="float: right;"
{| class="wikitable" style="float: right;"
|-  
|-  
! colspan="2" | mod_form extension Specification
! colspan="2" | mod_form extension Specification
Line 13: Line 13:


== Introduction ==
== Introduction ==
One of Moodle's greatest strengths is its pluggability and the wide range of plugins that have been made available for it. However, whilst some plugins are made with one set of users in mind, individual institutions may have slightly different requirements and, as such, wish to have slightly different defaults or may wish to hide a setting entirely. Additionally, some institutions will want to automatically create some modules based on external data sources. Whilst this is theoretically possible with use of the cmidnumber, users can currently reset settings post-creation or synchronisation.
One of Moodle's greatest strengths is its pluggability and the wide range of plugins that have been made available for it;  however, whilst some plugins are made with one set of users in mind, individual institutions may have slightly different requirements and therefore wish to have slightly different defaults or may wish to hide a setting entirely. Additionally, some institutions will want to automatically create some modules based on external data sources. Whilst this is theoretically possible with use of the cmidnumber, users can currently reset settings post-creation or synchronisation.


This specification proposes an easy way of extending any installed modules mod_form to cater for these scenarios and others without making any changes to the module itself.
This specification proposes an easy way of changing the module creation/editing form of any installed modules without making any changes to the module itself.  The standard form is instead extended, and standard Moodle forms syntax is used to make any changes to the form.


=== Usage scenarios ===
=== Usage scenarios ===
Line 27: Line 27:
* modify course/moodleform_mod.php to determine the name correctly based upon the new mod_form name
* modify course/moodleform_mod.php to determine the name correctly based upon the new mod_form name


The suggested change would require that a local plugin has a file with a name based upon the modules name. That file would contain a class extending the standard class for that module.
The suggested change would require that a local plugin contains:
* a file with a name based upon the modules name and
* that file would contain a class extending the standard class for the module


Some examples:
Some examples:
{| class="nicetable"
{| class="wikitable"
|-
|-
| Module frankenstyle name
| Module frankenstyle name
| Standard form class name
| Standard form class name
| local form file name
| local form class name
| local form class name
|-
|-
| mod_assign
| mod_assign
| mod_assign_mod_form
| mod_assign_mod_form
| local/example/mod_assign.php
| local_example_mod_assign_mod_form
| local_example_mod_assign_mod_form
|-
|-
| mod_page
| mod_page
| mod_page_mod_form
| mod_page_mod_form
| local/example/mod_page.php
| local_example_mod_page_mod_form
| local_example_mod_page_mod_form
|-
|-
| mod_resource
| mod_resource
| mod_resource_mod_form
| mod_resource_mod_form
| local/example/mod_resource.php
| local_example_mod_resource_mod_form
| local_example_mod_resource_mod_form
|}
|}

Revision as of 13:23, 14 July 2021

This page summarises a way to extend the module creation/editing form for existing mod plugins by defining custom classes in a local plugin for Moodle 2.3 Moodle 2.3


mod_form extension Specification
Status Draft
Tracker MDL-34509

Introduction

One of Moodle's greatest strengths is its pluggability and the wide range of plugins that have been made available for it; however, whilst some plugins are made with one set of users in mind, individual institutions may have slightly different requirements and therefore wish to have slightly different defaults or may wish to hide a setting entirely. Additionally, some institutions will want to automatically create some modules based on external data sources. Whilst this is theoretically possible with use of the cmidnumber, users can currently reset settings post-creation or synchronisation.

This specification proposes an easy way of changing the module creation/editing form of any installed modules without making any changes to the module itself. The standard form is instead extended, and standard Moodle forms syntax is used to make any changes to the form.

Usage scenarios

  • Administrator would like to change the default 'Prevent late submission' setting for mod_assign to 'No' (from 'Yes')
  • Administrator would like to entirely hide the 'Feedback comments' setting in mod_assign and force its value to 'Yes'
  • Administrator would like to set a range of default values based upon whether the cmidnumber value is set or not

Required modifications to core

In order to allow for this functionality in the least invasive way possible:

  • modify course/modedit.php to load the new module form from a local plugin
  • modify course/moodleform_mod.php to determine the name correctly based upon the new mod_form name

The suggested change would require that a local plugin contains:

  • a file with a name based upon the modules name and
  • that file would contain a class extending the standard class for the module

Some examples:

Module frankenstyle name Standard form class name local form file name local form class name
mod_assign mod_assign_mod_form local/example/mod_assign.php local_example_mod_assign_mod_form
mod_page mod_page_mod_form local/example/mod_page.php local_example_mod_page_mod_form
mod_resource mod_resource_mod_form local/example/mod_resource.php local_example_mod_resource_mod_form