You are here

function _hansel_ui_list_rules in Hansel breadcrumbs 7

Same name and namespace in other branches
  1. 8 hansel_ui/hansel_ui.module \_hansel_ui_list_rules()
1 call to _hansel_ui_list_rules()
hansel_ui_page in hansel_ui/hansel_ui.module
Page callback

File

hansel_ui/hansel_ui.module, line 43
Hansel UI module

Code

function _hansel_ui_list_rules($pid = 0) {
  $output = '';
  foreach (_hansel_get_rules($pid) as $rule) {
    $delete_path = str_replace('%', $rule->rid, 'admin/config/search/hansel/rule/%/delete');
    $config_path = str_replace('%', $rule->rid, 'admin/config/search/hansel/rule/%');
    $delete_link = '<a href="' . url($delete_path) . '" class="hansel-delete-link"><span>delete</span></a>';
    $config_link = '<a href="' . url($config_path) . '" class="hansel-config-rule-link"><span>configure rule</span></a>';
    $output .= '<div class="hansel-rule">';

    // Add rule name, configure and delete link
    $output .= '<div class="hansel-name">';
    $output .= '<span class="hansel-rule-name">' . check_plain($rule->name) . '</span>';
    $output .= '<div class="hansel-buttons">' . $config_link . ' ' . $delete_link . '</div>';
    $output .= '</div>';
    $output .= '<div class="hansel-info">';

    // Add crumb info (if any)
    if (!empty($rule->crumb_action)) {
      $output .= '<div class="hansel-crumb-info">';
      $output .= _hansel_get_crumb_action_info($rule);
      $output .= '</div>';
    }

    // Add action info
    $output .= '<div class="hansel-type">';
    switch ($rule->action) {
      case 'goto':
        $res = db_query("SELECT r.name FROM {hansel_rule} r WHERE r.rid = :rid", array(
          ':rid' => $rule->destination,
        ));
        if (!($name = $res
          ->fetchField())) {
          $name = t('(broken link)');
        }
        $output .= 'goto ' . check_plain($name);
        break;
      case 'leave':
        if ($rule->restore) {
          $output .= 'leave (restore original breadcrumbs)';
        }
        else {
          $output .= 'leave';
        }
        break;
      case 'switch':
        if (_hansel_is_configurable_switch($rule->handler)) {
          $config_path = str_replace('%', $rule->rid, 'admin/config/search/hansel/switch/%');
          $output .= 'switch on ' . l($rule->handler, $config_path);
        }
        else {
          $output .= 'switch on ' . check_plain($rule->handler);
        }
        $output .= ' ' . _hansel_get_switch_info($rule);
        break;
    }
    $output .= '</div>';

    // Add child rules (if any)
    $children = _hansel_ui_list_rules($rule->rid);
    if ($children) {
      $output .= '<div class="hansel-children">' . $children . '</div>';
    }
    $output .= '</div>';

    // Close .hansel-info
    $output .= '</div>';

    // Close .hansel-rule
  }
  return $output;
}