Aller directement à la fin des métadonnées
Aller au début des métadonnées

This page's contents are old and now superceded by the "Settings Reference" page.

Introduction

Sometimes you want to provide a page for settings for your module. Also modules should not have custom field id's hardcoded if possible since it makes it awkward to move the code between test installations. Instead you can provide a UI form with these simple steps.

Prerequisites

  • You know how to set up your path to custom php/templates.
  • At least passing familiarity with QuickForm and Smarty and how they are used in CiviCRM forms.
  • How to create a module to use hooks.

Steps

  1. Make a .xml file for the path to your settings page.

  2. Make a module to implement hook_civicrm_xmlMenu. After you enable the module you will need to visit <your_site>/civicrm/menu/rebuild&reset=1 to pick up this addition.

  3. At this point we will be creating a PHP class and Smarty template file similar to the ones found in core under civicrm/CRM.  In order for CiviCRM to pick up your new files, you'll either have to configure the directory settings at Administer > Configure > Global Settings > Directories or you'll need to implement hook_civicrm_config to programatically tell CiviCRM where to find your PHP classes and Smarty templates.  Here is an example implementation of hook_civicrm_config that tells CiviCRM to look in the module folder for the PHP classes and Smarty templates:

    This assumes that your module has a directory structure like so:

    This method has the advantage of not requiring your module users to set the global directories path, which allows multiple modules to package their CiviCRM PHP classes and Smarty templates in different directories.

  4. Make a custom form with something like this in it (change class to match where you are putting it). Of course you are not limited to custom fields in your select dropdowns - this is an example.

  5. Make a corresponding template with something like this in it.

  6. Use it in your module / custom form like so

These steps will store the settings in config_backend. If you don't want it there you can override postProcess in your class above and store them somewhere else, and then of course you will need to retrieve them differently too.

Étiquette
  • Aucun