When clearing the cache, several "Notice: Undefined index" messages will appear. This is because eu_cookie_compliance_get_settings() does not set a default value for all settings.

Comments

Liam Morland created an issue. See original summary.

liam morland’s picture

Assigned: liam morland » Unassigned
Status: Active » Needs review
StatusFileSize
new1.55 KB
krina.addweb’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new203.42 KB
new51.24 KB

@Liam Morland, Your patch is working fine & removes the error that shown after clearing the caches. I checked it with the reference of simplytest.me and local & attached the screenshots for the same.

svenryen’s picture

Thanks Liam, and Krina for the RTBC. I'll commit later.

svenryen’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new1.62 KB

I reviewed the attached patch. In my opinion this issue still needs work.

Let's say you already have a value for "cookie_categories" in the database. What the updated code does is it will first load the popup banner settings from the database, then it adds (and in my opinion overwrites the value coming from the database with) a new value, being NULL.

(Note I haven't run the resulting code after applying your patch, but my impression is that this will happen. Feel free to correct me if I'm wrong).

If we first initialize the default $popup_settings array and then afterwards add the values from the database, we will not have this problem.

Do you agree, Liam? Here's an updated patch. Can somebody review?

travis-bradbury’s picture

Status: Needs review » Needs work

+ $popup_settings += variable_get('eu_cookie_compliance', array());

That should be variable_get(...) + $popup_settings to set defaults. The values in that variable will not overwrite what's in $popup_settings.

Does this fix the problem generally or just for a few settings? My site has 40 values in the eu_cookie_compliance variable but this only guarantees 7 exist.

svenryen’s picture

Does this fix the problem generally or just for a few settings? My site has 40 values in the eu_cookie_compliance variable but this only guarantees 7 exist.

I should think so. Most settings have a default fallback when used. But if you say so, it wouldn't hurt to specify all defaults in this function.

liam morland’s picture

#6 is correct: The defaults have to be added to the configured values; they will not overwrite existing values, only set a value where one does not exist. The patch in #2 does it this way.

It is easy to add additional values to the defaults.

I don't think this needs a D8 port since eu_cookie_compliance_get_settings() doesn't exist in the D8 version.

liam morland’s picture

Status: Needs work » Needs review

Re-submitting the patch in #2 for review.

svenryen’s picture

Status: Needs review » Fixed

  • svenryen authored 77d2353 on 7.x-1.x
    Issue #3064610 by Liam Morland, svenryen, krina.addweb: Undefined index...

  • svenryen authored 77d2353 on 7.x-2.x
    Issue #3064610 by Liam Morland, svenryen, krina.addweb: Undefined index...

Status: Fixed » Closed (fixed)

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