I've searched but couldnt find a similar topic.

How do i import context setting programmatically? I looked at the code generated by Context export facility; but now i don't know what to do with it! Does it go in the .module file like an imagecache preset?

I've seen other examples of inserting context programmatically, for instance this:

$context = array(
	  'namespace' => 'context_ui',
	  'attribute' => 'section',
	  'value' => 'reviews',
	  'description' => 'reviews context',
	  'path' => array(
	   'reviews/*'=>'reviews/*',
	   'review/*'=>'review/*'  
	  ), 
	  'menu' => 'reviews',
	);
	context_save_context((object) $context);

But throws an undefined function error. Can someone please help? Im trying to replace existing context setting with the new one above!

Cheers

Comments

Greg Varga’s picture

Export the context object using the Context export tool (provided by CTools) and use the context_save function to import.
You can also create an array and convert it to an object if you like.
For more details, see context_save(), line 231; context.module

$context = new stdClass;
$context->disabled = FALSE; /* Edit this to true to make a default context disabled initially */
$context->api_version = 3;
$context->name = 'news';
$context->description = '';
$context->tag = '';
$context->conditions = array(
  'node' => array(
    'values' => array(
      'news' => 'news',
    ),
    'options' => array(
      'node_form' => '1',
    ),
  ),
);
$context->reactions = array(
  'menu' => 'news',
);

context_save($context);
Prine’s picture

Sorry for late reply, this is perfect. Thanks very much for the heads up :)