function ctools_content_select_context

Select the context to be used for a piece of content, based upon config.

Parameters

$plugin: The content plugin

$subtype: The subtype of the content.

$conf: The configuration array that should contain the context.

$contexts: A keyed array of available contexts.

Return value

The matching contexts or NULL if none or necessary, or FALSE if requirements can't be met.

3 calls to ctools_content_select_context()
ctools_content_admin_title in includes/content.inc
Get the administrative title from a given content type.
ctools_content_render in includes/content.inc
Get the content from a given content type.
views_content_views_row_content_type_admin_info in views_content/plugins/content_types/views_row.inc

File

includes/content.inc, line 779

Code

function ctools_content_select_context($plugin, $subtype, $conf, $contexts) {
    // Identify which of our possible contexts apply.
    if (empty($subtype)) {
        return;
    }
    $subtype_info = ctools_content_get_subtype($plugin, $subtype);
    if (empty($subtype_info)) {
        return;
    }
    if (!empty($subtype_info['all contexts']) || !empty($plugin['all contexts'])) {
        return $contexts;
    }
    // If the content requires a context, fetch it; if no context is returned,
    // do not display the pane.
    if (empty($subtype_info['required context'])) {
        return;
    }
    // Deal with dynamic required contexts not getting updated in the panes.
    // For example, Views let you dynamically change context info. While
    // we cannot be perfect, one thing we can do is if no context at all
    // was asked for, and then was later added but none is selected, make
    // a best guess as to what context should be used. THis is right more
    // than it's wrong.
    if (is_array($subtype_info['required context'])) {
        if (empty($conf['context']) || count($subtype_info['required context']) != count($conf['context'])) {
            foreach ($subtype_info['required context'] as $index => $required) {
                if (!isset($conf['context'][$index])) {
                    $filtered = ctools_context_filter($contexts, $required);
                    if ($filtered) {
                        $keys = array_keys($filtered);
                        $conf['context'][$index] = array_shift($keys);
                    }
                }
            }
        }
    }
    else {
        if (empty($conf['context'])) {
            $filtered = ctools_context_filter($contexts, $subtype_info['required context']);
            if ($filtered) {
                $keys = array_keys($filtered);
                $conf['context'] = array_shift($keys);
            }
        }
    }
    if (empty($conf['context'])) {
        return;
    }
    $context = ctools_context_select($contexts, $subtype_info['required context'], $conf['context']);
    return $context;
}