Attached is a module called Context Variable for review for inclusion in the Context Extras package. What this module does:

Provide a Condition called "Variable Match" which allows for a condition of a key pair matching a variable in drupal's database. Here are some example uses of this module:

--Add a block based on whether or not a value in a custom module is set
--react to changes in theme settings as opposed to theme
--react to changes made on a Space per Space basis as this hits variable_get which obeys Strongarm's ability to override

This module has a special condition for active theme to allow for things like this:
theme_%theme_settings|toggle_primary_links:0

This condition would say when the active theme in a OG / Space has primary links unchecked, then do XYZ.

If the best place to submit this is a new module then let me know and I'll put this there but wanted to add to an impressive context package and flush it out further.

EDIT: here are two videos walking through how this works -- https://drupal.psu.edu/blog/260 and http://screencast.com/t/9UD6AI2U

CommentFileSizeAuthor
context_var.zip5.52 KBbtopro

Comments

hadsie’s picture

Status: Needs review » Needs work

Hey @btopro,

I think this one would be really useful. But it appears there's a lot of possibly unnecessary code in the module. In context_var_context_condition.inc you have: $current_path = drupal_get_path_alias($_GET['q']); but $current_path doesn't seem to be used. As well, there's a bunch of OG and theme specific code in there that I don't understand. Shouldn't this basically be as simple as running a variable_get() on the variables in question and comparing the results?

I do have a concern about the variables and stuff though, because sometimes users will be working with complex objects and arrays. Perhaps it would be much simpler and more comprehensive the entire serialized string was used? Also, how will long strings with line breaks in them work?

- Scott

btopro’s picture

good questions. If there's still that's left over it's cause I patterned it off the excluding path context plugin.

%theme should probably be replaced with actual tokens, original use case was being able to tap into the theme_{themename}_settings variable and then reading a specific value within that variable. Right now I have this code working to see if the theme that's currently active has primary links turned on. as well as creating cases like "if primary links are turned on and 2ndary links are turned off in this theme, do xyz".

Most use-cases would be more of the form:

site_footer|Cool stuff

to provide a reaction to the site footer based on cool stuff.

"Perhaps it would be much simpler and more comprehensive the entire serialized string was used? Also, how will long strings with line breaks in them work?"
Not following what you mean by the entire serialized string. Do you mean checking that all values of an array stored in the variables table be checked? Right now the : operator allows for an added level of granularity.

Not sure that long strings with line breaks in them would work, currently don't have a case where this is happening in the values I'm tapping.

btopro’s picture

Status: Needs work » Fixed

added as it's own module in-case anyone were to find this thread.

http://drupal.org/project/context_var

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

EDIT: here are two videos walking through how this works -- https://drupal.psu.edu/blog/260 and http://screencast.com/t/9UD6AI2U