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,17 @@
; $Id: custom_breadcrumbs_views.info,v 1.1.2.1 2009/03/29 04:36:45 mgn Exp $
name = Custom Breadcrumbs for Views
package = Custom Breadcrumbs
dependencies[] = custom_breadcrumbs
dependencies[] = views
description = Provides Custom Breadcrumbs for views 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,123 @@
<?php
// $Id: custom_breadcrumbs_views.install,v 1.1.2.7 2010/05/03 22:49:15 mgn Exp $
/**
* @file
* Install file for the custom_breadcrumbs_views module.
*/
/**
* Implements hook_install().
*/
function custom_breadcrumbs_views_install() {
drupal_install_schema('custom_breadcrumbs_views');
// Search for Views breadcrumbs in existing {custom_breadcrumb} and move to new table.
drupal_set_message('Looking for views breadcrumbs to copy from {custom_breadcrumb}...');
$result = db_query("SELECT * FROM {custom_breadcrumb} WHERE node_type = '%s'", 'Views Page');
$found = 0;
while ($breadcrumb = db_fetch_object($result)) {
$start = strpos($breadcrumb->paths, "\n");
$views_path = drupal_substr($breadcrumb->paths, 0, $start);
$title = drupal_substr($breadcrumb->titles, strpos($breadcrumb->titles, "\n")+1);
$newpath = drupal_substr($breadcrumb->paths, strpos($breadcrumb->paths, "\n")+1);
db_query("INSERT INTO {custom_breadcrumbs_views} (titles, paths, visibility_php, views_path, set_active_menu, language) VALUES ('%s', '%s', '%s', '%s', %d, '%s' )", $title, $newpath, $breadcrumb->visibility_php, $views_path, $breadcrumb->set_active_menu, $breadcrumb->language);
drupal_set_message('copied path '. $views_path);
++$found;
}
if ( $found > 0) {
drupal_set_message(format_plural($found, 'Copied 1 breadcrumb.', 'Copied @count breadcrumbs.'));
drupal_set_message(t('You can now delete the old views breadcrumb from <a href="@link">admin/build/custom_breadcrumbs</a>. They will be listed with title Views Page and page type node.', array('@link' => url('admin/build/custom_breadcrumbs'))));
}
else {
drupal_set_message(t('No views breadcrumbs were found in {custom_breadcrumbs}'));
}
}
/**
* Implements hook_schema().
*/
function custom_breadcrumbs_views_schema() {
$schema['custom_breadcrumbs_views'] = array(
'description' => 'Stores custom breadcrumb trail overrides for views pages.',
'fields' => array(
'bid' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Unique identifier for the {custom_breadcrumbs_views}.',
),
'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_views} visibility.',
),
'views_path' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'description' => 'Path to the view 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'),
'vpath_language' => array('views_path', 'language'),
),
'primary key' => array('bid'),
);
return $schema;
}
/**
* Adds indices to custom_breadcrumb table to improve performance.
*/
function custom_breadcrumbs_views_update_6000() {
$ret = array();
db_add_index($ret, 'custom_breadcrumbs_views', 'language', array('language'));
db_add_index($ret, 'custom_breadcrumbs_views', 'vpath_language', array('views_path', 'language'));
return $ret;
}
/**
* Adds name field for improved organization of breadcrumbs
* Remove set_active_menu field because it is no longer used.
*/
function custom_breadcrumbs_views_update_6200() {
$ret = array();
db_add_field($ret, 'custom_breadcrumbs_views', 'name', array('type' => 'varchar', 'length' => 128, 'NOT NULL' => FALSE, 'description' => 'An optional name for the custom breadcrumb.'));
db_drop_field($ret, 'custom_breadcrumbs_views', 'set_active_menu');
return $ret;
}
/**
* Implements hook_uninstall().
*/
function custom_breadcrumbs_views_uninstall() {
drupal_uninstall_schema('custom_breadcrumbs_views');
}

View file

@ -0,0 +1,170 @@
<?php
// $Id: custom_breadcrumbs_views.module,v 1.1.2.21 2010/05/03 22:49:15 mgn Exp $
/**
* @file
* Provide custom breadcrumbs for views pages.
*/
module_load_include('inc', 'custom_breadcrumbs', 'custom_breadcrumbs.admin');
module_load_include('inc', 'custom_breadcrumbs', 'custom_breadcrumbs_common');
/**
* 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_views_cb_breadcrumb_info() {
$breadcrumb_type_info = array();
$breadcrumb_type_info['views'] = array(
'table' => 'custom_breadcrumbs_views',
'field' => 'views_path',
'type' => 'views',
'name_constructor' => '_custom_breadcrumbs_views_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_views_breadcrumb_name($breadcrumb) {
if (isset($breadcrumb->views_path)) {
return $breadcrumb->views_path;
}
}
/**
* Implements hook_menu().
*/
function custom_breadcrumbs_views_menu() {
$items = array();
$items['admin/build/custom_breadcrumbs/views/add'] = array(
'title' => 'Views',
'page callback' => 'drupal_get_form',
'page arguments' => array('custom_breadcrumbs_views_form', 'views'),
'access callback' => 'user_access',
'access arguments' => array('administer custom breadcrumbs'),
'type' => MENU_LOCAL_TASK,
'weight' => 5,
);
$items['admin/build/custom_breadcrumbs/views/edit'] = array(
'title' => 'Edit custom breadcrumb for views',
'page callback' => 'drupal_get_form',
'page arguments' => array('custom_breadcrumbs_views_form', 'views'),
'access callback' => 'user_access',
'access arguments' => array('administer custom breadcrumbs'),
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Implements hook_views_pre_render().
*/
function custom_breadcrumbs_views_views_pre_render(&$view) {
// Don't really do anything with the view. This is just a pretense to insert a breadcrumb.
global $language;
$languages = array('language' => $language->language, 'all' => '');
$curpath = drupal_get_normal_path($_GET['q']);
// Check to see if the view path matches the current path.
foreach ($view->display as $id => $display) {
// Identify allowed displays for breadcrumb replacement.
if (!_custom_breadcrumbs_allowed_display($display)) continue;
$viewpath = _custom_breadcrumbs_construct_view_path($display);
if (_custom_breadcrumbs_match_path($curpath, $viewpath)) {
$loadpath = $display->display_options['path'];
$breadcrumbs = custom_breadcrumbs_load_breadcrumbs('custom_breadcrumbs_views', NULL, array('views_path' => $loadpath), $languages);
if (!empty($breadcrumbs)) {
if ($breadcrumb = custom_breadcrumbs_select_breadcrumb($breadcrumbs, array('view' => $view))) {
// Select breadcrumb for the matching display with the greatest number of explicit arguments.
$num = substr_count($breadcrumb->views_path, '%');
if (!isset($max) || (isset($max) && ($num > $max))) {
$max = $num;
$candidate = $breadcrumb;
$max_id = $id;
}
}
}
}
}
if (isset($candidate)) {
$objs = _custom_breadcrumbs_views_token_types($view->display[$max_id]);
$objs['view'] = $view;
if (!isset($objs['node']) && isset($view->result[0]->nid)) {
$node = node_load(array('nid' => $view->result[0]->nid));
$objs['node'] = $node;
}
custom_breadcrumbs_set_breadcrumb($candidate, $objs);
return;
}
if (variable_get('custom_breadcrumbs_set_menu_breadcrumb', FALSE) && (!custom_breadcrumbs_exclude_path())) {
// If a views breadcrumb has not been defined for this view, then use the default menu structure.
custom_breadcrumbs_set_menu_breadcrumb();
}
}
/**
* Form builder; Displays an edit form for a views breadcrumb.
*
* @param $type
* The type of custom breadcrumb to edit.
*
* @ingroup forms
* @see custom_breadcrumbs_form_validate()
* @see custom_breadcrumbs_form_submit()
*/
function custom_breadcrumbs_views_form(&$form_state, $type) {
$form = array();
$breadcrumb = NULL;
$bid = arg(5);
if (isset($bid)) {
drupal_set_title(t('Edit Custom Breadcrumb for View'));
$breadcrumbs = custom_breadcrumbs_load_breadcrumbs('custom_breadcrumbs_views', NULL, array('bid' => $bid));
$breadcrumb = array_pop($breadcrumbs);
}
else {
drupal_set_title(t('Add Custom Breadcrumb for View'));
}
$options = array();
$views = views_get_all_views();
foreach ($views as $view) {
if (!isset($view->disabled) || (isset($view->disabled) && !$view->disabled)) {
foreach ($view->display as $display) {
if (_custom_breadcrumbs_allowed_display($display)) {
$name = $display->display_options['path'];
$options[$name] = $name;
}
}
}
}
$form['views_path'] = array(
'#type' => 'select',
'#title' => t('Views Path'),
'#required' => TRUE,
'#options' => $options,
'#description' => t('The path to the view that this custom breadcrumb trail will apply to.'),
'#default_value' => isset($breadcrumb->views_path) ? $breadcrumb->views_path : NULL,
'#weight' => -10,
);
// Store information needed to save this breadcrumb.
$form['#module'] = 'custom_breadcrumbs_views';
$form['#infokey'] = 'views';
$form += custom_breadcrumbs_common_form_elements($bid, $breadcrumb);
$form['visibility_php']['#description'] = t('Determine whether this breadcrumb should be displayed by using a PHP snippet to return TRUE or FALSE.');
$form['#submit'][] = 'custom_breadcrumbs_form_submit';
$form['#validate'][] = 'custom_breadcrumbs_form_validate';
return $form;
}