It would save me some code if we added a 3rd param to context_get. The new param is a callback function (with arguments) which will be called if there is a cache miss. So if this 3rd param is specified then cache_get will always return a value. Here is the patch (untested), with docs.
I'm not positive this is a good idea but lets discuss.
| Comment | File | Size | Author |
|---|---|---|---|
| mw.patch | 1.13 KB | moshe weitzman |
Comments
Comment #1
jmiccolis commentedI see the value with using function to establish context, but I'm not sure about doing at at in context_get. I don't think I want to make it possible to set context in what is explicity a '_get' function. I'm curious as to how your using context where this has come up - is this inside a panels setup?
I've been looking with a clean way to set a context value as a function - either by using a object (with methods) to establish an entire context namespace, or pushing an anonymous function in as a context value. Either approach could be quite useful and provide a lot of flexibility with how a context could behave, but so far I'm not really happy with any of these approaches.
Comment #2
moshe weitzman commentedYes, this came up within panels.
How about context_get_always() or context_get_callback(). I suggest 'always' because you are guaranteed to get a context back from this call.
Comment #3
moshe weitzman commentedAny further thoughts here? The menu system works with callback functions so it would be quite drupalish to use them here.
Comment #4
dmitrig01 commented<?
+ context_set($space, $key = null, $return);
?>
Comment #5
dmitrig01 commentedI'm sort of neutral on the idea. We don't do that kind of thing with cache - we use the if (!cache_get()) cache_set() etc. type of thing, and that's currently what context does. So IMO it's drupalish how it is too
Comment #6
paulocsClosing all issues from 5.x.* as it is not supported anymore.
If you need this in the supported issues, please open another issue.