Problem/Motivation

It is not possible to modify variables outside the 'page' key in a page preprocess event, and as a result it's not possible to change the cache settings ('#cache') of the page template.

All bundled preprocess events expose access to the hooks $variables using generic get/set/remove/getByReference methods. Additional getters are provided per event type, such as getNode() or getElement(). The PageEventVariables class however limits the scope of the accessors to 'page' key.

Changing the behaviour of the PageEventVariables class is a major BC break, and not required for most use-cases. But I do believe it's important to allow changing the cache settings of the page template.

Proposed resolution

I've attached a patch that allows adding cache contexts to the page template. It also adds a method to get a reference to the full $variables array - I don't see a use-case for it, but I'm sure somebody will need to do that one day so it makes sense to support that as well.

Comments

jsst created an issue. See original summary.

jsst’s picture

pdenooijer’s picture

Thanks jsst!

  • pdenooijer committed 80e7906 on 8.x-1.x authored by jsst
    Issue #3030687 by jsst, pdenooijer: Support changing cache settings in...
pdenooijer’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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