You are here

function piwik_form_user_profile_form_alter in Piwik Web Analytics 7

Same name and namespace in other branches
  1. 7.2 piwik.module \piwik_form_user_profile_form_alter()

Implement hook_form_FORM_ID_alter().

Allow users to decide if tracking code will be added to pages or not.

File

./piwik.module, line 174
Drupal Module: Piwik Adds the required Javascript to the bottom of all your Drupal pages to allow tracking by the Piwik statistics package.

Code

function piwik_form_user_profile_form_alter(&$form, &$form_state) {
  $account = $form['#user'];
  $category = $form['#user_category'];
  if ($category == 'account' && user_access('opt-in or out of tracking') && ($custom = variable_get('piwik_custom', 0)) != 0 && _piwik_visibility_roles($account)) {
    $form['piwik'] = array(
      '#type' => 'fieldset',
      '#title' => t('Piwik configuration'),
      '#weight' => 3,
      '#collapsible' => TRUE,
      '#tree' => TRUE,
    );
    switch ($custom) {
      case 1:
        $description = t('Users are tracked by default, but you are able to opt out.');
        break;
      case 2:
        $description = t('Users are <em>not</em> tracked by default, but you are able to opt in.');
        break;
    }
    $form['piwik']['custom'] = array(
      '#type' => 'checkbox',
      '#title' => t('Enable user tracking'),
      '#description' => $description,
      '#default_value' => isset($account->data['piwik']['custom']) ? $account->data['piwik']['custom'] : $custom == 1,
    );
    return $form;
  }
}