You are here

function messaging_template_get_branch in Messaging 6.4

Build fallback sub-tree (only parents and children of given template)

1 call to messaging_template_get_branch()
messaging_template_admin_info in messaging_template/messaging_template.admin.inc
Build template description for admin pages

File

messaging_template/messaging_template.admin.inc, line 118
Messaging Framework - Admin UI

Code

function messaging_template_get_branch($find, $tree = NULL) {
  $tree = $tree ? $tree : messaging_template_get_tree();
  if ($find && isset($tree[$find])) {
    $template = $tree[$find];
    if (!empty($template['children'])) {
      $template['children'] = messaging_template_get_branch(NULL, $template['children']);
    }
    return array(
      $find => $template,
    );
  }

  // Not in this set, explore children
  foreach ($tree as $key => &$template) {
    if (!$find) {

      // Already found, we are just removing sub-chilren
      $template['children'] = NULL;
    }
    elseif (!empty($template['children']) && ($subtree = messaging_template_get_branch($find, $template['children']))) {
      $template['children'] = $subtree;
      return array(
        $key => $template,
      );
    }
  }
  return $tree;
}