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 extesnion¶
- 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.You can see an example of this in the mutlisite extension Multisite extension example
'settings_pages' => ['stripe' => ['weight' => 10]]
- You will need to then run within your extension
civix mixin --enable=setting-php@1to then enable the relevant setting hooks.
- You will then want to create or update your menu hook file in the following folder
xml/Menu/myextension.xmland 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>
civix mixin --enable=menu-xml@1this will ensure your newly created xml is picked up.
cv api system.flushor
Admin → System Settings → Cleanup Cachesto flush CiviCRM caches and register the new settings metadata.