Introduction
Flavours are a way to define a set of features and settings. Flavours can set defaults and also enforce settings so that they cannot be changed in the interface anymore.
For a flavour to take effect it needs to be activated (either via a config flag in the config.php or via a CLI script) and enforced. Enforcing a flavour can be done via a CLI script or in the Features overview by an admin.
There can only be one flavour active at a time.
How to define flavours
Each flavour has its own subplugin within the totara_flavour plugin.
Definition
The flavour needs to implement its own definition class and can override different methods to customise the settings and behaviour.
Default settings
You can override the load_default_settings()
method to provide defaults which will override the existing site default settings.
Enforced settings
You can override the load_enforced_settings()
method to provide defaults which will be applied once this flavour gets activated. Those settings cannot be changed in the interface anymore once the flavour is active and enforced.
Prohibited settings
By default all enforced settings are automatically prohibited, meaning they are shown as disabled in the features overview. There is an advanced option to override the load_prohibited_settings()
method to let you make modifications to the default behaviour. Normally this is not required but can be implemented as follows:
Active flavour notice
If the flavour defines the following strings in its language file this will show up on the environment check page on installation and upgrades. The activenoticeinfo text does support markdown.
$string['activenoticetitle'] = 'Example flavour'; $string['activenoticeinfo'] = 'This text can be defined by the flavour and shows up on installation and upgrades.';
Additional upgrade steps
The method additional_upgrade_steps()
can be overridden to implement additional steps on every upgrade. This method is called on every upgrade if the flavour is active.
Additional activation steps
The method additional_activation_steps()
can be overridden to implement additional steps on activation. This method is called only once when the flavour is being activated.
How to use flavours
CFG flags
Set the $CFG→forceflavour
to the flavour you want to enable and enforce. This will lock in the flavour and it can only be changed by changing the same config flag again.
$CFG->forceflavour = 'example';
After setting the flag you need to either enforce the flavour by clicking the Enforce flavour button in the Feature overview interface or execute the CLI script server/totara/flavour/cli/enforce_current.php.
Installation and upgrades automatically enforce the flavour set by this flag, so it is possible to set the config flag before installation to have it active from the start.
If no flavour is provided the system will default to the Learn flavour.
CLI scripts
There are two scripts which can be called from the command line, one to activate a flavour (and enforce it as well) and one to enforce the current flavour.
# Activate a flavour php server/totara/flavour/cli/activate_flavour.php --activate=example # List all available flavours php server/totara/flavour/cli/activate_flavour.php --list # Show active flavour name php server/totara/flavour/cli/activate_flavour.php --show # Enforce the current flavour making sure all settings are applied php server/totara/flavour/cli/enforce_current.php