You are here

function spaces_dashboard_preprocess_context_block_browser in Spaces 6.3

Same name and namespace in other branches
  1. 7.3 spaces_dashboard/spaces_dashboard.module \spaces_dashboard_preprocess_context_block_browser()
  2. 7 spaces_dashboard/spaces_dashboard.module \spaces_dashboard_preprocess_context_block_browser()

Preprocessor for theme('context_block_browser').

File

spaces_dashboard/spaces_dashboard.module, line 338

Code

function spaces_dashboard_preprocess_context_block_browser(&$vars) {

  // Check a static cache flag that alerts us to being within the build of the
  // spaces_dashboard_editor form build.
  if (context_get('spaces_dashboard', 'form_build')) {
    foreach ($vars['blocks'] as $category => $blocks) {
      foreach ($blocks as $bid => $block) {

        // Recategorize blocks by feature.
        if (spaces_dashboard_block_access($block)) {
          $block_module = spaces_dashboard_get_module($block);
          if ($block_module != $category) {
            if (!isset($vars['categories']['#options'][$block_module])) {
              $info = context_get_info('module', $block_module);
              $vars['categories']['#options'][$block_module] = isset($info['name']) ? $info['name'] : $block_module;
            }
            unset($vars['blocks'][$category][$bid]);
            $vars['blocks'][$block_module][$bid] = $block;
          }
        }
        else {
          unset($vars['blocks'][$category][$bid]);
        }
      }
    }

    // Remove empty categories.
    foreach ($vars['categories']['#options'] as $k => $v) {
      if ($k != '0' && empty($vars['blocks'][$k])) {
        unset($vars['categories']['#options'][$k]);
      }
    }

    // Sort
    asort($vars['categories']['#options']);

    // Clear out the form build flag.
    context_set('spaces_dashboard', 'form_build', FALSE);
  }
}