You are here

function farm_ui_entity_type_breadcrumb in farmOS 7

Build breadcrumbs for a specific entity type and bundle.

Parameters

$type: The entity type.

$bundle: The bundle.

Return value

array Returns a breadcrumb array.

1 call to farm_ui_entity_type_breadcrumb()
farm_ui_entity_set_breadcrumb in modules/farm/farm_ui/farm_ui.breadcrumb.inc
Set the breadcrumb for an entity view page. This should be called in hook_entity_view().

File

modules/farm/farm_ui/farm_ui.breadcrumb.inc, line 68

Code

function farm_ui_entity_type_breadcrumb($type, $bundle) {

  // Start an empty breadcrumb array.
  $breadcrumb = array();

  // Load entity UI information.
  $ui_info = farm_ui_entities($type, $bundle);

  // Get the label (plural). Bail if it's not set.
  if (empty($ui_info['label_plural'])) {
    return $breadcrumb;
  }
  $label = $ui_info['label_plural'];

  // If the entity type has a View, load the path.
  if (!empty($ui_info['view'])) {
    $path = farm_ui_view_page_path($ui_info['view']);
  }

  // If this is a farm_asset entity, add a link to the full assets list.
  if ($type == 'farm_asset') {
    $breadcrumb[] = l(t('Assets'), 'farm/assets');
  }
  elseif ($type == 'farm_plan') {
    $breadcrumb[] = l(t('Plans'), 'farm/plans');
  }
  elseif ($type == 'log') {
    $breadcrumb[] = l(t('Logs'), 'farm/logs');
  }

  // If this is a taxonomy_term entity, and it is linked to a specific asset
  // type, add the asset breadcrumb trail (recurse into this function again).
  if ($type == 'taxonomy_term' && !empty($ui_info['farm_asset'])) {
    $asset_breadcrumbs = farm_ui_entity_type_breadcrumb('farm_asset', $ui_info['farm_asset']);
    $breadcrumb = array_merge($asset_breadcrumbs, $breadcrumb);
  }

  // If a path was found, add a link to the breadcrumb. Otherwise, add a simple
  // text breadcrumb.
  if (!empty($path)) {
    $breadcrumb[] = l($label, $path);
  }
  else {
    $breadcrumb[] = $label;
  }

  // If this is a taxonomy_term entity, get the default breadcrumb and tack it
  // onto the end, so we can take advantage of the structure already provided
  // by the taxonomy hierarchy. Shift the first item off (home) because we've
  // started a new breadcrumb from scratch.
  if ($type == 'taxonomy_term') {
    $default_breadcrumb = drupal_get_breadcrumb();
    array_shift($default_breadcrumb);
    $breadcrumb = array_merge($breadcrumb, $default_breadcrumb);
  }

  // Return the breadcrumb.
  return $breadcrumb;
}