Title says it all.

This patch adds hook_variable_set() and hook_variable_del(), so modules can react to changes/deletions.

CommentFileSizeAuthor
#8 hook_variables_1035940.patch2.28 KBfgm
hook-variables.patch2.04 KBAnonymous (not verified)

Comments

katbailey’s picture

Who could possibly object to something so simple and yet so awesome :-D
You've set it to D8 though :-(
Just subscribing for now.

carlos8f’s picture

Version: 7.x-dev » 8.x-dev
Status: Needs review » Needs work

So this patch needs at minimum to add hook_variable_get/set() to bootstrap_hooks(). Otherwise, the hook won't properly function until bootstrap_full.

Performance-wise I'm not so excited about adding more bootstrap hooks, or increasing the overhead of variable_get/set() by adding invokes. Invokes when added up in all variable_get() calls could cause a significant regression, even if barely any modules implement the hook.

The idea of giving modules the ability to react to every little thing is certainly inviting to module developers, but I would be cautious that so oft-used functions as these could become heavyweights as a result, i.e. who knows what stupid stuff people are going to do with this hook? :)

Anonymous’s picture

Status: Needs review » Needs work

carlos8f: the module stuff is definitely needs more investigation.

the variable_get() is a red herring ;-)

this patch has no interest in informing modules of reads, just writes.

if you do lots of writes all the time, you're doing it wrong :-)

carlos8f’s picture

oh, I see. no hook introduced for variable_get(). Whoops. Scratch the performance concerns in #2.

Just curious, what's your use case? Trying to place this conceptually in the new D8 butler/context system, which I think would gobble up variable_get/set into something more structured.

katbailey’s picture

Yeah, I can't help feeling that D8 will hopefully move towards a much more standardized way of getting in on the action of inserts and updates, not that I've been following the butler movement... (*makes note to do so*)
So this patch really should be for D7. Go on - I dare you - what's the worst that can happen? ;-)

Anonymous’s picture

Version: 8.x-dev » 7.x-dev

Well, dries did talk about this today at drupal down under...

ksenzee’s picture

Status: Needs work » Needs review

One use case is #1032700-14: Add caching to hook_admin_paths(). Core has variable_get()s in some implementations of hook_admin_paths(), so if we're going to cache results for that hook, we have to clear the cache when those variables are changed. The current patch in that issue does it in a form submit handler, which is the best we can do in current D7, but obviously won't help if somebody does a drush vset. This hook would solve that problem much more robustly and elegantly.

fgm’s picture

Version: 8.x-dev » 7.x-dev
Status: Needs work » Needs review
StatusFileSize
new2.28 KB

Added to bootstrap_hooks, and changed the array_key_exists() to an isset: since we set to NULL when key does not exist, the net result is the same, although the test logic is not identical.

Anonymous’s picture

Issue tags: +Needs tests, +Needs committer feedback

Awesome, thanks fgm.

Now we need tests and we need webchick and dries to look at this.

jonathan1055’s picture

Subscribing.
Sorry to clutter the issue thread, but we don't have any other way to be notified of individual thread updates or get them in our personal 'my issues' queue, do we?

Jonathan

Anonymous’s picture

Assigned: » Unassigned
marcingy’s picture

Version: 7.x-dev » 8.x-dev

Bumping to d8

moshe weitzman’s picture

xjm’s picture

Issue summary: View changes
Issue tags: -Needs tests, -Needs committer feedback