Browse Source

Make breadcrumb creation a hookable process.

pull/651/head
Jared Whiklo 10 years ago
parent
commit
dcee212379
  1. 15
      includes/breadcrumb.inc
  2. 40
      islandora.api.php
  3. 16
      islandora.module

15
includes/breadcrumb.inc

@ -25,9 +25,20 @@
* drupal_set_breadcrumb(). * drupal_set_breadcrumb().
*/ */
function islandora_get_breadcrumbs($object) { function islandora_get_breadcrumbs($object) {
$breadcrumbs = array();
if (variable_get('islandora_render_drupal_breadcrumbs', TRUE)) { if (variable_get('islandora_render_drupal_breadcrumbs', TRUE)) {
$breadcrumbs = islandora_get_breadcrumbs_recursive($object->id, $object->repository); $backend = variable_get('islandora_breadcrumbs_backends', ISLANDORA_BREADCRUMB_LEGACY_BACKEND);
$backends = module_invoke_all('islandora_breadcrumbs_backends');
if ($backend === ISLANDORA_BREADCRUMB_LEGACY_BACKEND || !isset($backends[$backend])) {
$breadcrumbs = islandora_get_breadcrumbs_recursive($object->id, $object->repository);
}
else {
if (isset($backends[$backend]['file'])) {
require_once $backends[$backend]['file'];
}
$breadcrumbs = call_user_func($backends[$backend]['callable'], $object);
}
array_pop($breadcrumbs); array_pop($breadcrumbs);
$context = 'islandora'; $context = 'islandora';
drupal_alter('islandora_breadcrumbs', $breadcrumbs, $context, $object); drupal_alter('islandora_breadcrumbs', $breadcrumbs, $context, $object);

40
islandora.api.php

@ -907,3 +907,43 @@ function hook_islandora_edit_datastream_registry_alter(&$edit_registry, $context
function hook_islandora_repository_connection_construction_alter(RepositoryConnection $instance) { function hook_islandora_repository_connection_construction_alter(RepositoryConnection $instance) {
$instance->userAgent = "Tuque/cURL"; $instance->userAgent = "Tuque/cURL";
} }
/**
* Allow a overridable backend for generating breadcrumbs.
*
* Stolen shamelessly from @adam-vessey
*
* @return array
* Should return an associative array mapping unique (module-prefixed,
* preferably) keys to associative arrays containing:
* - title: A human-readable title for the backend.
* - callable: A PHP callable to call for this backend, implementing
* callback_islandora_basic_collection_query_backends().
* - file: An optional file to load before attempting to call the callable.
*/
function hook_islandora_breadcrumbs_backends() {
$a_callable = function ($object) {
// Do something to get an array of breadcrumb links for $object, root first.
return array($root_link, $collection_link, $object_link);
};
return array(
'awesome_backend' => array(
'title' => t('Awesome Backend'),
'callable' => $a_callable,
),
);
}
/**
* Generate an array of links for breadcrumbs leading to $object, root level first.
*
* @param AbstractObject $object
* The object to generate breadcrumbs for
*
* @return array
* Array of links from root to $object.
*/
function callback_islandora_breadcrumbs_backends(AbstractObject $object) {
// Do something to get an array of breadcrumb links for $object, root first.
return array($root_link, $collection_link, $object_link);
}

16
islandora.module

@ -68,6 +68,8 @@ define('ISLANDORA_DERIVATIVE_CREATION_HOOK', 'islandora_derivative');
define('ISLANDORA_CONTENT_MODELS_AUTOCOMPLETE', 'islandora/autocomplete/content-models'); define('ISLANDORA_CONTENT_MODELS_AUTOCOMPLETE', 'islandora/autocomplete/content-models');
define('ISLANDORA_MIME_TYPES_AUTOCOMPLETE', 'islandora/autocomplete/mime-types'); define('ISLANDORA_MIME_TYPES_AUTOCOMPLETE', 'islandora/autocomplete/mime-types');
const ISLANDORA_BREADCRUMB_LEGACY_BACKEND = 'islandora_breadcrumbs_legacy_sparql';
/** /**
* Implements hook_menu(). * Implements hook_menu().
* *
@ -2171,3 +2173,17 @@ function islandora_create_manage_overview(AbstractObject $object) {
$output = theme('islandora_object_overview', array('islandora_object' => $object)); $output = theme('islandora_object_overview', array('islandora_object' => $object));
return array('cmodels' => $output); return array('cmodels' => $output);
} }
/**
* Implements hook_islandora_breadcrumbs_backends().
*/
function islandora_islandora_breadcrumbs_backends() {
$module_path = drupal_get_path('module', 'islandora');
return array(
ISLANDORA_BREADCRUMB_LEGACY_BACKEND => array(
'title' => t('Resource Index - Default'),
// Callback not needed as this is our legacy process and the
// default incase anything goes wrong.
),
);
}

Loading…
Cancel
Save