You are here

function context_save_context in Context 6.2

Same name and namespace in other branches
  1. 6 context.module \context_save_context()

Inserts or updates a context object into the database. @TODO: should probably return the new cid on success -- make sure this doesn't break any checks elsewhere.

Parameters

$context: The context object to be inserted.

Return value

Returns true on success, false on failure.

5 calls to context_save_context()
ContextBlocksTestCase::testContextBlockTitles in tests/context_blocks.test
Check that the block title setting is respected by Context.
ContextBlocksTestCase::testContextCustomBlockTitles in tests/context_blocks.test
Check that the block title setting is respected by Context for custom blocks.
context_ui_form_submit in context_ui/context_ui.admin.inc
Submit handler for main context_ui form.
context_update_6001 in ./context.install
Update script for context that installs the context schema and migrates any existing context data from deprecated context_ui tables.
context_update_6002 in ./context.install
Update script for API change in path condition.

File

./context.module, line 227

Code

function context_save_context($context) {

  // Insert or update the core context definition
  if (!isset($context->cid)) {
    $existing = context_load_context($context, TRUE);
    if ($existing && $existing->cid) {
      return FALSE;
    }
    else {
      $packed = context_pack_context($context);
      drupal_write_record('context', $packed);
    }
  }
  else {

    // Ensure that when saving a context an existing one isn't overwritten:
    $context_to_load = drupal_clone($context);
    unset($context_to_load->cid);
    $context_to_load = context_load_context($context_to_load, TRUE);
    if ($context_to_load->cid && $context_to_load->cid != $context->cid) {

      // We loaded a context, and it wasn't ours, abort!
      return FALSE;
    }
    else {
      $packed = context_pack_context($context);
      drupal_write_record('context', $packed, 'cid');
    }
  }

  // Invalidate context cache
  cache_clear_all('context', 'cache');
  return TRUE;
}