You are here

function gdpr_consent_accept_form in GDPR Consent 7

Consent acceptance form.

Parameters

array $form_state: Array of form elements.

Return value

string HTML code of form.

1 string reference to 'gdpr_consent_accept_form'
gdpr_consent_page in ./gdpr_consent.pages.inc
Page callback.

File

./gdpr_consent.module, line 148
Module file for GDPR Consent.

Code

function gdpr_consent_accept_form(array $form_state) {
  global $language, $user;
  if (!empty($user->language)) {
    $lang = $user->language;
  }
  else {

    // Fallback to global language if user doesn't have one.
    $lang = $language->language;
  }
  $form = array();
  $accepted = FALSE;
  $gdpr_consent_account = gdpr_consent_get_accept($user->uid);
  if (!empty($gdpr_consent_account)) {
    $conditions = gdpr_consent_get_conditions($lang);
    $accepted = gdpr_consent_version_check($user->uid, $conditions['version'], $conditions['revision'], $gdpr_consent_account);
  }
  else {
    $conditions = gdpr_consent_get_conditions($lang);
  }
  $changes = gdpr_consent_display_changes($form, $user->uid);
  drupal_add_library('system', 'drupal.collapse');
  $form['gdpr_consent']['conditions'] = array(
    '#type' => 'markup',
    '#markup' => $conditions['conditions'],
    '#weight' => 0,
    '#prefix' => '<div class="gdpr_consent-terms">',
    '#suffix' => '</div>',
  );
  if (!empty($conditions['data_details'])) {
    $form['gdpr_consent']['data_container'] = array(
      '#type' => 'fieldset',
      '#title' => t('Details on data we collect'),
      '#attributes' => array(
        'class' => array(
          'collapsible',
          'collapsed',
        ),
      ),
    );
    $form['gdpr_consent']['data_container']['data_details'] = array(
      '#type' => 'markup',
      '#markup' => $conditions['data_details'],
      '#weight' => 0,
      '#prefix' => '<div class="gdpr_consent-data_details">',
      '#suffix' => '</div>',
    );
  }
  if (!empty($changes['changes']['bullet_points']['#markup'])) {
    $form['gdpr_consent']['changes'] = array(
      '#type' => 'markup',
      '#markup' => t('<label>Description of changes to consent:</label> @bullet_points', array(
        '@bullet_points' => $changes['changes']['bullet_points']['#markup'],
      )),
      '#weight' => 1,
    );
  }
  $form['gdpr_consent']['gdpr_consent_accept'] = array(
    '#type' => 'checkbox',
    '#title' => theme('gdpr_consent_accept_label'),
    '#default_value' => $accepted,
    '#weight' => 50,
  );
  $form['save'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  $form = theme('gdpr_consent_display', array(
    'form' => $form,
  ));
  return $form;
}