function gdpr_consent_form_user_profile_form_alter in GDPR Consent 7
Implements hook_form_FORM_ID_alter().
File
- ./
gdpr_consent.module, line 566 - Module file for GDPR Consent.
Code
function gdpr_consent_form_user_profile_form_alter(&$form, $form_state) {
global $language, $user;
if (!empty($user->language)) {
$lang = $user->language;
}
else {
$lang = $language->language;
}
$accepted = FALSE;
$account = $form['#user'];
// If this profile belongs to user 1 or if it has an exempt user role we don't
// display Consent. Pass the user of the profile being viewed, not
// the current user.
if (gdpr_consent_user_is_exempt($account)) {
return;
}
if ($form['#user_category'] != 'account') {
return;
}
// Set reminder to change password if coming from one time login link and
// user hasn't changed his/her password yet.
if (isset($_REQUEST['pass-reset-token']) && isset($_COOKIE['Drupal_visitor_gdpr_consent_pass_reset'])) {
user_cookie_delete('gdpr_consent_pass_reset');
$messages = drupal_get_messages('status', FALSE);
$status_messages = isset($messages['status']) ? $messages['status'] : array();
$reminder = t('You have just used your one-time login link. It is no longer necessary to use this link to log in. Please change your password.');
if (!in_array($reminder, $status_messages)) {
drupal_set_message($reminder);
}
}
// Get last accepted version for this account.
$gdpr_consent_account = gdpr_consent_get_accept($account->uid);
// If no version has been accepted yet, get version with current
// language revision.
if (empty($gdpr_consent_account['version'])) {
$conditions = gdpr_consent_get_conditions($lang);
// No conditions set yet.
if (empty($conditions['conditions'])) {
return;
}
}
else {
// Get version / revision of last accepted language.
$conditions = gdpr_consent_get_conditions($lang);
// No conditions set yet.
if (empty($conditions['conditions'])) {
return;
}
// Check latest version of Consent has been accepted.
$accepted = gdpr_consent_version_check($account->uid, $conditions['version'], $conditions['revision'], $gdpr_consent_account);
// Enable language switching if version accepted and revision up to date.
if ($accepted && $gdpr_consent_account['language'] != $lang) {
$conditions = gdpr_consent_get_conditions($lang);
}
}
$form = array_merge($form, gdpr_consent_display_fields($conditions));
if ($accepted === TRUE) {
$form['gdpr_consent']['gdpr_consent_accept']['#default_value'] = 1;
}
// Disable checkbox if user is not account owner.
if ($account->uid != $user->uid) {
$form['gdpr_consent']['gdpr_consent_accept']['#attributes'] = array(
'disabled' => 'disabled',
);
}
// Show last changes.
$form = gdpr_consent_display_changes($form, $user->uid);
$form['gdpr_consent']['#description'] = '<label>' . t('Data processing consent') . '</label>';
if (!empty($form['changes']['bullet_points']['#markup'])) {
$form['gdpr_consent']['#description'] .= t('Changes since last approval:<br />@bullet_points<br/>', array(
'@bullet_points' => $form['changes']['bullet_points']['#markup'],
));
}
$form['#submit'][] = 'gdpr_consent_accept_form_submit';
$form = theme('gdpr_consent_display', array(
'form' => $form,
));
}