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 (Moderator: Donald Lobo) »
  • hook_civicrm_pre called twice on drupal edit user form
Pages: [1]

Author Topic: hook_civicrm_pre called twice on drupal edit user form  (Read 1000 times)

Michael McAndrew

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1274
  • Karma: 55
    • Third Sector Design
  • CiviCRM version: various
  • CMS version: Nearly always Drupal
  • MySQL version: 5.5
  • PHP version: 5.3
hook_civicrm_pre called twice on drupal edit user form
April 06, 2011, 04:53:59 am
Hello folks,

I am calling hook_civicrm_pre when a profile is edited on the Drupal user page.

For some reason the hook is being called twice.  I am wondering why.  I prefer the format of the params in the second call to this function (because they look the same as when it is called on the submission of civicrm/contact/add and are therefore easy to work with).  Is it bad that this is called twice?

It was bad for me because I was performing some logic that triggered an email to be sent people based on the form submission and it called called twice.

What do you think?

Should we make sure it is only called once?

For now I will update the code to check for the presence of ['edit']['civicrm_dummy_field'] (unless you wanna suggest something more sensible)

Here is the result of print_r($params); ...

Code: [Select]
Array
(
    [MAX_FILE_SIZE] => 33554432
    [edit] => Array
        (
            [civicrm_dummy_field] => CiviCRM Dummy Field for Drupal
        )

    [first_name] => Michael
    [last_name] => McAndrew
    [street_address-1] => 109 Roding Road
    [supplemental_address_1-Primary] =>
    [supplemental_address_2-Primary] =>
    [city-1] => London
    [postal_code-1] => E5 0DR
    [country-1] =>
    [phone-1-1] => 07817 80229
    [phone-1-2] =>
    [uf_group_id] => 1
)
Array
(
    [contact_type] => Individual
    [contact_id] => 4
    [MAX_FILE_SIZE] => 33554432
    [first_name] => Michael
    [last_name] => McAndrew
    [address] => Array
        (
            [1] => Array
                (
                    [location_type_id] => 1
                    [is_primary] => 1
                    [street_address] => 109 Roding Road
                    [supplemental_address_1] =>
                    [supplemental_address_2] =>
                    [city] => London
                    [postal_code] => E5 0DR
                    [country] =>
                )

        )

    [phone] => Array
        (
            [2] => Array
                (
                    [location_type_id] => 1
                    [is_primary] => 1
                    [phone_type_id] => 1
                    [phone] => 07817 80229
                )

            [3] => Array
                (
                    [location_type_id] => 1
                    [phone_type_id] => 2
                    [phone] =>
                )

        )

    [uf_group_id] => 1
)
Service providers: Grow your business, build your reputation and support CiviCRM. Become a partner today

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: hook_civicrm_pre called twice on drupal edit user form
April 06, 2011, 10:24:15 am

yes, i suspect it is being called twice

in user reg / my account case, drupal form api is controlling the sequence of calls. It makes multiple calls to civicrm in different phases (form, validate, insert/update).

We have not optimized it and tried to sequence things with the drupal calls, and hence its called twice

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • hook_civicrm_pre called twice on drupal edit user form

This forum was archived on 2017-11-26.