You are here

function ctools_context_replace_form in Chaos Tool Suite (ctools) 6

Same name and namespace in other branches
  1. 7 includes/context.inc \ctools_context_replace_form()

Provide a form array for getting data to replace placeholder contexts with real data.

File

includes/context.inc, line 1246
Contains code related to the ctools system of 'context'.

Code

function ctools_context_replace_form(&$form, $contexts) {
  foreach ($contexts as $cid => $context) {
    if (empty($context->empty)) {
      continue;
    }

    // Get plugin info from the context which should have been set when the
    // empty context was created.
    $info = NULL;
    $plugin = NULL;
    $settings = NULL;
    switch ($context->placeholder['type']) {
      case 'argument':
        $info = $context->placeholder['conf'];
        $plugin = ctools_get_argument($info['name']);
        $settings = $info['settings'];
        break;
      case 'context':
        $info = $context->placeholder['conf'];
        $plugin = ctools_get_context($info['name']);
        $settings = $info['context_settings'];
        break;
    }

    // Ask the plugin where the form is.
    if ($plugin && isset($plugin['placeholder form'])) {
      if (is_array($plugin['placeholder form'])) {
        $form[$cid] = $plugin['placeholder form'];
      }
      else {
        if (function_exists($plugin['placeholder form'])) {
          $widget = $plugin['placeholder form']($info['settings']);
          if ($widget) {
            $form[$cid] = $widget;
          }
        }
      }
      if (!empty($form[$cid])) {
        $form[$cid]['#title'] = t('@identifier (@keyword)', array(
          '@keyword' => '%' . $context->keyword,
          '@identifier' => $context->identifier,
        ));
      }
    }
  }
}