Skip to content

Usage

Setting Storage and Retrieval

Domain Settings

To set a setting for a whole domain, developers can use either the Setting.Create API or use Civi::settings()->set() to set the value e.g. Civi::settings()->set('editor_id', 'CKEditor');. To Retrieve a setting value, developers can use the Setting.Get API or use Civi::settings()->get() e.g. Civi::settings()->get('max_attachments');

Contact Settings

After 5.7.0 developers are able to use the Civi::contactSettings facade to set contact specific settings. You can also use the API to set it but must pass in a contact_id parameter. To set a contact setting it would be like Civi::contactSettings($contact_id)->set('navigation', $value). To retrieve the setting developers can use Civi::contactSettings($contact_id)->get('navigation')

API actions

The following api actions have been introduced into CiviCRM

  • civicrm_api3('setting', 'getfields', array());
  • civicrm_api3('setting', 'get', array());
  • civicrm_api3('setting', 'getvalue', array()); (see note)
  • civicrm_api3('setting', 'create', array());
  • civicrm_api3('setting', 'getdefaults', array());
  • civicrm_api3('setting', 'revert', array());
  • civicrm_api3('setting', 'fill', array());

Note

'getvalue' is not a pseudonym for get - it is intended for runtime whereas get is a heavier function intended for configuration

As with all CivicRM API you can access it through your standard CLI tools e.g.

drush civicrm-api setting.create debug_enabled =1 userFrameworkLogging=1
drush civicrm-api setting.revert filters.group=localization domain_id = 3

Smarty / Template Layer

crmAPI will interact with settings but a specific option exists. This will access settings stored in $config or settings

{crmSetting name="search_autocomplete_count" group="Search Preferences"}
(Group is still required here but .... fixing that)

Multiple Domains

The settings api supports the following values for domain_id :

  • current_domain (default)
  • integer
  • array of integers
  • all

It is desirable to make this api handling of domain id part of the api layer for all api that involve domains.