CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Best practices for storing extension config settings?
Pages: [1]

Author Topic: Best practices for storing extension config settings?  (Read 353 times)

JoeMurray

  • Administrator
  • Ask me questions
  • *****
  • Posts: 578
  • Karma: 24
    • JMA Consulting
  • CiviCRM version: 4.4 and 4.5 (as of Nov 2014)
  • CMS version: Drupal, WordPress, Joomla
  • MySQL version: MySQL 5.5, 5.6, MariaDB 10.0 (as of Nov 2014)
Best practices for storing extension config settings?
June 06, 2014, 11:14:42 am
For an extension that needs to potentially store multiple settings for multiple providers, I'm wondering what the advice of the community is for the persistence approach. For example, we may have one phone integration with Twilio and two available for Plivo, sort of like how there can be multiple payment processors active at the same time. Also, just like with payment processors, the fields needed to store the config information are sometimes the same across providers though each tends to have a few unique ones.

Should we just develop our own table for all of this? Should we be serializing PHP variables into a single field (yuck!)? Or is their a Symfony component we should start using? Advice and pros and cons welcome!

As background that is only sort of related, see https://wiki.civicrm.org/confluence/display/CRM/API+for+Settings
Co-author of Using CiviCRM https://www.packtpub.com/using-civicrm/book

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Best practices for storing extension config settings?
June 08, 2014, 03:20:22 pm
Hi Joe,

I do a few things.

If the settings are site-wide then I describe new settings using the settings format & use the settings api

As you can see you can describe the setting as an array
https://github.com/eileenmcnaughton/nz.co.fuzion.accountsync/blob/master/settings/AccountSync.setting.php#L8

Note that CiviCRM does store this as a serialised array - of course I prefer JSON but from the extension point of view it's basically irrelevant as you retrieve via api as well.

& here is a form that constructs a settings page with only the setting group hard-coded
https://github.com/eileenmcnaughton/nz.co.fuzion.civixero/blob/master/CRM/Civixero/Form/XeroSettings.php


IF there is a setting per entity I use the entity_setting extension 

https://github.com/eileenmcnaughton/nz.co.fuzion.entitysetting

This does the same thing but it saves all the settings to a single table (entity_setting) with an entity_id & entity_type for each line. Each unique entity has a json array of settings & the extension takes care of the fact it might have settings from more than one extension e.g

https://github.com/eileenmcnaughton/nz.co.fuzion.frontendpageoptions/blob/master/settings/nz.co.fuzion.frontendpageoptions.event.entity_setting.php
defines 2 settings - one the form to redirect to after save & the second is the relationship to create when someone registers another person.

There are accessed using the entity_setting api.

Note that you can optionally add these settings to the relevant config form - but the method I've been using to do this has been by adding in the alterContent hook. Because it's all config form stuff I wasn't concerned about the speed side - but the CiviCRM html quality has been causing a few problems here.
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

jaapjansma

  • I post frequently
  • ***
  • Posts: 247
  • Karma: 9
    • CiviCoop
  • CiviCRM version: 4.4.2
  • CMS version: Drupal 7
  • MySQL version: 5
  • PHP version: 5.4
Re: Best practices for storing extension config settings?
June 10, 2014, 02:02:33 am
When it comes to implement certain providers. Such as the payment providers, but then for phone systems. I would combine the civicrm settings hook but also create my own hooks in the extension so that you could create new providers for the extension in other extensions.

I have done that for the automatic relationship extension. In which I provide a hook for retrieving optional rules for autoamtic relationships. In another extensions I have implemented this hook to provide the rules. That way your extension becomes more flexible and more loosly coupled.
Developer at Edeveloper / CiviCoop

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Best practices for storing extension config settings?

This forum was archived on 2017-11-26.