function ctools_context_get_context_from_context

Return a context object from a context definition array.

The input $context contains the information needed to identify and invoke the context plugin and create the plugin context from that.

Parameters

array $context: The configuration of a context. It must contain the following data:

  • name: The name of the context plugin being used.
  • context_settings: The configuration based upon the plugin forms.
  • identifier: The human readable identifier for this context, usually defined by the UI.
  • keyword: The keyword used for this context for substitutions.

string $type: This is either 'context' which indicates the context will be loaded from data in the settings, or 'requiredcontext' which means the context must be acquired from an external source. This is the method used to pass pure contexts from one system to another.

mixed $argument: Optional information passed to the plugin context via the arg defined in the plugin's "placeholder name" field.

Return value

ctools_context|null A context object if one can be loaded.

See also

ctools_get_context()

ctools_plugin_get_function()

2 calls to ctools_context_get_context_from_context()
ctools_context_get_context_from_contexts in includes/context.inc
Retrieve a list of base contexts based upon a simple 'contexts' definition.
ctools_context_replace_placeholders in includes/context.inc
Replace placeholders with real contexts using data extracted from a form for the purposes of previews.

File

includes/context.inc, line 1519

Code

function ctools_context_get_context_from_context($context, $type = 'context', $argument = NULL) {
    ctools_include('plugins');
    $plugin = ctools_get_context($context['name']);
    $function = ctools_plugin_get_function($plugin, 'context');
    if ($function) {
        // Backward compatibility: Merge old style settings into new style:
        if (!empty($context['context_settings'])) {
            $context += $context['context_settings'];
            unset($context['context_settings']);
        }
        if (isset($argument) && isset($plugin['placeholder name'])) {
            $context[$plugin['placeholder name']] = $argument;
        }
        $return = $function($type == 'requiredcontext', $context, TRUE, $plugin);
        if ($return) {
            $return->identifier = $context['identifier'];
            $return->page_title = isset($context['title']) ? $context['title'] : '';
            $return->keyword = $context['keyword'];
            if (!empty($context->empty)) {
                $context->placeholder = array(
                    'type' => 'context',
                    'conf' => $context,
                );
            }
            return $return;
        }
    }
    return NULL;
}