function ctools_context_replace_form

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

File

includes/context.inc, line 1763

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']);
                break;
            case 'context':
                $info = $context->placeholder['conf'];
                $plugin = ctools_get_context($info['name']);
                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);
                    if ($widget) {
                        $form[$cid] = $widget;
                    }
                }
            }
            if (!empty($form[$cid])) {
                $form[$cid]['#title'] = t('@identifier (@keyword)', array(
                    '@keyword' => '%' . $context->keyword,
                    '@identifier' => $context->identifier,
                ));
            }
        }
    }
}