You are here

function piwik_reports_form_alter in Piwik Reports 6

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

Implementation of hook_form_alter().

File

./piwik_reports.module, line 212
Drupal Module: Piwik Reports Sponsored by IO1, http://www.io1.biz All code is released under the GNU General Public License.

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['_category']['#value'] == 'account' && user_access('access site reports')) {
    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->piwik['piwik_token_auth']) ? $user->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>.'),
    );
  }
}