You are here

function farm_ui_entity_view in farmOS 7

Implements hook_entity_view().

File

modules/farm/farm_ui/farm_ui.module, line 193
Farm UI module code.

Code

function farm_ui_entity_view($entity, $type, $view_mode, $langcode) {

  // If the view mode is not 'full', bail.
  if ($view_mode != 'full') {
    return;
  }

  // We are only concerned with asset, plan, log, and term entities.
  $entity_types = array(
    'farm_asset',
    'farm_plan',
    'log',
    'taxonomy_term',
  );
  if (!in_array($type, $entity_types)) {
    return;
  }

  // Determine the bundle based on the type.
  switch ($type) {
    case 'farm_asset':
    case 'farm_plan':
    case 'log':
      $bundle = $entity->type;
      break;
    case 'taxonomy_term':
      $bundle = $entity->vocabulary_machine_name;
      break;
  }

  // Set the entity breadcrumb.
  module_load_include('inc', 'farm_ui', 'farm_ui.breadcrumb');
  farm_ui_entity_set_breadcrumb($type, $bundle);

  // Add Views to the entity.
  module_load_include('inc', 'farm_ui', 'farm_ui.entity_views');
  $views = farm_ui_entity_views($type, $bundle, $entity);
  if (!empty($views)) {
    $entity->content['views'] = $views;
    $entity->content['views']['#weight'] = 100;
  }
}