Example #1
0
/**
 * Block preprocessing
 */
function fusion_core_preprocess_block(&$vars)
{
    global $theme_info, $user;
    static $grid;
    // Exit if block is outside a defined region
    if (!in_array($vars['block']->region, array_keys($theme_info->info['regions']))) {
        return;
    }
    // Initialize grid info once per page
    if (!isset($grid)) {
        $grid = fusion_core_grid_info();
    }
    // Increment block count for current block's region, add first/last position class
    $grid['regions'][$vars['block']->region]['count']++;
    $region_count = $grid['regions'][$vars['block']->region]['count'];
    $total_blocks = $grid['regions'][$vars['block']->region]['total'];
    $vars['classes_array'][] = $region_count == 1 ? 'first' : '';
    $vars['classes_array'][] = $region_count == $total_blocks ? 'last' : '';
    $vars['classes_array'][] = $vars['block_zebra'];
    // Set a default block width if not already set by Fusion Apply
    $classes = implode(' ', $vars['classes_array']);
    // Special treatment for node_top and node_bottom regions.
    // They are rendered inside of the $content region, so they need to be adjusted to fit the grid properly.
    $assign_grid_units = $vars['block']->region == 'node_top' || $vars['block']->region == 'node_bottom' ? FALSE : TRUE;
}
Example #2
0
/**
 * Block preprocessing
 */
function fusion_core_preprocess_block(&$vars) {
  global $theme_info, $user;
  static $grid;

  // Exit if block is outside a defined region
  if (!in_array($vars['block']->region, array_keys($theme_info->info['regions']))) {
    return;
  }

  // Initialize grid info once per page
  if (!isset($grid)) {
    $grid = fusion_core_grid_info();
  }

  // Increment block count for current block's region, add first/last position class
  $grid['regions'][$vars['block']->region]['count'] ++;
  $region_count = $grid['regions'][$vars['block']->region]['count'];
  $total_blocks = $grid['regions'][$vars['block']->region]['total'];
  $vars['classes_array'][] = ($region_count == 1) ? 'first' : '';
  $vars['classes_array'][] = ($region_count == $total_blocks) ? 'last' : '';
  $vars['classes_array'][] = $vars['block_zebra'];

  // Set a default block width if not already set by Skinr
  $classes = implode(' ', $vars['classes_array']);
  
  // Special treatment for node_top and node_bottom regions.  
  // They are rendered inside of the $content region, so they need to be adjusted to fit the grid properly.
  $assign_grid_units = ($vars['block']->region == 'node_top' || $vars['block']->region == 'node_bottom') ? FALSE : TRUE;
    
  if (strpos($classes, $grid['name']) === false && $assign_grid_units) {
    // Stack blocks vertically in sidebars by setting to full sidebar width
    if ($vars['block']->region == 'sidebar_first') {
      $width = $grid['fixed'] ? $grid['sidebar_first_width'] : $grid['width'];  // Sidebar width or 100% (if fluid)
    }
    elseif ($vars['block']->region == 'sidebar_second') {
      $width = $grid['fixed'] ? $grid['sidebar_second_width'] : $grid['width'];  // Sidebar width or 100% (if fluid)
    }
    else {
      // Default block width = region width divided by total blocks, adding any extra width to last block
      $region_width = ($grid['fixed']) ? $grid['regions'][$vars['block']->region]['width'] : $grid['width'];  // fluid grid regions = 100%
      $width_adjust = (($region_count == $total_blocks) && ($region_width % $total_blocks)) ? $region_width % $total_blocks : 0;
      $width = ($total_blocks) ? floor($region_width / $total_blocks) + $width_adjust : 0;
    }
    $vars['classes_array'][] = $grid['name'] . $width;
  }
}