You are here

class FormWarning in General Data Protection Regulation Compliance 8

FormWarning helpers.

Hierarchy

Expanded class hierarchy of FormWarning

5 files declare their use of FormWarning
FormContactMessageFormAlter.php in src/Hook/FormContactMessageFormAlter.php
FormNodeFormAlter.php in src/Hook/FormNodeFormAlter.php
FormUserLoginFormAlter.php in src/Hook/FormUserLoginFormAlter.php
FormUserRegisterFormAlter.php in src/Hook/FormUserRegisterFormAlter.php
FormWebformSubmissionFormAlter.php in src/Hook/FormWebformSubmissionFormAlter.php

File

src/Utility/FormWarning.php, line 14
Contains \Drupal\gdpr_compliance\Utility\FormWarning.

Namespace

Drupal\gdpr_compliance\Utility
View source
class FormWarning {

  /**
   * Add "Cookie & Privacy Policy" warning.
   */
  public static function addWarning(&$form) {

    // Generate url for 'More information' link.
    $link = \Drupal::config('gdpr_compliance.settings')
      ->get('from-morelink');
    if (substr($link, 0, 1) == '/') {

      // A path should be handled as user input.
      $url = Url::fromUserInput($link);
    }
    else {

      // An external url should use 'fromUri'.
      $url = Url::fromUri($link);
    }

    // Check 'admin/people' & administer_users permission.
    $is_adminpath = \Drupal::request()
      ->getRequestUri() == '/admin/people/create';
    if (!$is_adminpath && empty($form['administer_users']['#value'])) {
      $form['gdpr-warning'] = [
        '#type' => 'checkbox',
        '#title' => t("I have read and agree to the Cookie & Privacy Policy"),
        '#default_value' => FALSE,
        '#required' => TRUE,
        '#attributes' => [
          'required' => 'required',
        ],
        '#description' => t("<a href='@href' target='_blank'>Cookie & Privacy Policy for Website</a>", [
          '@href' => $url
            ->toString(),
        ]),
        '#weight' => 99,
      ];
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FormWarning::addWarning public static function Add "Cookie & Privacy Policy" warning.