From 3ee80f75c7765dcd36fe0bcb7564bcaeccebba75 Mon Sep 17 00:00:00 2001 From: Michael Stenta Date: Mon, 13 Apr 2015 17:01:48 -0400 Subject: [PATCH] Add breadcrumbs to asset view pages, and provide a hook that allows other modules to add to the asset breadcrumb. --- farm_asset.api.php | 19 +++++++++++++++++++ farm_asset.pages.inc | 9 +++++++++ 2 files changed, 28 insertions(+) diff --git a/farm_asset.api.php b/farm_asset.api.php index f043de5eb..1ac1e8ba9 100644 --- a/farm_asset.api.php +++ b/farm_asset.api.php @@ -21,6 +21,25 @@ * Hooks that can be implemented by other modules in order to extend farm_asset. */ +/** + * Add breadcrumbs to the asset view page. + * + * @param FarmAsset $farm_asset + * The farm asset entity. + * + * @return array + * Returns an array of links to add to the asset breadcrumb. + */ +function hook_farm_asset_breadcrumb(FarmAsset $farm_asset) { + + // If the asset is an animal, add a link to the animals list. + $breadcrumb = array(); + if ($farm_asset->type == 'animal') { + $breadcrumb[] = l(t('Animals'), 'farm/animals'); + } + return $breadcrumb; +} + /** * Attach Views to asset view pages. * diff --git a/farm_asset.pages.inc b/farm_asset.pages.inc index f2462f42c..0071fa759 100644 --- a/farm_asset.pages.inc +++ b/farm_asset.pages.inc @@ -19,6 +19,15 @@ function farm_asset_view(FarmAsset $farm_asset) { // Set the page title. drupal_set_title(entity_label('farm_asset', $farm_asset)); + // Set the page breadcrumb. + $breadcrumb = array( + l(t('Home'), ''), + l(t('Farm'), 'farm'), + ); + $module_breadcrumbs = module_invoke_all('farm_asset_breadcrumb', $farm_asset); + $breadcrumb = array_merge($breadcrumb, $module_breadcrumbs); + drupal_set_breadcrumb($breadcrumb); + // Build the asset's render array. $build = entity_view('farm_asset', array(entity_id('farm_asset', $farm_asset) => $farm_asset), 'full');