We needed to be able to force people to 're-agree' if the site cookie policies changed. The easiest way to do this was to modify this module so that the 'cookie-agreed' name could be set via the UI. So to force people to agree again, just change the name of the cookie.

Attached to the first comment below is a patch that does this. Requires the update.php process to be run to add the new config defaults (but will work if it has not been run). The cookie name can be set at the bottom of the admin GUI form. Defaults to current name.

Comments

cgmonroe created an issue. See original summary.

cgmonroe’s picture

Status: Active » Needs review
StatusFileSize
new3.81 KB

Here's the patch file based on Dev branch. Will apply to Beta6.

Status: Needs review » Needs work
naveenvalecha’s picture

Thanks for the patch that would be great addition.

  1. +++ b/config/install/eu_cookie_compliance.settings.yml
    @@ -1,4 +1,5 @@
    +cookie_name: 'cookie-agreed'
    

    Also define the schema of cookie in eu_cookie_compliance.schema.yml

  2. +++ b/eu_cookie_compliance.install
    @@ -4,3 +4,12 @@
    +/**
    + * Add cookie_name property to the default configuration.
    + */
    +function eu_cookie_compliance_update_8001() {
    +  $config_factory = \Drupal::configFactory();
    +  $config = $config_factory->getEditable('eu_cookie_compliance.settings');
    +  $config->set('cookie_name', 'cookie-agreed');
    +  $config->save(TRUE);
    +}
    

    we need hook_post_update_NAME
    https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Extension...

  3. +++ b/eu_cookie_compliance.module
    @@ -139,6 +139,7 @@ function eu_cookie_compliance_page_attachments(&$attachments) {
    +        'cookie_name'          => !empty($config->get('cookie_name')) ? $config->get('cookie_name') : "cookie-agreed",
    

    use single quotes instead of double quotes.

naveenvalecha’s picture

Issue tags: +Needs tests

Needs tests for hook_post_update_NAME path

cgmonroe’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new5.92 KB

Here's a modified version with missing schema changes, update_n moved to post_update, and a quick and dirty test to check the schema was created and the default value updated.

Status: Needs review » Needs work
naveenvalecha’s picture

+++ b/src/Tests/Update/EuCookieComplianceUpdateTest.php
@@ -64,4 +64,27 @@ class EuCookieComplianceUpdateTest extends UpdatePathTestBase {
+  /**
+   * Tests that the cookie_name has been properly added to the configuration
+   * ¶
+   * @see eu_cookie_compliance_post_update_add_cookie_name_configuration()
+   */
+  public function testPostUpdateCookieNameConfig() {
+
+    // Test that the schema configuration exists for new property.
+    $definition = \Drupal::service('config.typed')
+      ->getDefinition('eu_cookie_compliance.settings');
+    $this->assertTrue(isset($definition['mapping']['cookie_name']), 'Check that a cookie_name schema mapping exists');
+    $expected = array(
+      'type' => 'text',
+      'label' => 'Cookie Name',
+    );
+    $this->assertEqual($expected, $definition['mapping']['cookie_name'], 'Check the cookie_name mapping values are correct');
+
+    // Test that the default value was correctly updated.
+    $config = \Drupal::config('eu_cookie_compliance.settings');
+    $cookie_name  = $config->get('cookie_name');
+    $this->assertEqual($cookie_name, 'cookie-agreed', 'Check default cookie name is set');
+  }
+

This should be in another Test class and fixtures should be updated.

naveenvalecha’s picture

Here are the steps that needs to follow to write the update path test:

  1. Install Drupal with standard profile.
  2. Install this module without patch.
  3. Create dump using php ./core/scripts/dump-database-d8-mysql.php --no-ansi|gzip > modules/contrib/eu-cookie-compliance/tests/fixtures/update/drupal-8.eu-cookie-compliance-beta6.standard.php.gz
  4. Create new test class EuCookieComplianceUpdateCookieTest extending UpdatePathTestBase.
  5. Use both dump files as databaseDumpFiles.
  6. And test it like this.
      public function testPostUpdateAddCookieConfig() {
      }
naveenvalecha’s picture

Issue tags: +Novice, +Needs reroll

The patch also needs a reroll

svenryen’s picture

Beta10 brings this feature to 8.x. This was committed in #2900092: Port 7.x javascript code and bug fixes

svenryen’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.