Commit 29a03fe9 authored by Sven Berg Ryen's avatar Sven Berg Ryen
Browse files

Issue #3274594 by svenryen, John_B: 8.x: We sometimes hit the cache before...

Issue #3274594 by svenryen, John_B: 8.x: We sometimes hit the cache before getting geographic location
parent bb9abfeb
Loading
Loading
Loading
Loading
+33 −12
Changes for src/Form/EuCookieComplianceConfigForm.php: 33 added lines, 12 removed lines.
Original line number Diff line number Diff line
@@ -838,17 +838,29 @@ class EuCookieComplianceConfigForm extends ConfigFormBase {
    ];

    if ($this->moduleHandler->moduleExists('smart_ip') || $this->moduleHandler->moduleExists('geoip') || extension_loaded('geoip')) {
      $form['eu_only']['eu_only'] = [
        '#type' => 'checkbox',
        '#title' => $this->t('Only display banner in EU countries.'),
        '#default_value' => !empty($config->get('eu_only')) ? $config->get('eu_only') : 0,
        '#description' => $this->t('You can limit the number of countries for which the banner is displayed by checking this option. If you want to provide a list of countries other than current EU states, you may place an array in <code>$config[\'eu_cookie_compliance.settings\'][\'eu_countries\']</code> in your <code>settings.php</code> file. Using the <a href="http://drupal.org/project/smart_ip">smart_ip</a> module or using the <a href="http://drupal.org/project/geoip">geoip</a> module or the <a href="http://www.php.net/manual/en/function.geoip-country-code-by-name.php">geoip_country_code_by_name()</a> PHP function.'),
      $form['eu_only']['eu_info'] = [
        '#type' => 'markup',
        '#markup' => $this->t('<p>You can limit the number of countries for which the banner is displayed. If you want to provide a list of countries other than current EU states, you may place an array in <code>$conf[\'eu_cookie_compliance_eu_countries\']</code> in your <code>settings.php</code> file. Using the <a href="http://drupal.org/project/geoip">geoip</a> module or the <a href="http://drupal.org/project/smart_ip">smart_ip</a> module or the <a href="http://www.php.net/manual/en/function.geoip-country-code-by-name.php">geoip_country_code_by_name()</a> PHP function.</p>'),
      ];
      $form['eu_only']['eu_only_js'] = [
        '#type' => 'checkbox',
        '#title' => $this->t('JavaScript-based (for Varnish): Only display banner in EU countries.'),
        '#default_value' => !empty($config->get('eu_only_js')) ? $config->get('eu_only_js') : 0,
        '#description' => $this->t('This option also works for visitors that bypass Varnish. You can limit the number of countries for which the banner is displayed by checking this option. If you want to provide a list of countries other than current EU states, you may place an array in <code>$config[\'eu_cookie_compliance.settings\'][\'eu_countries\']</code> in your <code>settings.php</code> file. Using the <a href="http://drupal.org/project/smart_ip">smart_ip</a> module or the <a href="http://www.php.net/manual/en/function.geoip-country-code-by-name.php">geoip_country_code_by_name()</a> PHP function.'),

      if ($config->get('eu_only') == 1) {
        $eu_option_default_value = 'eu_only';
      }
      elseif ($config->get('eu_only_js') == 1) {
        $eu_option_default_value = 'eu_only_js';
      }
      else {
        $eu_option_default_value = 'disabled';
      }

      $form['eu_only']['eu_option'] = [
        '#type' => 'radios',
        '#options' => [
          'eu_only_js' => $this->t('Use JavaScript to determine if the visitor is in a country where GDPR applies. Required if caching is enabled or a caching strategy such as varnish is utilized.'),
          'eu_only' => $this->t('I have no caching enabled or set up. Use non-JavaScript method.'),
          'disabled' => $this->t('Disabled. Show the banner to all visitors, also those in non-GDPR countries.'),
        ],
        '#default_value' => $eu_option_default_value,
      ];
    }
    else {
@@ -1110,6 +1122,15 @@ class EuCookieComplianceConfigForm extends ConfigFormBase {
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $eu_only = 0;
    $eu_only_js = 0;
    if ($form_state->getValue('eu_option') === 'eu_only') {
      $eu_only = 1;
    }
    elseif ($form_state->getValue('eu_option') === 'eu_only_js') {
      $eu_only_js = 1;
    }

    // Clear values if we are using minimal css.
    if ($form_state->getValue('use_bare_css')) {
      $form_state->setValue('popup_bg_hex', '');
@@ -1237,8 +1258,8 @@ class EuCookieComplianceConfigForm extends ConfigFormBase {
      ->set('cookie_lifetime', $form_state->getValue('cookie_lifetime'))
      ->set('cookie_session', $form_state->getValue('cookie_session'))
      ->set('set_cookie_session_zero_on_disagree', $form_state->getValue('set_cookie_session_zero_on_disagree'))
      ->set('eu_only', $form_state->getValue('eu_only'))
      ->set('eu_only_js', $form_state->getValue('eu_only_js'))
      ->set('eu_only', $eu_only)
      ->set('eu_only_js', $eu_only_js)
      ->set('use_bare_css', $form_state->getValue('use_bare_css'))
      ->set('disagree_do_not_show_popup', $form_state->getValue('disagree_do_not_show_popup'))
      ->set('reload_page', $form_state->getValue('reload_page'))