You are here

function fusion_labels_page_build in Fusion Accelerator 7.2

Same name and namespace in other branches
  1. 7.3 fusion_labels/fusion_labels.module \fusion_labels_page_build()

Implements hook_page_build().

File

fusion_labels/fusion_labels.module, line 46

Code

function fusion_labels_page_build(&$page) {

  // only add region labels if the fusion "theme_grid" setting is set to true.
  if (!theme_get_setting('theme_grid')) {
    return;
  }

  // check for permission.
  if (!user_access('administer fusion labels')) {
    return false;
  }
  $current_theme = $GLOBALS['theme_key'];
  $regions = system_region_list($current_theme);
  foreach ($regions as $region => $region_label) {
    if ($region == "help") {
      continue;
    }

    // combine block's data from db with what is provided with hook_block_view().
    $debug_block_view = module_invoke('fusion_labels', 'block_view', 'fusion_region_label');
    $debug_block_data = block_load('fusion_labels', 'fusion_region_label');
    $debug_block = (object) array_merge((array) $debug_block_data, (array) $debug_block_view);
    $debug_block->subject = $region_label;
    $render_array = array(
      '#block' => $debug_block,
      '#theme_wrappers' => array(
        'block',
      ),
      '#weight' => -400,
    );
    if (isset($page[$region])) {

      // add block to all regions currently in use.
      // weight doesn't seem to be respected.  append to front of the array for now.
      array_unshift($page[$region], $render_array);
    }
    else {
      $page[$region]['fusion_region_label'] = $render_array;
    }
  }

  // add a toggle.  requires page bottom region.
  if (isset($page['page_bottom'])) {
    $page['page_bottom']['fusion_label_toggle'] = array(
      '#type' => "markup",
      '#markup' => "<div id='fusion-label-toggle'>Labels</div>",
      '#attached' => array(
        'css' => array(
          drupal_get_path('module', 'fusion_labels') . '/fusion-labels.css',
        ),
      ),
    );

    // Prints currently selected grid in upper right hand corner, below grid and label buttons.
    $responsive_displays = theme_get_setting('responsive_displays');
    if (is_array($responsive_displays)) {
      $markup = '';
      foreach ($responsive_displays as $responsive_display) {
        $width = theme_get_setting($responsive_display . '_grid_width');
        $markup .= "<div id='label_{$responsive_display}' class='debug-responsive'>{$width}</div>" . "\n";
      }
      $page['page_bottom']['fusion_grid_label'] = array(
        '#type' => "markup",
        '#markup' => $markup,
      );
    }
    drupal_add_js(drupal_get_path('module', 'fusion_labels') . '/fusion_labels.js');
  }
}