You are here

social_gdpr.module in Open Social 10.2.x

Contains social_gdpr.module.

File

modules/custom/social_gdpr/social_gdpr.module
View source
<?php

/**
 * @file
 * Contains social_gdpr.module.
 */
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\data_policy\Entity\DataPolicy;

/**
 * Implements hook_help().
 */
function social_gdpr_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {

    // Main module help for the social_gdpr module.
    case 'help.page.social_gdpr':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Integrate Data Policy module.') . '</p>';
      return $output;
  }
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function social_gdpr_form_data_policy_data_policy_agreement_alter(&$form, FormStateInterface $form_state, $form_id) {
  if (isset($form['not_agree'])) {
    $form['not_agree']['#tag'] = 'small';
  }
}

/**
 * Implements hook_form_FORM_ID_alter().
 *
 * Move the GDPR checkbox into the account fieldset if it's available.
 */
function social_gdpr_form_user_register_form_alter(&$form, FormStateInterface $form_state) {
  if (isset($form['data_policy'], $form['account'])) {
    $form['account']['data_policy'] = $form['data_policy'];
    unset($form['data_policy']);

    // Provide it with a weight so it'll sit at the bottom relative to the other
    // user registration form fields.
    $form['account']['data_policy']['#weight'] = 100;
  }
}

/**
 * Implements hook_social_user_account_header_links().
 */
function social_gdpr_social_user_account_header_links() {
  $items = [];
  if (\Drupal::service('data_policy.manager')
    ->needConsent()) {
    $items['data_policy_agreement'] = [
      'title' => t('Data policy agreement'),
      'url' => Url::fromRoute('data_policy.data_policy.agreement'),
      'after' => 'edit_profile',
      'divider' => 'before',
    ];
  }
  return $items;
}