function om_maximenu_blocks_get in OM Maximenu 6
Same name and namespace in other branches
- 8 inc/om_maximenu.blocks.inc \om_maximenu_blocks_get()
- 7 inc/om_maximenu.blocks.inc \om_maximenu_blocks_get()
Adding Blocks
List of all available blocks in the system
1 string reference to 'om_maximenu_blocks_get'
- om_maximenu_menu in ./
om_maximenu.module - Implementation of hook_menu().
File
- inc/
om_maximenu.blocks.inc, line 18 - OM Maximenu Blocks.
Code
function om_maximenu_blocks_get() {
global $_om_maximenu_variable;
drupal_set_title(t('OM Maximenu Blocks'));
// get the variable to merge with enabled blocks
$maximenu = $_om_maximenu_variable;
// based on url variables
$args = arg();
$menu_title = isset($maximenu[$args[4]]['title']) ? $maximenu[$args[4]]['title'] : '';
$link_title = isset($maximenu[$args[4]]['links'][$args[5]]['link_title']) ? $maximenu[$args[4]]['links'][$args[5]]['link_title'] : 'New Link';
$link_title_path = isset($maximenu[$args[4]]['links'][$args[5]]['link_title_path']) ? $maximenu[$args[4]]['links'][$args[5]]['link_title_path'] : '';
$blocks_enabled = isset($maximenu[$args[4]]['links'][$args[5]]['content']) ? $maximenu[$args[4]]['links'][$args[5]]['content'] : array();
//dsm($blocks_enabled);
// make sure there's theme name
$theme_default = variable_get('theme_default', 'garland');
// get all available blocks for the current theme
$blocks = _block_rehash($theme_default);
foreach ($blocks as $key => $block) {
$block = (object) $block;
// filter out om_maximenu module
if ($block->module != 'om_maximenu') {
$title = $block->title;
// custom title
$info = $block->info;
// default title
$module = $block->module;
// block's source
$delta = $block->delta;
// block's identifier
// checked state is based on blocks existence in the array
$modules[$module][$delta]['checked'] = isset($blocks_enabled[$module . '___' . $delta]) ? 1 : 0;
// om block title has the highest priority
if (isset($blocks_enabled[$module . '___' . $delta]) && !empty($blocks_enabled[$module . '___' . $delta]['title'])) {
// if custom title is present
$modules[$module][$delta]['title'] = $blocks_enabled[$module . '___' . $delta]['title'];
}
else {
// will get custom title, and default block title
$modules[$module][$delta]['title'] = !empty($title) ? $title : $info;
}
$modules[$module][$delta]['title_path'] = isset($blocks_enabled[$module . '___' . $delta]) && !empty($blocks_enabled[$module . '___' . $delta]['title_path']) ? $blocks_enabled[$module . '___' . $delta]['title_path'] : '';
$modules[$module][$delta]['title_path_query'] = isset($blocks_enabled[$module . '___' . $delta]) && !empty($blocks_enabled[$module . '___' . $delta]['title_path_query']) ? $blocks_enabled[$module . '___' . $delta]['title_path_query'] : '';
$modules[$module][$delta]['title_path_fragment'] = isset($blocks_enabled[$module . '___' . $delta]) && !empty($blocks_enabled[$module . '___' . $delta]['title_path_fragment']) ? $blocks_enabled[$module . '___' . $delta]['title_path_fragment'] : '';
$modules[$module][$delta]['weight'] = isset($blocks_enabled[$module . '___' . $delta]) && !empty($blocks_enabled[$module . '___' . $delta]['weight']) ? $blocks_enabled[$module . '___' . $delta]['weight'] : 0;
$modules[$module][$delta]['visibility'] = isset($blocks_enabled[$module . '___' . $delta]) && !empty($blocks_enabled[$module . '___' . $delta]['visibility']) ? $blocks_enabled[$module . '___' . $delta]['visibility'] : 0;
}
}
//dsm($modules);
if (module_exists('om_tools')) {
$block_class_edit = l(t('<strong>Block Classes</strong> | '), 'admin/settings/om-tools', array(
'attributes' => array(
'title' => t('Edit / Add custom block classes.'),
),
'query' => array(
'destination' => 'admin/settings/om-maximenu/blocks/' . $args[4] . '/' . $args[5],
),
//'fragment' => '',
'html' => TRUE,
));
}
else {
$block_class_edit = t('Block Classes (OM Tools must be intalled)');
}
$form = array();
$form['om_maximenu_content'] = array(
'#type' => 'fieldset',
'#title' => t(om_string_name($menu_title, FALSE) . ' / ' . om_string_name($link_title, FALSE)),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#tree' => TRUE,
'#description' => t('These are all the available blocks in your system. Choose the blocks which will appear under the navigation menu link.<br />') . $block_class_edit . '<strong>' . l(t('Back to OM Settings'), 'admin/settings/om-maximenu') . '</strong>',
);
//dsm($modules);
foreach ($modules as $module => $blocks) {
// count all blocks in a module
$total = count($modules[$module]);
// count how many are enabled
$count = 0;
foreach ($blocks as $key => $checked) {
if ($checked['checked']) {
$count++;
}
}
$form['om_maximenu_content'][$module] = array(
'#type' => 'fieldset',
'#title' => t(om_string_name($module, FALSE) . ' (' . $count . ' of ' . $total . ')'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#theme' => 'om_maximenu_blocks_attach',
);
$form['om_maximenu_content'][$module] += om_maximenu_blocks_attach($module, $blocks);
}
$form['save'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}