You are here

function piwik_reports_form_alter in Piwik Reports 7.2

Same name and namespace in other branches
  1. 6 piwik_reports.module \piwik_reports_form_alter()
  2. 7.4 piwik_reports.module \piwik_reports_form_alter()
  3. 7.3 piwik_reports.module \piwik_reports_form_alter()

Implements hook_form_alter().

File

./piwik_reports.module, line 213
Defines features and functions common to Piwik Reports

Code

function piwik_reports_form_alter(&$form, $form_state, $form_id) {

  // Extend the form in "user/{userid}/edit/account".
  if ($form_id == 'user_profile_form' && $form['#user_category'] == 'account' && user_access('access site reports') && variable_get('piwik_token_auth', '') == '') {
    global $user;

    // Make sure the fieldset is also visible if user do not have permission
    // on the form field "Enable user tracking" in the main piwik module.
    // Additional the fieldset shouldn't be overriden by this hook if still active.
    if (empty($form['piwik'])) {
      $form['piwik'] = array(
        '#type' => 'fieldset',
        '#title' => t('Piwik configuration'),
        '#weight' => 3,
        '#collapsible' => TRUE,
        '#tree' => TRUE,
      );
    }
    $form['piwik']['piwik_token_auth'] = array(
      '#type' => 'textfield',
      '#title' => t('Piwik authentication string'),
      '#default_value' => !empty($user->data['piwik']['piwik_token_auth']) ? $user->data['piwik']['piwik_token_auth'] : 'anonymous',
      '#size' => 40,
      '#maxlength' => 40,
      '#description' => t('Click the <strong>Settings</strong> link in your Piwik account, then the <strong>Users</strong> tab and copy and paste your personal <strong>token_auth</strong> value into this field. If anonymous users have view permissions in Piwik you can set this value to <strong>anonymous</strong>.'),
    );
  }
  elseif ($form_id == 'piwik_admin_settings_form') {
    $form['piwik_reports'] = array(
      '#type' => 'fieldset',
      '#title' => t('Piwik reports token_auth'),
      '#weight' => 0,
      '#description' => t('To see piwik reports in Drupal you need a <strong>token_auth</strong> value. You can find it in the  <strong>Users</strong> tab under the <strong>Settings</strong> link in your Piwik account.'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $form['piwik_reports']['piwik_token_auth'] = array(
      '#type' => 'textfield',
      '#title' => t('Piwik authentication string'),
      '#default_value' => variable_get('piwik_token_auth', ''),
      '#size' => 40,
      '#maxlength' => 40,
      '#description' => t('Leave blank if you prefer each user setting his own, or paste it here to have a global <strong>token_auth</strong>. If anonymous users have view permissions in Piwik you can set this value to <strong>anonymous</strong>. In any case users still need adequate permissions in Drupal to see the reports.'),
    );
  }
}