function matomo_reports_form_user_form_alter in Matomo Reports 8
Implements hook_form_FORM_ID_alter().
File
- ./
matomo_reports.module, line 38 - Contains matomo_reports.module.
Code
function matomo_reports_form_user_form_alter(&$form, $form_state, $form_id) {
$config = \Drupal::config('matomo_reports.matomoreportssettings');
$account = $form_state
->getFormObject()
->getEntity();
$userData = \Drupal::service('user.data');
if ($account
->hasPermission('access matomo reports') && $config
->get('matomo_reports_token_auth') == '') {
$account = \Drupal::currentUser();
$form['matomo_reports'] = [
'#type' => 'fieldset',
'#title' => t('Matomo reports configuration'),
'#weight' => 3,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
];
$form['matomo_reports']['matomo_reports_token_auth'] = [
'#type' => 'textfield',
'#title' => t('Matomo authentication string'),
'#default_value' => !empty($userData
->get('matomo_reports', $account
->id(), 'matomo_reports_token_auth')) ? $userData
->get('matomo_reports', $account
->id(), 'matomo_reports_token_auth') : '',
'#size' => 40,
'#maxlength' => 40,
'#description' => t('Click the <strong>Settings</strong> link in your Matomo 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 Matomo you can set this value to <strong>anonymous</strong>. Or just ask the Matomo server administrator.'),
];
// hook_user_update() is missing in D8, add custom submit handler.
$form['actions']['submit']['#submit'][] = 'matomo_reports_user_profile_form_submit';
}
}