You are here

function context_ui_export in Context 5

Same name and namespace in other branches
  1. 6 context_ui/context_ui.admin.inc \context_ui_export()
  2. 6.2 context_ui/context_ui.admin.inc \context_ui_export()

Provides a form with an exported context definition for use in modules.

Parameters

$cid: A context id.

Return value

A FormAPI array.

1 string reference to 'context_ui_export'
context_ui_menu in context_ui/context_ui.module
Implementation of hook_menu().

File

context_ui/context_ui_admin.inc, line 451

Code

function context_ui_export($cid = NULL) {
  if (is_numeric($cid) && ($context = context_ui_context('load', $cid))) {
    drupal_set_title(t('Export %title', array(
      '%title' => $context->value,
    )));

    // help text -- too bad the help module in 5 doesn't take wildcards
    $help = t('You can use exported contexts in your modules by returning an array of defined contexts in <code>hook_context_define()</code>.');

    // prune system specific information and cast for Drupal's AOP (array oriented programming)
    unset($context->cid);
    unset($context->status);
    unset($context->system);
    $context = (array) $context;

    // clean up blocks
    foreach ($context['block'] as $bid => $block) {
      unset($block->bid);
      $context['block'][$bid] = (array) $block;
    }

    // export
    $export = '$items[] = ' . var_export($context, true) . ';';

    // build the form
    $form = array();
    $form['help'] = array(
      '#type' => 'item',
      '#value' => $help,
    );
    $form['export'] = array(
      '#type' => 'textarea',
      '#rows' => 24,
      '#default_value' => $export,
    );
    return $form;
  }
  else {
    drupal_goto('admin/build/context');
    return;
  }
}