Skip to content

Creating a extension setting and admin form

Extension authors may want to create settings to store data that relate to their extensions and there is a standard pattern of how this works.

Creating Setting defintion in an extension

  1. Create a settings folder within your extension and create a file such as myextension.setting.php this is where you store the setting metadata array as per the Settings Properties. You should make sure that you set in your setting metadata array the settings_pages. When you are creating your extensions you should make sure to namespace your settings names to avoid conflicts, For example, a 'Rate limit' setting in a 'My Extension' should be named.my_extension_rate_limit. The key of the settings pages extension should be the extension short name e.g.
    'settings_pages' => ['stripe' => ['weight' => 10]]
    
    You can see an example of this in the mutlisite extension Multisite extension example
  2. You will need to then run within your extension civix mixin --enable=setting-php@1 to then enable the relevant setting hooks.
  3. You will then want to create or update your menu hook file in the following folder xml/Menu/myextension.xml and you want to create a menu item like the following
    <?xml version="1.0"?>
    <menu>
      <item>
         <path>civicrm/admin/setting/myextension</path>
         <title>Really important settings</title>
         <page_callback>CRM_Admin_Form_Generic</page_callback>
      </item>
    </menu>
    
  4. run civix mixin --enable=menu-xml@1 this will ensure your newly created xml is picked up.
  5. Use cv api system.flush or Admin → System Settings → Cleanup Caches to flush CiviCRM caches and register the new settings metadata.