Ïnitial Commit module v1.0.2
This commit is contained in:
parent
73decbbd0f
commit
24dce862d6
13 changed files with 298 additions and 0 deletions
13
composer.json
Normal file
13
composer.json
Normal file
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"name": "seers_cookie_consent_privacy_policy",
|
||||
"type": "drupal-module",
|
||||
"description": "Seers cookie consent fulfils the requirements of transparency, consent and documentation under ePrivacy Directive and GDPR.",
|
||||
"keywords": [
|
||||
],
|
||||
"homepage": "https://www.drupal.org/project/seers_cookie_consent_privacy_policy",
|
||||
"minimum-stability": "dev",
|
||||
"support": {
|
||||
"issues": "https://www.drupal.org/project/issues/seers_cookie_consent_privacy_policy",
|
||||
"source": "http://cgit.drupalcode.org/seers_cookie_consent_privacy_policy"
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
seers_cookie_consent_privacy_policy:
|
7
css/cookie-style.css
Normal file
7
css/cookie-style.css
Normal file
|
@ -0,0 +1,7 @@
|
|||
|
||||
/*
|
||||
* For Cookie Policy & Cookie Declarations
|
||||
*/
|
||||
.cx-policy-container, .cx-table-container {
|
||||
width: 100% !important;
|
||||
}
|
6
seers_cookie_consent_privacy_policy.info.yml
Normal file
6
seers_cookie_consent_privacy_policy.info.yml
Normal file
|
@ -0,0 +1,6 @@
|
|||
name: 'Seers Cookie Consent Banner Privacy Policy'
|
||||
type: module
|
||||
description: 'Seers cookie consent fulfils the requirements of transparency, consent and documentation under ePrivacy Directive and GDPR.'
|
||||
core: 8.x
|
||||
core_version_requirement: ^7 || ^8 || ^9
|
||||
package: 'Custom'
|
5
seers_cookie_consent_privacy_policy.libraries.yml
Normal file
5
seers_cookie_consent_privacy_policy.libraries.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
global:
|
||||
version: VERSION
|
||||
css:
|
||||
theme:
|
||||
css/cookie-style.css: {}
|
6
seers_cookie_consent_privacy_policy.links.menu.yml
Normal file
6
seers_cookie_consent_privacy_policy.links.menu.yml
Normal file
|
@ -0,0 +1,6 @@
|
|||
seers_cookie_consent_privacy_policy.seer_cookie_consent_form:
|
||||
title: 'SeerCookieConsentForm'
|
||||
route_name: seers_cookie_consent_privacy_policy.seer_cookie_consent_form
|
||||
description: 'Enter your cookie id'
|
||||
parent: system.admin_config_system
|
||||
weight: 99
|
81
seers_cookie_consent_privacy_policy.module
Normal file
81
seers_cookie_consent_privacy_policy.module
Normal file
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains seers_cookie_consent_privacy_policy.module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_install().
|
||||
*/
|
||||
function seers_cookie_consent_privacy_policy_install()
|
||||
{
|
||||
$modulename = basename(__FILE__, '.module');
|
||||
|
||||
\Drupal::service('custom_functions')->doActiveInactive(1, $modulename);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_preprocess().
|
||||
*/
|
||||
function seers_cookie_consent_privacy_policy_preprocess_page(&$variables, $hook)
|
||||
{
|
||||
|
||||
$variables['#attached']['library'][] = 'seers_cookie_consent_privacy_policy/global';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_page_attachments().
|
||||
*/
|
||||
function seers_cookie_consent_privacy_policy_page_attachments(&$page)
|
||||
{
|
||||
$config = \Drupal::config('seers_cookie_consent_privacy_policy.seercookieconsent')->getRawData();
|
||||
/**
|
||||
* Initial JS.
|
||||
*/
|
||||
if (!empty($config["cookie_id"])) {
|
||||
$page['#attached']['html_head'][] = [
|
||||
[
|
||||
// Add a <script> tag.
|
||||
'#tag' => 'script',
|
||||
// Add attributes to the <script> tag.
|
||||
'#attributes' => [
|
||||
'src' => 'https://cmp.seersco.com/script/cb.js',
|
||||
'type' => 'text/javascript',
|
||||
'data-key' => $config["cookie_id"],
|
||||
'data-name' => 'CookieXray',
|
||||
'async' => false
|
||||
],
|
||||
// Give weight so it appears after meta tags, etc.
|
||||
'#weight' => -1,
|
||||
],
|
||||
// A key, to make it possible to recognize this HTML <HEAD> element when altering.
|
||||
'seers cookie consent'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_preprocess_region().
|
||||
*/
|
||||
function seers_cookie_consent_privacy_policy_preprocess_region(&$variables)
|
||||
{
|
||||
if ($variables['region'] == 'content') {
|
||||
$content = $variables['content']->__toString();
|
||||
$variables['content'] = Drupal\Core\Render\Markup::create($content . '<div id="seers-cookie-consent"></div>');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function seers_cookie_consent_privacy_policy_uninstall()
|
||||
{
|
||||
$modulename = basename(__FILE__, '.module');
|
||||
|
||||
\Drupal::service('custom_functions')->doActiveInactive(0, $modulename);
|
||||
|
||||
}
|
9
seers_cookie_consent_privacy_policy.routing.yml
Normal file
9
seers_cookie_consent_privacy_policy.routing.yml
Normal file
|
@ -0,0 +1,9 @@
|
|||
seers_cookie_consent_privacy_policy.seer_cookie_consent_form:
|
||||
path: '/admin/config/seers_cookie_consent_privacy_policy/seercookieconsent'
|
||||
defaults:
|
||||
_form: '\Drupal\seers_cookie_consent_privacy_policy\Form\SeerCookieConsentForm'
|
||||
_title: 'SeerCookieConsentForm'
|
||||
requirements:
|
||||
_permission: 'access administration pages'
|
||||
options:
|
||||
_admin_route: TRUE
|
3
seers_cookie_consent_privacy_policy.services.yml
Normal file
3
seers_cookie_consent_privacy_policy.services.yml
Normal file
|
@ -0,0 +1,3 @@
|
|||
services:
|
||||
custom_functions:
|
||||
class: '\Drupal\seers_cookie_consent_privacy_policy\Service\CustomFunctions'
|
60
src/Form/SeerCookieConsentForm.php
Normal file
60
src/Form/SeerCookieConsentForm.php
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\seers_cookie_consent_privacy_policy\Form;
|
||||
|
||||
use Drupal\Core\Form\ConfigFormBase;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Class SeerCookieConsentForm.
|
||||
*/
|
||||
class SeerCookieConsentForm extends ConfigFormBase
|
||||
{
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getEditableConfigNames()
|
||||
{
|
||||
return [
|
||||
'seers_cookie_consent_privacy_policy.seercookieconsent',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFormId()
|
||||
{
|
||||
return 'seer_cookie_consent_form';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state)
|
||||
{
|
||||
$config = $this->config('seers_cookie_consent_privacy_policy.seercookieconsent');
|
||||
$form['cookie_id'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Cookie ID'),
|
||||
'#maxlength' => 64,
|
||||
'#size' => 64,
|
||||
'#default_value' => $config->get('cookie_id'),
|
||||
];
|
||||
return parent::buildForm($form, $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function submitForm(array &$form, FormStateInterface $form_state)
|
||||
{
|
||||
parent::submitForm($form, $form_state);
|
||||
|
||||
$this->config('seers_cookie_consent_privacy_policy.seercookieconsent')
|
||||
->set('cookie_id', $form_state->getValue('cookie_id'))
|
||||
->save();
|
||||
}
|
||||
|
||||
}
|
60
src/Service/CustomFunctions.php
Normal file
60
src/Service/CustomFunctions.php
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
// The namespace is Drupal\[module_key]\[Directory\Path(s)]
|
||||
namespace Drupal\seers_cookie_consent_privacy_policy\Service;
|
||||
|
||||
/**
|
||||
* The CustomFunctions service. Does a bunch of stuff.
|
||||
*/
|
||||
class CustomFunctions {
|
||||
|
||||
public $apisecrekkey = '$2y$10$9ygTfodVBVM0XVCdyzEUK.0FIuLnJT0D42sIE6dIu9r/KY3XaXXyS';
|
||||
|
||||
/**
|
||||
* Does something.
|
||||
*
|
||||
* @return json-object or NULL
|
||||
* Some value.
|
||||
*/
|
||||
public function doActiveInactive($isactive = 0, $modulename='') {
|
||||
|
||||
$postData = array(
|
||||
'domain' => \Drupal::request()->getHost(),
|
||||
'isactive' => $isactive,
|
||||
'secret' => $this->apisecrekkey,
|
||||
'platform' => 'drupal',
|
||||
'pluginname' => $modulename
|
||||
);
|
||||
$request_headers = array(
|
||||
'Content-Type' => 'application/json',
|
||||
'Referer' => \Drupal::request()->getHost(),
|
||||
);
|
||||
//$url = "https://seersco.backend/api/plugin-domain";
|
||||
$url = "https://cmp.seersco.com/api/plugin-domain";
|
||||
$curl = curl_init();
|
||||
|
||||
curl_setopt_array($curl, array(
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_ENCODING => "",
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_TIMEOUT => 0,
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
CURLOPT_CUSTOMREQUEST => "POST",
|
||||
CURLOPT_HTTPHEADER => $request_headers,
|
||||
CURLOPT_POSTFIELDS => $postData
|
||||
));
|
||||
|
||||
$response = curl_exec($curl);
|
||||
$error_number = curl_errno($curl);
|
||||
$error_message = curl_error($curl);
|
||||
curl_close($curl);
|
||||
|
||||
$response =json_decode($response, TRUE);
|
||||
|
||||
return $response;
|
||||
|
||||
}
|
||||
|
||||
}
|
1
templates/seers-cookie-consent-privacy-policy.html.twig
Normal file
1
templates/seers-cookie-consent-privacy-policy.html.twig
Normal file
|
@ -0,0 +1 @@
|
|||
<!-- Add you custom twig html here -->
|
46
tests/src/Functional/LoadTest.php
Normal file
46
tests/src/Functional/LoadTest.php
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\seers_cookie_consent_privacy_policy\Functional;
|
||||
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
/**
|
||||
* Simple test to ensure that main page loads with module enabled.
|
||||
*
|
||||
* @group seers_cookie_consent_privacy_policy
|
||||
*/
|
||||
class LoadTest extends BrowserTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['seers_cookie_consent_privacy_policy'];
|
||||
|
||||
/**
|
||||
* A user with permission to administer site configuration.
|
||||
*
|
||||
* @var \Drupal\user\UserInterface
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->user = $this->drupalCreateUser(['administer site configuration']);
|
||||
$this->drupalLogin($this->user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the home page loads with a 200 response.
|
||||
*/
|
||||
public function testLoad() {
|
||||
$this->drupalGet(Url::fromRoute('<front>'));
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue