Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I want to disable contexts programmatically (for automated updates, where a new release of a website needs a context to be disabled).

I manage contexts using Features, but Features doesn't hold the enabled/disabled status of the context.

I can't find a fucntion to change context status programmatically. There's a support request but the snipet is not working (nothing happends, context remiangs the same status).

After some investigations I come across the context_status variable. It seems to hold an array with context names as key and TRUE as value: each of this context is disabled. If you edit the that variable unsetting one context the context becomes enabled.

So it seems the only way to disable/enable a context programmatically is to edit this conext_status.

Is there a better way to do it?

share|improve this question
    
BTW, as context_status is a varialbe I can pack it into a feature, and move config from dev sites to prod site, but I can't just pack only one context: this variable seems to hold all system context that are disabled. –  tunic Jul 15 at 15:54
    
Thanks for the tip, it's not ideal like you say but at least it's someting we can work with. –  marcvangend Aug 19 at 9:49

1 Answer 1

up vote 2 down vote accepted

Use the context_status to enable/disable contexts.

This variable is an array with context names as key and TRUE as value: each of this context is disabled.

To disable a context: add a new pair to the array like this:

$contexts = variable_get('context_status', array());
$contexts['context_name'] = TRUE;
variable_set('context_status', $contexts);

To enable a context: unset the context name from context_status.

$contexts = variable_get('context_status', array());
unset($contexts['context_name']);
variable_set('context_status', $contexts);

Also you can use Features, exporting the context_status to a feature.

share|improve this answer
1  
Should be variable_set('context_status', $contexts); rather than variable_set('context_name', $contexts); –  codeinthehole Aug 27 at 14:18
    
Yes, you are right, thanks for pointing it out. I've updated my answer. –  tunic Aug 27 at 16:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.