You are here

function farm_asset_entity_view in farmOS 7

Implements hook_entity_view().

File

modules/farm/farm_asset/farm_asset.module, line 320
Farm asset - A farm asset entity type.

Code

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

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

  // Add the asset type.
  $asset_types = farm_asset_type_get_names();
  if (!empty($asset_types[$entity->type])) {
    $entity->content['type'] = array(
      '#markup' => '<div><strong>' . t('Asset type:') . '</strong> ' . $asset_types[$entity->type] . '</div>',
      '#weight' => -102,
    );
  }

  // Add the asset ID.
  if (!empty($entity->id)) {
    $entity->content['id'] = array(
      '#markup' => '<div><strong>' . t('Asset ID:') . '</strong> ' . $entity->id . '</div>',
      '#weight' => -101,
    );
  }

  // If the asset is archived, display a message and the archived date.
  if (!empty($entity->archived)) {
    drupal_set_message(t('This asset is archived. Archived assets should not be edited or deleted unless they contain information that is incorrect.'), 'warning');
    $date = format_date($entity->archived);
    $entity->content['archived'] = array(
      '#markup' => '<div><strong>' . t('Archived') . ':</strong> ' . $date . '</div>',
      '#weight' => -100,
    );
  }
}