You are here

function context_ui_import_submit in Context 6

Same name and namespace in other branches
  1. 5 context_ui/context_ui_admin.inc \context_ui_import_submit()
  2. 6.2 context_ui/context_ui.admin.inc \context_ui_import_submit()

Import form submit handler. Evaluates import code and transfers to context definition form.

File

context_ui/context_ui.admin.inc, line 496

Code

function context_ui_import_submit($form, &$form_state) {
  $items = array();
  if ($import = $form_state['values']['import']) {
    if (strpos($import, 'return') !== 0) {
      $import = "return {$import}";
    }
    ob_start();
    $context = eval($import);
    ob_end_clean();
  }
  if (is_array($context)) {
    $context = (object) $context;
    if ($exists = context_load_context($context)) {
      drupal_set_message(t('A user-defined context definition with this space/key/value identifier already exists. Please remove the existing context before importing this definition.'), 'error');
      $form_state['redirect'] = 'admin/build/context';
    }
    else {
      drupal_set_title(t('Add context'));
      $output = drupal_get_form('context_ui_form', 'add', (object) $context);
      print theme('page', $output);
      exit;
    }
  }
  else {
    drupal_set_message(t('An error occurred while importing. Please check your context definition.', 'error'));
    $form_state['redirect'] = 'admin/build/context';
  }
}