function homebox_build in Homebox 6.2
Same name and namespace in other branches
- 6.3 homebox.module \homebox_build()
- 6 homebox.module \homebox_build()
- 7.3 homebox.module \homebox_build()
- 7.2 homebox.module \homebox_build()
Responsible for firing the hook_theme()
Parameters
$page: A page object
Return value
homebox_theme() call
2 calls to homebox_build()
- homebox_og_override_group in homebox_og/
homebox_og.module - Override a group's homepage with a homebox
- homebox_pre_build_user in ./
homebox.module - Helper function for performing operations prior to rendering a Homebox that is set as a user profile tab
2 string references to 'homebox_build'
- homebox_menu in ./
homebox.module - Implementation of hook_menu().
- homebox_og_menu in homebox_og/
homebox_og.module
File
- ./
homebox.module, line 305 - Homebox main file, takes care of global functions settings constants, etc.
Code
function homebox_build($page) {
global $user;
// If no default block layout is set, return a simple message
if (empty($page->settings['blocks'])) {
return t('This page has not yet been configured.');
}
// Get every block placed into its region sorted by weight
$column_count = $page->settings['regions'];
$regions = array_fill(1, $column_count, array());
// Extract blocks from the page
$blocks = $page->settings['blocks'];
$allowed_blocks = array();
$info = array();
foreach ($page->settings['blocks'] as $block) {
if (!isset($info[$block['module']])) {
$info[$block['module']] = module_invoke($block['module'], 'block', 'list');
}
$allowed_blocks[$block['module']][$block['delta']] = $info[$block['module']][$block['delta']];
if (!empty($block['title'])) {
$allowed_blocks[$block['module']][$block['delta']]['info'] = $block['title'];
}
}
// Get user settings, so custom blocks are placed in regions.
$user_blocks = _homebox_get_user_settings($page);
if ($user_blocks !== FALSE) {
// Add custom blocks.
foreach ($user_blocks as $key => $block) {
if (isset($allowed_blocks[$block['module']][$block['delta']])) {
$blocks[$key] = $user_blocks[$key];
}
}
}
// Preparing blocks object for theming
foreach ($blocks as $key => $block_settings) {
// Adds block to its regions
if ($block_settings['status']) {
$block = homebox_prepare_block($key, $page);
if (!is_null($block)) {
// If user defined region is greater than real column count put block in
// the last column/region.
$regions[min($block->region, $column_count)][$block->weight][] = $block;
$allowed_blocks[$block->module][$block->delta]['used'] = TRUE;
}
}
}
// Sort each region/column based on key value
for ($i = 1; $i <= count($regions); $i++) {
ksort($regions[$i]);
}
// Add block links
if ($user->uid) {
$add_links = array();
foreach ($allowed_blocks as $module => $blocks) {
foreach ($blocks as $delta => $info) {
$options = array();
if (isset($info['used'])) {
$options['attributes'] = array(
'class' => 'used',
);
}
$add_links[] = homebox_add_link($info['info'], $page, $module, $delta, $options);
}
}
$add_links['restore'] = l(t('Restore to defaults'), 'homebox/' . $page->name . '/restore', array(
'attributes' => array(
'class' => 'restore',
),
));
$add_links = theme('item_list', $add_links, NULL, 'ul', array(
'class' => 'clear-block',
));
$save_form = drupal_get_form('homebox_save_form', $page);
}
else {
$add_links = NULL;
$save_form = NULL;
}
// Build output
$output = theme('homebox', $regions, $page->settings['regions'], $add_links, $save_form, $page);
// Build the page
if ($page->settings['full']) {
// If page is set to full, avoid printing other theme block regions
print theme('page', $output, FALSE);
}
else {
// Simply return the page
return $output;
}
}