1

I am using module Mixpanel in my site. And I want to override function of this module. Here is link where we can see the function or code which I need to alter CODE NEED TO MODIFIED

Below is the code line which suggest that I can override this function :

    // Let other modules alter the defaults.
    drupal_alter('mixpanel_defaults', $properties, $account);

So from above line I am trying to override it with code as below, please let me know what I am doing wrong as it does not make any changes. However if I do same thing in main module it make changes but I don't want to make change in module but want to do in my custom module.

My custom module name: custom

function custom_mixpanel_defaults_alter($properties, $account) {

  $properties['distinct_id'] = $account->name;

}

When i see in system table weight of my custom module is 1000 and weight of Mixpanel is 0.

Please suggest! Thanks

  • 2
    Alter functions takes the variables as references. Try using &$properties instead of just $properties, and &$account in place of $account. – AjitS Dec 7 '15 at 7:03
  • Thank you. as per your suggestion it worked :) I think you can post it as answer if you want to so that it can help other users as well. – jas Dec 7 '15 at 7:06
2

The error is how you define the parameters, which should be defined as custom_mixpanel_defaults_alter(&$properties, $account).
PHP 5 automatically passes by reference any object passed to a function, but not the arrays. Since $properties is an array, you need to make the reference explicit.

Generally speaking, when you see a call to drupal_alter() like drupal_alter('node_view', $build), and you need to implement that alter hook, check the second and third parameter are object or arrays; in the case they are array, you need to explicitly declare the parameter as reference. In this case, hook_node_view_alter() is defined as hook_node_view_alter(&$build).

| improve this answer | |
  • Thanks for explanation! and so it means we do not need to pass $account as reference &$account as its not array ? – jas Dec 7 '15 at 7:13
  • Exactly: $account is an object, so PHP 5 will automatically pass it as reference. – kiamlaluno Dec 7 '15 at 7:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.