function rb_misc_list_variant_context_entities in Rules Bonus Pack 7
Helper function to get a list of all configured context objects in variant.
This function catches the *types* of entities in a Page manager variant, used to declare the trigger events for Rules.
Parameters
<array> $task: A task array, as defined and provided by CTools.
<object> $handler: A task handler object, as defined and provided by CTools.
Return value
<array> An array matching the format Rules uses to declare variables provided by events. The key names (used for variable names) are based on the somewhat cumbersome IDs of the context objects in Page manager.
1 call to rb_misc_list_variant_context_entities()
- _rb_misc_add_variant_render_events in ./
rb_misc.rules.inc - Helper function that adds event information for Page manager page variants.
File
- ./
rb_misc.module, line 118 - A necessary file for letting Drupal know this is a module. All functionality goes into rb_misc.rules.inc.
Code
function rb_misc_list_variant_context_entities($task, $subtask, $handler) {
// Include some files that may not be loaded when this function is called from
// outside Page manager.
ctools_include('context', 'ctools', 'includes');
ctools_include('context-task-handler', 'ctools', 'includes');
// Get a list of all entity types supported by Rules, and a list of all
// objects provided as contexts in the variant.
$supported_entity_types = rb_misc_entity_keys();
$potential_entities = ctools_context_handler_get_all_contexts($task, $subtask, $handler);
// Build an array of all context objects that Rules can handle.
$entities = array();
foreach ($potential_entities as $entity_name => $potential_entity) {
// Check the types for each potential variable, to see if any matches the
// types handles by Rules (or, rather, Entity API).
foreach ($potential_entity->type as $type) {
if (isset($supported_entity_types[$type])) {
// The variable name cannot contain colon or dashes.
$id = str_replace(':', '__', $entity_name);
$id = str_replace('-', '_', $id);
$entities[$id] = array(
'label' => $potential_entity->identifier,
'type' => $type,
);
}
}
}
return $entities;
}