Commit 59f504f6 authored by Sven Berg Ryen's avatar Sven Berg Ryen
Browse files

Issue #3269529 by svenryen, ProperCroc: Warning "Your privacy policy link is...

Issue #3269529 by svenryen, ProperCroc: Warning "Your privacy policy link is pointing at the front page" should be ommited when there is no translation active
parent 6740c4d8
Loading
Loading
Loading
Loading
+26 −8
Changes for eu_cookie_compliance.install: 26 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ use Drupal\Core\Config\Entity\ConfigEntityType;
use Drupal\Core\Site\Settings;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\eu_cookie_compliance\Entity\CookieCategoryInterface;
use Drupal\language\ConfigurableLanguageManagerInterface;
use Drupal\user\Entity\Role;
use Drupal\Core\Database\Database;
use Drupal\filter\Entity\FilterFormat;
@@ -129,23 +130,27 @@ function eu_cookie_compliance_requirements($phase) {

  $language_manager = \Drupal::languageManager();

  $default_language = $language_manager->getDefaultLanguage();
  // Retrieve the show privacy button setting here as it's universal for all
  // languages.
  $show_policy = Drupal::config('eu_cookie_compliance.settings')->get('show_more_info');

  if ($language_manager instanceof ConfigurableLanguageManagerInterface && $phase === 'runtime') {

    // Get all configured languages.
    $languages = $language_manager->getLanguages();
    // Store a reference to the current language.
    $current_language = $language_manager->getCurrentLanguage();

  if ($phase === 'runtime') {
    foreach ($languages as $key => $language) {
      // Set the language override.
      $language_manager->setConfigOverrideLanguage($language);
      $config = $language_manager->getLanguageConfigOverride($language->getId(), 'eu_cookie_compliance.settings');

      // Get the config variables. This will use the overridden language.
      $popup_link = Drupal::config('eu_cookie_compliance.settings')
        ->get('popup_link');
      $show_policy = Drupal::config('eu_cookie_compliance.settings')->get('show_more_info');
      $popup_link = $config->get('popup_link');

      // Check the current language for wrongly configured policy link.
      if ($popup_link === '<front>' && $show_policy) {
      if ($popup_link === '<front>' && $show_policy && $default_language->getId() !== $language->getId()) {
        $requirements['eu_cookie_compliance_' . $key] = [
          'title' => t('EU Cookie Compliance'),
          'severity' => REQUIREMENT_WARNING,
@@ -154,10 +159,23 @@ function eu_cookie_compliance_requirements($phase) {
        ];
      }
    }
  }

    // Reset the language manager.
    $language_manager->setConfigOverrideLanguage($current_language);
  }
  if ($phase === 'runtime') {
    // Get the config variables.
    $popup_link = Drupal::config('eu_cookie_compliance.settings')
      ->get('popup_link');

    if ($popup_link === '<front>' && $show_policy) {
      $requirements['eu_cookie_compliance'] = [
        'title' => t('EU Cookie Compliance'),
        'severity' => REQUIREMENT_WARNING,
        'description' => t('Language @language_id: Your privacy policy link is pointing at the front page. This is the default value after installation, and unless your privacy policy is actually posted at the front page, you will need to create a separate page for the privacy policy and link to that page.', ['@language_id' => $default_language->getName()]),
        'value' => t('Privacy policy link not provided'),
      ];
    }
  }

  return $requirements;
}