You are here

function piwik_reports_form_user_form_alter in Piwik Reports 8

Implements hook_form_FORM_ID_alter().

File

./piwik_reports.module, line 38
Contains piwik_reports.module.

Code

function piwik_reports_form_user_form_alter(&$form, $form_state, $form_id) {
  $x = 1;
  $config = \Drupal::config('piwik_reports.piwikreportssettings');
  $account = $form_state
    ->getFormObject()
    ->getEntity();
  $userData = \Drupal::service('user.data');
  if ($account
    ->hasPermission('access piwik reports') && $config
    ->get('piwik_reports_token_auth') == '') {
    $account = \Drupal::currentUser();
    $form['piwik_reports'] = array(
      '#type' => 'fieldset',
      '#title' => t('Piwik reports configuration'),
      '#weight' => 3,
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $form['piwik_reports']['piwik_reports_token_auth'] = array(
      '#type' => 'textfield',
      '#title' => t('Piwik authentication string'),
      '#default_value' => !empty($userData
        ->get('piwik_reports', $account
        ->id(), 'piwik_reports_token_auth')) ? $userData
        ->get('piwik_reports', $account
        ->id(), 'piwik_reports_token_auth') : '',
      '#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>. Or just ask the Piwik server administrator.'),
    );

    // hook_user_update() is missing in D8, add custom submit handler.
    $form['actions']['submit']['#submit'][] = 'piwik_reports_user_profile_form_submit';
  }
}