You are here

function template_preprocess_context_block_browser in Context 7.3

Same name and namespace in other branches
  1. 6.3 theme/context_reaction_block.theme.inc \template_preprocess_context_block_browser()
  2. 6 theme/context_reaction_block.theme.inc \template_preprocess_context_block_browser()

Preprocessor for theme('context_block_browser').

File

theme/context_reaction_block.theme.inc, line 73

Code

function template_preprocess_context_block_browser(&$vars) {
  $categories = array(
    '#type' => 'select',
    '#options' => array(
      0 => '<' . t('All Categories') . '>',
    ),
    '#attributes' => array(
      'class' => array(
        'context-block-browser-categories',
      ),
    ),
    '#value' => 0,
    '#size' => 1,
    '#id' => '',
    '#name' => '',
    '#parents' => array(
      '',
    ),
    '#multiple' => FALSE,
    '#required' => FALSE,
  );
  $blocks = array();

  // Group blocks by module.
  foreach ($vars['blocks'] as $block) {
    $group = isset($block->context_group) ? $block->context_group : $block->module;

    // Normalize the $group, borrowed from drupal_html_id
    $group = strtr(drupal_strtolower($group), array(
      ' ' => '-',
      '_' => '-',
      '[' => '-',
      ']' => '',
    ));
    if (!isset($categories[$group])) {
      $info = system_get_info('module', $block->module);
      $title = isset($block->context_group) ? $block->context_group : (!empty($info['name']) ? $info['name'] : $block->module);
      $categories['#options'][$group] = $title;
    }
    $blocks[$group][$block->bid] = $block;

    // Don't call theme('context_block_browser_item') to allow others to alter.
  }

  //add help text to tell people how to use the block browser
  $help_text = array(
    '#prefix' => '<div class="context_ui-help-text">',
    '#markup' => t('To add a block to the current region, simply click on the block. You may use the category filter to filter by block type or the search filter to find the block that you wish to add.'),
    '#suffix' => '</div>',
  );
  $filter_label = array(
    '#prefix' => '<div class="filter-label">',
    '#markup' => t('Search filter'),
    '#suffix' => '</div>',
  );
  $vars['categories'] = $categories;

  // Don't call theme('select') here to allow further preprocesses to alter the element.
  $vars['blocks'] = $blocks;
  $vars['help_text'] = $help_text;
  $vars['filter_label'] = $filter_label;
}