function ctools_context_match_requirements in Chaos Tool Suite (ctools) 7
Same name and namespace in other branches
- 6 includes/context.inc \ctools_context_match_requirements()
Are there enough contexts for a plugin?
Some plugins can have a 'required contexts' item which can either be a context requirement object or an array of them. When contexts are required, items that do not have enough contexts should not appear. This tests an item to see if it has enough contexts to actually appear.
Parameters
$contexts: A keyed array of all available contexts.
$required: The required context object or array of objects.
Return value
bool True if there are enough contexts, otherwise False.
2 calls to ctools_context_match_requirements()
- ctools_content_get_available_types in includes/
content.inc - Get an array of all available content types that can be fed into the display editor for the add content list.
- ctools_get_relevant_access_plugins in includes/
context.inc - Fetch a list of access plugins that are available for a given list of contexts.
File
- includes/
context.inc, line 637 - Contains code related to the ctools system of 'context'.
Code
function ctools_context_match_requirements($contexts, $required) {
if (!is_array($required)) {
$required = array(
$required,
);
}
// Get the keys to avoid bugs in PHP 5.0.8 with keys and loops.
// And use it to remove optional contexts.
$keys = array_keys($required);
foreach ($keys as $key) {
if (empty($required[$key]->required)) {
unset($required[$key]);
}
}
$count = count($required);
return count(ctools_context_filter($contexts, $required)) >= $count;
}