FormWarning.php in General Data Protection Regulation Compliance 8
File
src/Utility/FormWarning.php
View source
<?php
namespace Drupal\gdpr_compliance\Utility;
use Drupal\Core\Url;
class FormWarning {
public static function addWarning(&$form) {
$link = \Drupal::config('gdpr_compliance.settings')
->get('from-morelink');
if (substr($link, 0, 1) == '/') {
$url = Url::fromUserInput($link);
}
else {
$url = Url::fromUri($link);
}
$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,
];
}
}
}