Commit 048658b8 authored by Lilit Ghazaryan's avatar Lilit Ghazaryan Committed by Gobinath Mallaiyan
Browse files

Issue #3099651 by rahulrasgon, Lilit_Ghazaryan, Hardik_Patel_12,...

Issue #3099651 by rahulrasgon, Lilit_Ghazaryan, Hardik_Patel_12, aliaksandr_rozum: Remove and replace deprecated code
parent 97c4b0c4
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -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.
+3 −3
Original line number Diff line number Diff line
@@ -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;
  }

@@ -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.');
  }

}
+27 −12
Original line number Diff line number Diff line
@@ -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.
   */
@@ -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 {
@@ -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()) {
@@ -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;
  }

@@ -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()) {
@@ -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()) {
@@ -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.');
  }

}
+1 −1
Original line number Diff line number Diff line
@@ -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>",
    ];
  }