You are here

function context_ui_import_submit in Context 5

Same name and namespace in other branches
  1. 6 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 412

Code

function context_ui_import_submit($form_id, $form_values) {
  $items = array();
  if ($import = $form_values['import']) {
    ob_start();
    eval($import);
    ob_end_clean();
  }
  if (is_array($items) && count($items)) {
    $context = current($items);
  }
  if (is_array($context)) {
    $context = (object) $context;
    $context->system = FALSE;
    if ($exists = context_ui_context('load', $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');
      return 'admin/build/context';
    }
    else {
      drupal_set_title(t('Add context'));
      $output = drupal_get_form('context_ui_form', 'add', null, (object) $context);
      print theme('page', $output);
      exit;
    }
  }
  else {
    drupal_set_message(t('An error occurred while importing. Please check your context definition.', 'error'));
    return 'admin/build/context';
  }
}