Add breadcrumbs to asset view pages, and provide a hook that allows other modules to add to the asset breadcrumb.
This commit is contained in:
parent
c0749526d7
commit
3ee80f75c7
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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'), '<front>'),
|
||||
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');
|
||||
|
||||
|
|
Loading…
Reference in New Issue