Note: You are currently viewing documentation for Moodle 2.3. Up-to-date documentation for the latest stable version is available here: Customlabel subtype development framework.

Customlabel subtype development framework

From MoodleDocs

The customlabel subtype development framework is a set of writting and development rules which will make easy making new subtypes for use in course contents.

The customlabel concept is to centralize all mechanical aspects in the customlabel module, thus keeping writing of a subtype minimalist.

What is a subtype?

A subtype is a cutomlabel subplugin handled by the generic subplugin API of Moodle.

A subtype is essentially :

  • a directory in the mod/customlabel/type directory
  • a subclass of the customlabel_type (@see /mod/customlabel/type/customtype.class.php)
  • a file version.php to handle subplugin verisonning
  • a lang directory for storing templates and language dependant strings
  • a local css file for preseting default styling

The customlabel_type class

The customlabel_type class describes what is the internal information model of the customlabel. The custom type must require the geenric customlabel_type implementation to extend the parent class :

  require_once ($CFG->dirroot."/mod/customlabel/type/customtype.class.php");
  
  class customlabel_type_coursedata extends customlabel_type{
  ... implementation ...
  }


Just three methods are enough to build the customtype :

The class constructor

Defines all information fields used by the customlabel templates. The class stores the type information and builds the $this->fields array that defines each field.

  function __construct($data){
     parent::__construct($data);
     $this->type = 'coursedata';
     $this->fields = array();

The constructor will define fields using the following code template :

  unset($field);
       $field->name = 'fieldname';
       $field->type = 'textfield';
       $this->fields['fieldname'] = $field;

Field type drives how the instance setting form will require information from the editing teacher. Depending on the type accessory attributes can be used to control specific aspects of the settings form.

Field type : choiceyesno

       unset($field);
       $field->name = 'choiceyesnoname';
       $field->type = 'choiceyesno';
       $this->fields['choiceyesnoname'] = $field;

Provides a boolean selector as a yes/no list

Field type : textfield

       unset($field);
       $field->name = 'textfieldname';
       $field->type = 'textfield';
       $field->size = 40;  // optional
       $field->mawlength = 40;  // optional
       $this->fields['textfieldname'] = $field;

Provides a simple textfield to get a simple string

Field type : htmlarea

Field type : htmlarea