You are here

function rb_misc_load_variant_context_entities in Rules Bonus Pack 7

Helper function to fetch fully loaded context objects from a PM variant.

Parameters

<object> $handler: The variant (task) handler, as defined and provided by CTools.

<array> $base_contexts: An array of contexts loaded by arguments in the Page manager variant.

Return value

<array> A keyed array of entity objects, with their Rules configuration names used as keys.

1 call to rb_misc_load_variant_context_entities()
rb_misc_ctools_render_alter in ./rb_misc.module
Implements hook_ctools_render_alter().

File

./rb_misc.module, line 162
A necessary file for letting Drupal know this is a module. All functionality goes into rb_misc.rules.inc.

Code

function rb_misc_load_variant_context_entities($handler, $base_contexts) {

  // Get a list of all entity types supported by Rules, and a list of fully
  // loaded objects provided as contexts in the variant.
  $supported_entity_types = rb_misc_entity_keys();
  $potential_entities = ctools_context_handler_get_handler_contexts($base_contexts, $handler);

  // Build the list of objects to send as variables to Rules.
  $entities = array();
  foreach ($potential_entities as $entity_name => $potential_entity) {

    // Check the types for each potential entity, 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] = $potential_entity->data;
      }
    }
  }
  return $entities;
}