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) »
  • Setting is_default for options in hook_buildAmount doesn't seem to be working
Pages: [1]

Author Topic: Setting is_default for options in hook_buildAmount doesn't seem to be working  (Read 628 times)

lolas

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 9
    • Freeform Solutions
  • CiviCRM version: Several
  • CMS version: Drupal
  • MySQL version: 5.1+
  • PHP version: Several
Setting is_default for options in hook_buildAmount doesn't seem to be working
May 17, 2013, 11:20:35 am
I have a Drupal module using hook_civicrm_buildAmount that basically checks some rules and unsets some of the available options in the membership_amount part of the $amount array.
After unsetting some of the options I want to make sure that one of the radio buttons is checked by default so I run through and choose a default according to some rules and fall back to the first option if no rule matches. I have a situation where there is only one remaining option. Just before exiting  hook_buildAmount I print $amount with dpm and the options sub-array contains the contents shown below but the one remaining checkbox is not checked on the renewal page.

Code: [Select]
options (Array, 1 element)
111 (Array, 9 elements)
id (String, 3 characters ) 111
price_field_id (String, 2 characters ) 50
name (String, 10 characters ) My_Membership
label (String, 10 characters ) My Membership
amount (String, 5 characters ) 90.00
weight (String, 2 characters ) 13
membership_type_id (String, 2 characters ) 27
is_default (String, 1 characters ) 1
is_active (String, 1 characters ) 1

I guess I will need to dig a bit deeper into where the hook is called unless this is known restriction in the hook.
Freeform Solutions provides technology and management consulting, website and database development, and managed internet hosting solutions for not-for-profit organizations (NFPs).

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Setting is_default for options in hook_buildAmount doesn't seem to be working
May 17, 2013, 11:41:48 am
Are you using setDefaults() to set the defaults?

Kurund
Found this reply helpful? Support CiviCRM

lolas

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 9
    • Freeform Solutions
  • CiviCRM version: Several
  • CMS version: Drupal
  • MySQL version: 5.1+
  • PHP version: Several
Re: Setting is_default for options in hook_buildAmount doesn't seem to be working
May 17, 2013, 12:33:05 pm
Hi Kurund,
No, I was hoping I could do it all in hook_buildAmount. It would seem logical that if you can change the amounts here you can also change the default value. I guess you are saying I need to implement hook_buildForm as well to set the defaults?
Freeform Solutions provides technology and management consulting, website and database development, and managed internet hosting solutions for not-for-profit organizations (NFPs).

Kurund Jalmi

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4169
  • Karma: 128
    • CiviCRM
  • CiviCRM version: 4.x, future
  • CMS version: Drupal 7, Joomla 3.x
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Setting is_default for options in hook_buildAmount doesn't seem to be working
May 17, 2013, 01:10:36 pm
Quote
I guess you are saying I need to implement hook_buildForm as well to set the defaults?
Nope. You just need to call setDefaults() method in hook_buildAmount to set the defaults.

check https://github.com/civicrm/civicrm-drupal/blob/7.x-master/civitest.module.sample for example

Kurund
Found this reply helpful? Support CiviCRM

lolas

  • I post frequently
  • ***
  • Posts: 134
  • Karma: 9
    • Freeform Solutions
  • CiviCRM version: Several
  • CMS version: Drupal
  • MySQL version: 5.1+
  • PHP version: Several
Re: Setting is_default for options in hook_buildAmount doesn't seem to be working
May 17, 2013, 01:56:35 pm
Thanks Kurund!

You are right, using setDefaults works in either function. There's a spot where the docs recommend setting defaults in hook_civicrm_buildForm. Doesn't mean it's the only place it works right?

I also took a closer look and those is_default values on the price field options are used before hook_civicrm_buildAmount is called so changing them there has no effect - too bad but problem solved anyway. The drupal sample is very helpful.

Freeform Solutions provides technology and management consulting, website and database development, and managed internet hosting solutions for not-for-profit organizations (NFPs).

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Setting is_default for options in hook_buildAmount doesn't seem to be working

This forum was archived on 2017-11-26.