View source
<?php
module_load_include('inc', 'custom_breadcrumbs', 'custom_breadcrumbs.admin');
module_load_include('inc', 'custom_breadcrumbs', 'custom_breadcrumbs_common');
module_load_include('inc', 'page_manager', 'page_manager.admin');
function custom_breadcrumbs_panels_cb_breadcrumb_info() {
$breadcrumb_type_info = array();
$breadcrumb_type_info['panels'] = array(
'table' => 'custom_breadcrumbs_panels',
'field' => 'panel_id',
'type' => 'panels',
'name_constructor' => '_custom_breadcrumbs_panels_breadcrumb_name',
);
return $breadcrumb_type_info;
}
function _custom_breadcrumbs_panels_breadcrumb_name($breadcrumb) {
if (isset($breadcrumb->panel_id)) {
return $breadcrumb->panel_id;
}
}
function custom_breadcrumbs_panels_menu() {
$items = array();
$items['admin/structure/custom_breadcrumbs/panels/add'] = array(
'title' => 'Panels',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'custom_breadcrumbs_panels_form',
'panels',
),
'access callback' => 'user_access',
'access arguments' => array(
'administer custom breadcrumbs',
),
'type' => MENU_LOCAL_TASK,
'weight' => 5,
);
$items['admin/structure/custom_breadcrumbs/panels/edit'] = array(
'title' => 'Edit custom breadcrumb for panels',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'custom_breadcrumbs_panels_form',
'panels',
),
'access callback' => 'user_access',
'access arguments' => array(
'administer custom breadcrumbs',
),
'type' => MENU_CALLBACK,
);
return $items;
}
function custom_breadcrumbs_panels_node_view($node, $build_mode) {
static $module_weights = array();
if ($build_mode == 'full' && $node->type == 'panel') {
$display = panels_load_display($node->panels_node['did']);
$contents = $display->content;
foreach ((array) $contents as $content) {
if (isset($content->configuration['nid'])) {
$node_context = node_load($content->configuration['nid']);
if (empty($module_weights)) {
$modules = module_implements('cb_breadcrumb_info');
$module_weights = _custom_breadcrumbs_get_module_weight($modules);
unset($module_weights['custom_breadcrumbs_panels']);
}
foreach ($module_weights as $module_name => $weight) {
$func = $module_name . '_node_view';
if (function_exists($func)) {
$func($node_context, 'full');
}
}
}
}
}
}
function custom_breadcrumbs_panels_ctools_render_alter($info, $page, $data) {
static $module_weights = array();
extract($data);
if ($page) {
global $language;
$languages = array(
'language' => $language->language,
'all' => '',
);
$id = $handler->name;
$breadcrumbs = custom_breadcrumbs_load_breadcrumbs('custom_breadcrumbs_panels', NULL, array(
'panel_id' => $id,
), $languages);
if (empty($breadcrumbs)) {
$id = $handler->task;
$breadcrumbs = custom_breadcrumbs_load_breadcrumbs('custom_breadcrumbs_panels', NULL, array(
'panel_id' => $id,
), $languages);
}
if (!empty($breadcrumbs)) {
if ($breadcrumb = custom_breadcrumbs_select_breadcrumb($breadcrumbs, array(
'panel' => $info,
))) {
$objs = array(
'panel' => $info,
);
foreach ($contexts as $context) {
if (is_array($context->type) && (in_array('node', $context->type) || in_array('entity:node', $context->type)) && isset($context->data)) {
$objs['node'] = $context->data;
}
}
if (!empty($handler->conf['display'])) {
foreach ($handler->conf['display']->content as $pane) {
if ($pane->type == 'node') {
$objs['node'] = node_load($pane->configuration['nid']);
}
}
}
custom_breadcrumbs_set_breadcrumb($breadcrumb, $objs);
return;
}
}
}
if (isset($task['admin path']) && $task['admin path'] == "taxonomy/term/%taxonomy_term" && module_exists('custom_breadcrumbs_taxonomy') && variable_get('custom_breadcrumbs_taxonomy_panels', FALSE)) {
module_load_include('inc', 'custom_breadcrumbs_taxonomy');
foreach ($contexts as $context) {
if (isset($context->data->tid)) {
$terms = array(
$context->data->tid => $context->data,
);
_custom_breadcrumbs_taxonomy_set_breadcrumb($context->data->tid, $context->data->vid, TRUE, array(), $terms);
return;
}
}
}
if (isset($task['admin path']) && $task['admin path'] == "node/%node") {
$context = array_pop($contexts);
if (is_array($context->type) && (in_array('node', $context->type) || in_array('entity:node', $context->type)) && isset($context->data)) {
$node = $context->data;
if (empty($module_weights)) {
$modules = module_implements('cb_breadcrumb_info');
$module_weights = _custom_breadcrumbs_get_module_weight($modules);
unset($module_weights['custom_breadcrumbs_panels']);
}
foreach ($module_weights as $module_name => $weight) {
$func = $module_name . '_node_view';
if (function_exists($func)) {
$func($node, 'full');
}
}
return;
}
}
if (variable_get('custom_breadcrumbs_set_menu_breadcrumb', FALSE)) {
custom_breadcrumbs_set_menu_breadcrumb();
}
}
function custom_breadcrumbs_panels_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'custom_breadcrumbs_admin_settings') {
if (module_exists('custom_breadcrumbs_taxonomy')) {
$form['settings']['custom_breadcrumbs_panels'] = array(
'#type' => 'fieldset',
'#title' => t('Panels'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['settings']['custom_breadcrumbs_panels']['custom_breadcrumbs_taxonomy_panels'] = array(
'#type' => 'checkbox',
'#title' => t('Use taxonomy breadcrumbs for panels'),
'#default_value' => variable_get('custom_breadcrumbs_taxonomy_panels', FALSE),
'#description' => t('If enabled, the view argument and/or the taxonomy structure of nodes returned by panels will be used to form the taxonomy breadcrumb trail.'),
'#weight' => 45,
);
}
}
}
function custom_breadcrumbs_panels_form($form, &$form_state, $type) {
$form = array();
$breadcrumb = NULL;
$bid = arg(5);
if (isset($bid)) {
drupal_set_title(t('Edit Custom Breadcrumb for Panel Page'));
$breadcrumbs = custom_breadcrumbs_load_breadcrumbs('custom_breadcrumbs_panels', NULL, array(
'bid' => $bid,
));
$breadcrumb = array_pop($breadcrumbs);
}
else {
drupal_set_title(t('Add Custom Breadcrumb for Panel Page'));
}
$options = array();
$tasks = page_manager_get_tasks_by_type('page');
$pages = array(
'operations' => array(),
);
page_manager_get_pages($tasks, $pages);
foreach ($pages['rows'] as $id => $info) {
$task = page_manager_get_page_cache($id);
$title = decode_entities($task->subtask['admin title']);
if (count($task->handlers) > 1) {
$options[$title] = array(
$id => t('!title (All variants)', array(
'!title' => $title,
)),
);
foreach ($task->handlers as $handler) {
$options[$title][$handler->name] = decode_entities($handler->conf['title']);
}
}
else {
$handler = reset($task->handlers);
if (isset($handler->name)) {
$options[$handler->name] = $title;
}
}
}
$form['panel_id'] = array(
'#type' => 'select',
'#title' => t('Custom Panel Page'),
'#required' => TRUE,
'#options' => $options,
'#description' => t("The Panel variant (or page) that this custom breadcrumb trail will apply to. If you want to apply the custom breadcrumb trail to all variants of a Panel page, choose the 'All variants' option for that page."),
'#default_value' => isset($breadcrumb->panel_id) ? $breadcrumb->panel_id : NULL,
'#weight' => -10,
);
$form['#module'] = 'custom_breadcrumbs_panels';
$form['#infokey'] = 'panels';
$form += custom_breadcrumbs_common_form_elements($bid, $breadcrumb);
$form['visibility_php']['#description'] = t('Determine whether this breadcrumb should be displayed by using a snippet of PHP to return TRUE or FALSE. Do not use opening and closing php tags.');
$form['#submit'][] = 'custom_breadcrumbs_form_submit';
$form['#validate'][] = 'custom_breadcrumbs_form_validate';
return $form;
}