Browse Source

Merge pull request #306 from adam-vessey/7.x

Allow breadcrumb code to be called multiple times.
pull/305/merge
William Panting 12 years ago
parent
commit
2db98fb9d4
  1. 64
      includes/breadcrumb.inc
  2. 15
      islandora.api.php
  3. 5
      islandora.module

64
includes/breadcrumb.inc

@ -25,13 +25,8 @@
* drupal_set_breadcrumb(). * drupal_set_breadcrumb().
*/ */
function islandora_get_breadcrumbs($object) { function islandora_get_breadcrumbs($object) {
$breadcrumbs = array(); $breadcrumbs = islandora_get_breadcrumbs_recursive($object->id, $object->repository);
islandora_get_breadcrumbs_recursive($object->id, $breadcrumbs, $object->repository); array_pop($breadcrumbs);
if (isset($breadcrumbs[0])) {
// Remove the actual object.
unset($breadcrumbs[0]);
}
$breadcrumbs = array_reverse($breadcrumbs);
return $breadcrumbs; return $breadcrumbs;
} }
@ -40,30 +35,32 @@ function islandora_get_breadcrumbs($object) {
* *
* @todo Make fully recursive... * @todo Make fully recursive...
* *
* @todo Could use some clean up, can't be called multiple times safely due to
* the use of static variables.
*
* @param string $pid * @param string $pid
* THe object id whose parent will be fetched for the next link. * The object id whose parent will be fetched for the next link.
* @param array $breadcrumbs
* The list of existing bread-crumb links in reverse order.
* @param FedoraRepository $repository * @param FedoraRepository $repository
* The fedora repository. * The fedora repository.
* @param array $context
* An associative array of context for internal use when recursing. Currently
* only used to track a single value:
* - level: The number of child-parent relationships to follow. Defaults to
* 10.
*
* @return array
* An array of links representing the breadcrumb trail, "root" first.
*/ */
function islandora_get_breadcrumbs_recursive($pid, array &$breadcrumbs, FedoraRepository $repository) { function islandora_get_breadcrumbs_recursive($pid, FedoraRepository $repository, array &$context = NULL) {
// Before executing the query, we have a base case of accessing the top-level // Before executing the query, we have a base case of accessing the top-level
// collection. // collection.
static $max_level = 10; if ($context === NULL) {
static $level = -1; $context['level'] = 10;
if (count($breadcrumbs) === 0) {
$level = $max_level;
} }
$root = variable_get('islandora_repository_pid', 'islandora:root'); $root = variable_get('islandora_repository_pid', 'islandora:root');
if ($pid == $root) { if ($pid == $root) {
$breadcrumbs[] = l(menu_get_active_title(), 'islandora'); return array(
$breadcrumbs[] = l(t('Home'), '<front>'); l(t('Home'), '<front>'),
l(menu_get_active_title(), 'islandora'),
);
} }
else { else {
$query_string = 'select $parentObject $title $content from <#ri> $query_string = 'select $parentObject $title $content from <#ri>
@ -82,7 +79,7 @@ function islandora_get_breadcrumbs_recursive($pid, array &$breadcrumbs, FedoraRe
order by $title desc'; order by $title desc';
$results = $repository->ri->itqlQuery($query_string); $results = $repository->ri->itqlQuery($query_string);
if (count($results) > 0 && $level > 0) { if (count($results) > 0 && $context['level'] > 0) {
$parent = $results[0]['parentObject']['value']; $parent = $results[0]['parentObject']['value'];
$this_title = $results[0]['title']['value']; $this_title = $results[0]['title']['value'];
@ -90,16 +87,23 @@ function islandora_get_breadcrumbs_recursive($pid, array &$breadcrumbs, FedoraRe
$this_title = t('-'); $this_title = t('-');
} }
$breadcrumbs[] = l($this_title, "islandora/object/$pid"); $context['level']--;
return array_merge(
$level--; islandora_get_breadcrumbs_recursive($parent, $repository, $context),
islandora_get_breadcrumbs_recursive($parent, $breadcrumbs, $repository); array(
l($this_title, "islandora/object/$pid"),
)
);
} }
else { else {
// Add an non-link, as we don't know how to get back to the root. // Add an non-link, as we don't know how to get back to the root, and
$breadcrumbs[] = '...'; // render the last two links and break (on the next pass).
// And render the last two links and break (on the next pass). return array_merge(
islandora_get_breadcrumbs_recursive($root, $breadcrumbs, $repository); islandora_get_breadcrumbs_recursive($root, $repository, $context),
array(
'...',
)
);
} }
} }
} }

15
islandora.api.php

@ -45,11 +45,24 @@ function hook_CMODEL_PID_islandora_view_object($object) {
* @param FedoraObject $object * @param FedoraObject $object
* A Tuque FedoraObject being operated on. * A Tuque FedoraObject being operated on.
* @param array $rendered * @param array $rendered
* An arr of rendered views. * The array of rendered views.
*/ */
function hook_islandora_view_object_alter(&$object, &$rendered) { function hook_islandora_view_object_alter(&$object, &$rendered) {
} }
/**
* Alter display output if the object has the given model.
*
* @see hook_islandora_view_object_alter()
*
* @param FedoraObject $object
* A Tuque FedoraObject being operated on.
* @param array $rendered
* The array of rendered views.
*/
function hook_CMODEL_PID_islandora_view_object_alter(&$object, &$rendered) {
}
/** /**
* Generate an object's management display. * Generate an object's management display.
* *

5
islandora.module

@ -676,7 +676,8 @@ function islandora_view_object(FedoraObject $object) {
$page_number = (empty($_GET['page'])) ? '1' : $_GET['page']; $page_number = (empty($_GET['page'])) ? '1' : $_GET['page'];
$page_size = (empty($_GET['pagesize'])) ? '10' : $_GET['pagesize']; $page_size = (empty($_GET['pagesize'])) ? '10' : $_GET['pagesize'];
$output = array(); $output = array();
foreach (islandora_build_hook_list(ISLANDORA_VIEW_HOOK, $object->models) as $hook) { $hooks = islandora_build_hook_list(ISLANDORA_VIEW_HOOK, $object->models);
foreach ($hooks as $hook) {
// @todo Remove page number and size from this hook, implementers of the // @todo Remove page number and size from this hook, implementers of the
// hook should use drupal page handling directly. // hook should use drupal page handling directly.
$temp = module_invoke_all($hook, $object, $page_number, $page_size); $temp = module_invoke_all($hook, $object, $page_number, $page_size);
@ -689,7 +690,7 @@ function islandora_view_object(FedoraObject $object) {
$output = islandora_default_islandora_view_object($object); $output = islandora_default_islandora_view_object($object);
} }
arsort($output); arsort($output);
drupal_alter(ISLANDORA_VIEW_HOOK, $object, $output); drupal_alter($hooks, $object, $output);
return implode('', $output); return implode('', $output);
} }

Loading…
Cancel
Save