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.

CommentFileSizeAuthor
mw.patch1.13 KBmoshe weitzman

Comments

jmiccolis’s picture

I 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.

moshe weitzman’s picture

Yes, 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.

moshe weitzman’s picture

Any further thoughts here? The menu system works with callback functions so it would be quite drupalish to use them here.

dmitrig01’s picture

Status: Needs review » Needs work

<?
+ context_set($space, $key = null, $return);
?>

dmitrig01’s picture

I'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

paulocs’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)

Closing all issues from 5.x.* as it is not supported anymore.
If you need this in the supported issues, please open another issue.