You are here

function farm_plan_entity_view in farmOS 7

Implements hook_entity_view().

File

modules/farm/farm_plan/farm_plan.module, line 324
Farm plan - A farm plan entity type.

Code

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

  // If the entity is not a farm_plan, bail.
  if ($type != 'farm_plan') {
    return;
  }

  // Add the plan type.
  $plan_types = farm_plan_type_get_names();
  if (!empty($plan_types[$entity->type])) {
    $entity->content['type'] = array(
      '#markup' => '<div><strong>Plan type:</strong> ' . $plan_types[$entity->type] . '</div>',
      '#weight' => -101,
    );
  }

  // Add the plan's "active" status.
  if ($entity->active) {
    $status = 'Yes';
  }
  else {
    $status = 'No';
    drupal_set_message(t('This plan is no longer active. Inactive plans should be considered "archived" and should not be edited or deleted unless they contain information that is incorrect.'), 'warning');
  }
  $entity->content['active'] = array(
    '#markup' => '<div><strong>Active plan:</strong> ' . $status . '</div>',
    '#weight' => -100,
  );

  // Summarize areas and assets associated with the plan (logs will be added via
  // Views in hook_farm_ui_entity_views() below.
  $plan_areas = farm_plan_linked_records('area', $entity->id);
  if (!empty($plan_areas)) {
    $plan_area_links = array();
    foreach ($plan_areas as $area_id) {
      $area = taxonomy_term_load($area_id);
      $entity_label = entity_label('taxonomy_term', $area);
      $entity_uri = entity_uri('taxonomy_term', $area);
      $plan_area_links[] = l($entity_label, $entity_uri['path']);
    }
    $entity->content['farm_plan_areas'] = array(
      '#markup' => '<div><strong>Areas:</strong> ' . implode(', ', $plan_area_links) . '</div>',
    );
  }
  $plan_assets = farm_plan_linked_records('asset', $entity->id);
  if (!empty($plan_assets)) {
    $plan_asset_links = array();
    foreach ($plan_assets as $asset_id) {
      $asset = farm_asset_load($asset_id);
      $entity_label = entity_label('farm_asset', $asset);
      $entity_uri = entity_uri('farm_asset', $asset);
      $plan_asset_links[] = l($entity_label, $entity_uri['path']);
    }
    $entity->content['farm_plan_assets'] = array(
      '#markup' => '<div><strong>Assets:</strong> ' . implode(', ', $plan_asset_links) . '</div>',
    );
  }
}