function panels_breadcrumbs_ctools_render_alter in Panels Breadcrumbs 7
Same name and namespace in other branches
- 7.2 panels_breadcrumbs.module \panels_breadcrumbs_ctools_render_alter()
Implements hook_ctools_render_alter().
When a Page Manager page is rendered, set the breadcrumb
File
- ./
panels_breadcrumbs.module, line 117 - Main file for panels breadcrumbs module.
Code
function panels_breadcrumbs_ctools_render_alter($info, $page, $context) {
$conf = $context['handler']->conf;
// If panels_breadcrumbs isn't enabled for this display, bail out.
if (!isset($conf['panels_breadcrumbs_state']) || !$conf['panels_breadcrumbs_state']) {
return;
}
// If no titles or paths are defined, also bail out.
if (!isset($conf['panels_breadcrumbs_titles']) || !isset($conf['panels_breadcrumbs_paths'])) {
return;
}
$display_context = $context['handler']->conf['display']->context;
// Look for placeholder tokens in titles and paths and convert them for this display
$titles = ctools_context_keyword_substitute($conf['panels_breadcrumbs_titles'], array(), $display_context);
$paths = ctools_context_keyword_substitute($conf['panels_breadcrumbs_paths'], array(), $display_context);
// Break titles and paths into arrays and remove empty keys
$titles = array_filter(array_map('trim', explode(PHP_EOL, $titles)), 'strlen');
$paths = array_filter(array_map('trim', explode(PHP_EOL, $paths)), 'strlen');
$default_breadcrumb_info = array(
'title' => '',
'href' => '',
'localized_options' => array(),
);
$breadcrumbs_info = array();
// Set the first crumb to home
if (!isset($conf['panels_breadcrumbs_home']) || $conf['panels_breadcrumbs_home'] == TRUE) {
$breadcrumbs_info[] = array(
'title' => t('Home'),
'href' => '<front>',
) + $default_breadcrumb_info;
}
// Iterate through all crumbs and add them to the breadcrumb
foreach ($titles as $key => $title) {
$title = html_entity_decode(trim($title), ENT_QUOTES);
$path = empty($paths[$key]) ? '<none>' : trim($paths[$key]);
$breadcrumbs_info[] = array(
'title' => t($title),
'href' => $path,
) + $default_breadcrumb_info;
}
// Allow other modules to intercept and operate changes in the breadcrumb
$breadcrumb_info_end = end($breadcrumbs_info);
drupal_alter('menu_breadcrumb', $breadcrumbs_info, $breadcrumb_info_end);
// Finally, render the breadcrumb
$breadcrumbs = array();
foreach ($breadcrumbs_info as $crumb) {
if (isset($crumb['href']) && $crumb['href'] == '<none>') {
$crumb['localized_options'] += array(
'attributes' => array(),
'html' => TRUE,
);
$breadcrumbs[] = '<span ' . drupal_attributes($crumb['localized_options']['attributes']) . '>' . ($crumb['localized_options']['html'] ? $crumb['title'] : check_plain($crumb['title'])) . '</span>';
}
else {
$breadcrumbs[] = l($crumb['title'], $crumb['href'], $crumb['localized_options']);
}
}
drupal_set_breadcrumb($breadcrumbs);
}