function ctools_context_optional::select

Select and return one context from the list of applicable contexts.

Fundamentally, this returns $contexts[$context] or the empty context if that does not exist.

Parameters

array $contexts: The applicable contexts to check.

string $context: The context id to check for.

Return value

bool|ctools_context The matching ctools_context, or False if no such context was found.

Overrides ctools_context_required::select

See also

ctools_context_required::select()

File

includes/context.inc, line 465

Class

ctools_context_optional
Used to compare to see if a list of contexts match an optional context. This can produce empty contexts to use as placeholders.

Code

public function select($contexts, $context) {
    
    /**
     * @todo We are assuming here that $contexts is actually an array, whereas
     * ctools_context_required::select permits ctools_context objects as well.
     */
    $this->add_empty($contexts);
    if (empty($context)) {
        return $contexts['empty'];
    }
    $result = parent::select($contexts, $context);
    // Don't flip out if it can't find the context; this is optional, put
    // in an empty.
    if ($result === FALSE) {
        $result = $contexts['empty'];
    }
    return $result;
}