You are here

function _variable_realm_union_realm_keys in Variable 7

Produce keys for union realm.

1 string reference to '_variable_realm_union_realm_keys'
variable_realm_union_variable_realm_info_alter in variable_realm_union/variable_realm_union.variable.inc
Implements hook_variable_realm_info_alter();

File

variable_realm_union/variable_realm_union.variable.inc, line 25
Variable hooks for variable_realm_union.

Code

function _variable_realm_union_realm_keys($realm_name, $realm_info) {
  $union = array_combine($realm_info['union'], $realm_info['union']);
  $all_realm_keys = array_map('variable_realm_keys', $union);

  // First build all combinations of realm keys.
  $combine = array(
    array(
      'keys' => array(),
      'names' => array(),
    ),
  );
  foreach ($all_realm_keys as $realm => $realm_keys) {
    $new_combine = array();
    foreach ($combine as $index => $data) {
      foreach ($realm_keys as $new_key => $new_name) {
        $keys = $data['keys'];
        $names = $data['names'];
        $keys[$realm] = $new_key;
        $names[$realm] = $new_name;
        $new_combine[] = array(
          'keys' => $keys,
          'names' => $names,
        );
      }
    }
    $combine = $new_combine;
  }

  // Now build all realm keys for the combinations.
  $keys = array();
  foreach ($combine as $data) {
    $key = variable_realm_union_build_key($realm_name, $data['keys']);
    $name = variable_realm_union_build_name($realm_name, $data['names']);
    $keys[$key] = $name;
  }
  return $keys;
}