New module 'Custom breadcrumbs'

This commit is contained in:
Manuel Cillero 2017-07-26 10:57:18 +02:00
parent 89b4aad0f8
commit 3813ae0e06
26 changed files with 6004 additions and 0 deletions

View file

@ -0,0 +1,19 @@
; $Id: custom_breadcrumbs_panels.info,v 1.1.2.1 2009/08/02 23:18:48 mgn Exp $
name = Custom Breadcrumbs for Panels
package = Custom Breadcrumbs
dependencies[] = custom_breadcrumbs
dependencies[] = panels
dependencies[] = ctools
dependencies[] = page_manager
description = Provides Custom Breadcrumbs for panels pages.
core = 6.x
; Information added by drupal.org packaging script on 2011-01-08
version = "6.x-2.0-rc1"
core = "6.x"
project = "custom_breadcrumbs"
datestamp = "1294462254"

View file

@ -0,0 +1,94 @@
<?php
// $Id: custom_breadcrumbs_panels.install,v 1.1.2.3 2010/05/03 22:49:15 mgn Exp $
/**
* @file
* Install file for the custom_breadcrumbs_panels module.
*/
/**
* Implements hook_install().
*/
function custom_breadcrumbs_panels_install() {
drupal_install_schema('custom_breadcrumbs_panels');
}
/**
* Implements of hook_schema().
*/
function custom_breadcrumbs_panels_schema() {
$schema['custom_breadcrumbs_panels'] = array(
'description' => 'Stores custom breadcrumb trail overrides for panels pages.',
'fields' => array(
'bid' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Unique identifier for the {custom_breadcrumbs_panels}.',
),
'name' => array(
'type' => 'varchar',
'length' => 128,
'not null' => FALSE,
'description' => 'An optional name for the custom breadcrumb.',
),
'titles' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
'description' => 'A return-delimited list of titles for the breadcrumb links.',
),
'paths' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'A return-delimited list of url paths for the breadcrumb links.',
),
'visibility_php' => array(
'type' => 'text',
'not null' => TRUE,
'size' => 'medium',
'description' => 'An optional PHP snippet to control the {custom_breadcrumbs_panels} visibility.',
),
'panel_id' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'description' => 'The Id of the panel for this custom breadcrumb.',
),
'language' => array(
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
'description' => 'The language this breadcrumb is for; if blank, the breadcrumb will be used for unknown languages.',
),
),
'indexes' => array(
'language' => array('language'),
'panelid_language' => array('panel_id', 'language'),
),
'primary key' => array('bid'),
);
return $schema;
}
/**
* Adds name field for improved organization of breadcrumbs
* Remove set_active_menu field because it is no longer used.
*/
function custom_breadcrumbs_panels_update_6200() {
$ret = array();
db_add_field($ret, 'custom_breadcrumbs_panels', 'name', array('type' => 'varchar', 'length' => 128, 'NOT NULL' => FALSE, 'description' => 'An optional name for the custom breadcrumb.'));
return $ret;
}
/**
* Implements hook_uninstall().
*/
function custom_breadcrumbs_panels_uninstall() {
drupal_uninstall_schema('custom_breadcrumbs_panels');
// Remove persistent variables.
variable_del('custom_breadcrumbs_taxonomy_panels');
}

View file

@ -0,0 +1,228 @@
<?php
// $Id: custom_breadcrumbs_panels.module,v 1.1.2.9 2010/12/30 18:36:25 mgn Exp $
/**
* @file
* Provide custom breadcrumbs for panels pages.
*/
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');
/**
* Implements hook_cb_breadcrumb_info().
*
* @return an array with elements:
* 'table' indicating the db_table to load the breadcrumb from,
* 'field' a unique field of the database table used to identify the breadcrumb,
* 'type' a string used for indicating the breadcrumb type on the admin list,
* 'name_constructor' a function which generates the breadcrumb name from the breadcrumb.
*/
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;
}
/**
* Constructs a default name to display in the admin screen.
*
* @param $breadcrumb
* The breadcrumb object.
*
* @return
* A text string that will be used as the breadcrumb name.
*/
function _custom_breadcrumbs_panels_breadcrumb_name($breadcrumb) {
if (isset($breadcrumb->panel_id)) {
return $breadcrumb->panel_id;
}
}
/**
* Implements hook_menu().
*/
function custom_breadcrumbs_panels_menu() {
$items = array();
$items['admin/build/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/build/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;
}
/**
* Implements hook_nodeapi().
*/
function custom_breadcrumbs_panels_nodeapi($node, $op, $teaser, $page) {
static $module_weights = array();
if ($op == 'alter' && empty($teaser) && !empty($page) && $node->type == 'panel') {
// Loop through content objects and call hook_nodeapi for custom_breadcrumbs
// and its submodules for each node object.
$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 . '_nodeapi';
if (function_exists($func)) {
$func($node_context, 'alter', array(), array(1));
}
}
}
}
}
}
/**
* Implements hook_ctools_render_alter().
*/
function custom_breadcrumbs_panels_ctools_render_alter($info, $page, $args, $contexts, $task, $subtask) {
// Don't really do anything with the panel. This is just a pretense to insert a breadcrumb.
static $module_weights = array();
// Is this a node template?
if (isset($task['admin path']) && ($task['admin path'] == "node/%node")) {
$context = array_pop($contexts);
if ($context->type == 'node' && isset ($context->data)) {
$node = $context->data;
// Call hook_nodeapi for each Custom Breadcrumbs submodule in order of the module's weight.
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 . '_nodeapi';
if (function_exists($func)) {
$func($node, 'alter', array(), array(1));
}
}
return;
}
}
// Is this a taxonomy term template?
if (isset($task['admin path']) && ($task['admin path'] == "taxonomy/term/%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 ($page) {
global $language;
$languages = array('language' => $language->language, 'all' => '');
// Check to see if the panel ID matches any custom_breadcrumb panel_id.
$id = isset($subtask['name']) ? 'page-' . $subtask['name'] : $task['name'];
$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))) {
custom_breadcrumbs_set_breadcrumb($breadcrumb, array('panel' => $info));
return;
}
}
if (variable_get('custom_breadcrumbs_set_menu_breadcrumb', FALSE)) {
// If a panels breadcrumb has not been defined for this panel, then use the default menu structure.
custom_breadcrumbs_set_menu_breadcrumb();
}
}
}
/**
* Implements hook_form_alter().
*/
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,
);
}
}
}
/**
* Form builder; Displays an edit form for a panels breadcrumb.
*
* @ingroup forms
* @see custom_breadcrumbs_form_validate()
* @see custom_breadcrumbs_form_submit()
*/
function custom_breadcrumbs_panels_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) {
$options[$id] = $id;
}
$form['panel_id'] = array(
'#type' => 'select',
'#title' => t('Custom Panel Page Id'),
'#required' => TRUE,
'#options' => $options,
'#description' => t('The Panel that this custom breadcrumb trail will apply to.'),
'#default_value' => isset($breadcrumb->panel_id) ? $breadcrumb->panel_id : NULL,
'#weight' => -10,
);
// Store information needed to save this breadcrumb.
$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.');
$form['#submit'][] = 'custom_breadcrumbs_form_submit';
$form['#validate'][] = 'custom_breadcrumbs_form_validate';
return $form;
}