Loading modules/onetrust_cookie_blocking/onetrust_cookie_blocking.module +3 −2 Original line number Diff line number Diff line Loading @@ -90,13 +90,14 @@ function onetrust_cookie_blocking_page_attachments_alter(array &$attachments) { if (\Drupal::moduleHandler()->moduleExists('google_analytics')) { foreach ($attachments['#attached']['html_head'] as $key => $htmlhead) { if (is_array($htmlhead) && isset($htmlhead[0]['#value']) && preg_match("/GoogleAnalyticsObject/", $htmlhead[0]['#value'], $matches)) { $file_default_scheme = \Drupal::config('system.file')->get('default_scheme'); preg_match("/^\(function.*/", $htmlhead[0]['#value'], $ga_match); $ga_js = '/ga.js'; $ga_file_path = \Drupal::service('file_system')->realpath(file_default_scheme() . "://") . $ga_js; $ga_file_path = \Drupal::service('file_system')->realpath($file_default_scheme . "://") . $ga_js; $filepath = $ga_file_path; onetrust_cookie_blocking_create_gajs($filepath, $ga_match[0]); $base_wrapper = \Drupal::service('stream_wrapper_manager')->getViaScheme(file_default_scheme()); $base_wrapper = \Drupal::service('stream_wrapper_manager')->getViaScheme($file_default_scheme); $ga_js_path = $base_wrapper::baseUrl() . $ga_js; // Attach the GA file to the OneTrust API. Loading modules/onetrust_cookie_blocking/src/Form/GDPROneTrustCookieBlocking.php +3 −3 Original line number Diff line number Diff line Loading @@ -33,11 +33,11 @@ class GDPROneTrustCookieBlocking extends FormBase { '#type' => 'textarea', '#title' => $this->t('External JS'), '#default_value' => $config->get('external_js_cookie'), '#description' => t('Add Javascript URL along with the cookie category separated by | symbol, '#description' => $this->t('Add Javascript URL along with the cookie category separated by | symbol, add one javascript path on each row. eg: path/jsfile|cookie_category_id cookie_category_id: 2 => Preformance, 3 => Functional, 4 => Targetting.'), ]; $form['submit'] = ['#type' => 'submit', '#value' => t('Submit')]; $form['submit'] = ['#type' => 'submit', '#value' => $this->t('Submit')]; return $form; } Loading @@ -50,7 +50,7 @@ class GDPROneTrustCookieBlocking extends FormBase { ->set('external_js_cookie', $form_state->getValue('external_js_cookie')) ->set('ga_performance_cookies', $form_state->getValue('ga_performance_cookies')) ->save(); drupal_set_message('GDPR Onetrust Configuration has been saved.'); $this->messenger()->addMessage('GDPR Onetrust Configuration has been saved.'); } } src/Form/GDPROneTrustForm.php +27 −12 Original line number Diff line number Diff line Loading @@ -5,12 +5,31 @@ namespace Drupal\gdpr_onetrust\Form; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageManager; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Build configuration form. */ class GDPROneTrustForm extends FormBase { protected $languages; /** * {@inheritdoc} */ public function __construct(LanguageManager $language_manager) { $this->languages = $language_manager->getLanguages(); } /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static( $container->get('language_manager') ); } /** * Get formid. */ Loading @@ -29,9 +48,8 @@ class GDPROneTrustForm extends FormBase { * Verify the compatibility with previous version. */ public function getGdprConfigInfo() { $languages = \Drupal::languageManager()->getLanguages(); $config = $this->config('gdpr_onetrust.settings'); if (count($languages) == 1 && !is_null($config->get('gdpr_onetrust_compliance_uuid'))) { if (count($this->languages) == 1 && !is_null($config->get('gdpr_onetrust_compliance_uuid'))) { return TRUE; } else { Loading @@ -43,9 +61,8 @@ class GDPROneTrustForm extends FormBase { * Build configuration form. */ public function buildForm(array $form, FormStateInterface $form_state) { $languages = \Drupal::languageManager()->getLanguages(); $config = $this->config('gdpr_onetrust.settings'); foreach ($languages as $language) { foreach ($this->languages as $language) { $lang_id = $language->getId(); $field_name = 'gdpr_onetrust_compliance_uuid_' . $lang_id; if ($this->getGdprConfigInfo()) { Loading @@ -53,12 +70,12 @@ class GDPROneTrustForm extends FormBase { } $form[$field_name] = [ '#type' => 'textfield', '#title' => t('UUID for the language') . ' - ' . $language->getName(), '#title' => $this->t('UUID for the language') . ' - ' . $language->getName(), '#default_value' => $config->get($field_name), '#description' => t('Sets the UUID provided by One Trust. This is language dependent.'), '#description' => $this->t('Sets the UUID provided by One Trust. This is language dependent.'), ]; } $form['submit'] = ['#type' => 'submit', '#value' => t('Submit')]; $form['submit'] = ['#type' => 'submit', '#value' => $this->t('Submit')]; return $form; } Loading @@ -67,8 +84,7 @@ class GDPROneTrustForm extends FormBase { */ public function validateForm(array &$form, FormStateInterface $form_state) { $gdpr_onetrust_compliance_uuid = $form_state->getValue('gdpr_onetrust_compliance_uuid'); $languages = \Drupal::languageManager()->getLanguages(); foreach ($languages as $language) { foreach ($this->languages as $language) { $lang_id = $language->getId(); $field_name = 'gdpr_onetrust_compliance_uuid_' . $lang_id; if ($this->getGdprConfigInfo()) { Loading @@ -87,8 +103,7 @@ class GDPROneTrustForm extends FormBase { * Form submit handler. */ public function submitForm(array &$form, FormStateInterface $form_state) { $languages = \Drupal::languageManager()->getLanguages(); foreach ($languages as $language) { foreach ($this->languages as $language) { $lang_id = $language->getId(); $field_name = 'gdpr_onetrust_compliance_uuid_' . $lang_id; if ($this->getGdprConfigInfo()) { Loading @@ -99,7 +114,7 @@ class GDPROneTrustForm extends FormBase { ->set($field_name, $form_value) ->save(); } drupal_set_message('GDPR Onetrust Configuration has been saved.'); $this->messenger()->addMessage('GDPR Onetrust Configuration has been saved.'); } } src/Plugin/Block/OneTrustCookieSettings.php +1 −1 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ class OneTrustCookieSettings extends BlockBase { */ public function build() { return [ '#markup' => "<a class='optanon-toggle-display'>" . t('Cookie Settings') . "</a>", '#markup' => "<a class='optanon-toggle-display'>" . $this->t('Cookie Settings') . "</a>", ]; } Loading Loading
modules/onetrust_cookie_blocking/onetrust_cookie_blocking.module +3 −2 Original line number Diff line number Diff line Loading @@ -90,13 +90,14 @@ function onetrust_cookie_blocking_page_attachments_alter(array &$attachments) { if (\Drupal::moduleHandler()->moduleExists('google_analytics')) { foreach ($attachments['#attached']['html_head'] as $key => $htmlhead) { if (is_array($htmlhead) && isset($htmlhead[0]['#value']) && preg_match("/GoogleAnalyticsObject/", $htmlhead[0]['#value'], $matches)) { $file_default_scheme = \Drupal::config('system.file')->get('default_scheme'); preg_match("/^\(function.*/", $htmlhead[0]['#value'], $ga_match); $ga_js = '/ga.js'; $ga_file_path = \Drupal::service('file_system')->realpath(file_default_scheme() . "://") . $ga_js; $ga_file_path = \Drupal::service('file_system')->realpath($file_default_scheme . "://") . $ga_js; $filepath = $ga_file_path; onetrust_cookie_blocking_create_gajs($filepath, $ga_match[0]); $base_wrapper = \Drupal::service('stream_wrapper_manager')->getViaScheme(file_default_scheme()); $base_wrapper = \Drupal::service('stream_wrapper_manager')->getViaScheme($file_default_scheme); $ga_js_path = $base_wrapper::baseUrl() . $ga_js; // Attach the GA file to the OneTrust API. Loading
modules/onetrust_cookie_blocking/src/Form/GDPROneTrustCookieBlocking.php +3 −3 Original line number Diff line number Diff line Loading @@ -33,11 +33,11 @@ class GDPROneTrustCookieBlocking extends FormBase { '#type' => 'textarea', '#title' => $this->t('External JS'), '#default_value' => $config->get('external_js_cookie'), '#description' => t('Add Javascript URL along with the cookie category separated by | symbol, '#description' => $this->t('Add Javascript URL along with the cookie category separated by | symbol, add one javascript path on each row. eg: path/jsfile|cookie_category_id cookie_category_id: 2 => Preformance, 3 => Functional, 4 => Targetting.'), ]; $form['submit'] = ['#type' => 'submit', '#value' => t('Submit')]; $form['submit'] = ['#type' => 'submit', '#value' => $this->t('Submit')]; return $form; } Loading @@ -50,7 +50,7 @@ class GDPROneTrustCookieBlocking extends FormBase { ->set('external_js_cookie', $form_state->getValue('external_js_cookie')) ->set('ga_performance_cookies', $form_state->getValue('ga_performance_cookies')) ->save(); drupal_set_message('GDPR Onetrust Configuration has been saved.'); $this->messenger()->addMessage('GDPR Onetrust Configuration has been saved.'); } }
src/Form/GDPROneTrustForm.php +27 −12 Original line number Diff line number Diff line Loading @@ -5,12 +5,31 @@ namespace Drupal\gdpr_onetrust\Form; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageManager; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Build configuration form. */ class GDPROneTrustForm extends FormBase { protected $languages; /** * {@inheritdoc} */ public function __construct(LanguageManager $language_manager) { $this->languages = $language_manager->getLanguages(); } /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static( $container->get('language_manager') ); } /** * Get formid. */ Loading @@ -29,9 +48,8 @@ class GDPROneTrustForm extends FormBase { * Verify the compatibility with previous version. */ public function getGdprConfigInfo() { $languages = \Drupal::languageManager()->getLanguages(); $config = $this->config('gdpr_onetrust.settings'); if (count($languages) == 1 && !is_null($config->get('gdpr_onetrust_compliance_uuid'))) { if (count($this->languages) == 1 && !is_null($config->get('gdpr_onetrust_compliance_uuid'))) { return TRUE; } else { Loading @@ -43,9 +61,8 @@ class GDPROneTrustForm extends FormBase { * Build configuration form. */ public function buildForm(array $form, FormStateInterface $form_state) { $languages = \Drupal::languageManager()->getLanguages(); $config = $this->config('gdpr_onetrust.settings'); foreach ($languages as $language) { foreach ($this->languages as $language) { $lang_id = $language->getId(); $field_name = 'gdpr_onetrust_compliance_uuid_' . $lang_id; if ($this->getGdprConfigInfo()) { Loading @@ -53,12 +70,12 @@ class GDPROneTrustForm extends FormBase { } $form[$field_name] = [ '#type' => 'textfield', '#title' => t('UUID for the language') . ' - ' . $language->getName(), '#title' => $this->t('UUID for the language') . ' - ' . $language->getName(), '#default_value' => $config->get($field_name), '#description' => t('Sets the UUID provided by One Trust. This is language dependent.'), '#description' => $this->t('Sets the UUID provided by One Trust. This is language dependent.'), ]; } $form['submit'] = ['#type' => 'submit', '#value' => t('Submit')]; $form['submit'] = ['#type' => 'submit', '#value' => $this->t('Submit')]; return $form; } Loading @@ -67,8 +84,7 @@ class GDPROneTrustForm extends FormBase { */ public function validateForm(array &$form, FormStateInterface $form_state) { $gdpr_onetrust_compliance_uuid = $form_state->getValue('gdpr_onetrust_compliance_uuid'); $languages = \Drupal::languageManager()->getLanguages(); foreach ($languages as $language) { foreach ($this->languages as $language) { $lang_id = $language->getId(); $field_name = 'gdpr_onetrust_compliance_uuid_' . $lang_id; if ($this->getGdprConfigInfo()) { Loading @@ -87,8 +103,7 @@ class GDPROneTrustForm extends FormBase { * Form submit handler. */ public function submitForm(array &$form, FormStateInterface $form_state) { $languages = \Drupal::languageManager()->getLanguages(); foreach ($languages as $language) { foreach ($this->languages as $language) { $lang_id = $language->getId(); $field_name = 'gdpr_onetrust_compliance_uuid_' . $lang_id; if ($this->getGdprConfigInfo()) { Loading @@ -99,7 +114,7 @@ class GDPROneTrustForm extends FormBase { ->set($field_name, $form_value) ->save(); } drupal_set_message('GDPR Onetrust Configuration has been saved.'); $this->messenger()->addMessage('GDPR Onetrust Configuration has been saved.'); } }
src/Plugin/Block/OneTrustCookieSettings.php +1 −1 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ class OneTrustCookieSettings extends BlockBase { */ public function build() { return [ '#markup' => "<a class='optanon-toggle-display'>" . t('Cookie Settings') . "</a>", '#markup' => "<a class='optanon-toggle-display'>" . $this->t('Cookie Settings') . "</a>", ]; } Loading