You are here

function farm_sensor_entity_view_alter in farmOS 7

Implements hook_entity_view_alter().

File

modules/farm/farm_sensor/farm_sensor.module, line 166

Code

function farm_sensor_entity_view_alter(&$build, $type) {

  /*
   * Alter farm assets to display sensor information.
   */

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

  // If the entity information isn't available, bail.
  if (empty($build['#entity'])) {
    return;
  }
  $asset = $build['#entity'];

  // If the asset does not have a sensor type, bail.
  if (empty($asset->sensor_type)) {
    return;
  }

  // Load the list of sensor types.
  $sensor_types = farm_sensor_types();

  // Get the sensor type label if it exists.
  if (!empty($sensor_types[$asset->sensor_type])) {
    $sensor_type_label = $sensor_types[$asset->sensor_type]['label'];
  }
  else {
    $sensor_type_label = $asset->sensor_type . ' (undefined)';
  }

  // Add the sensor type.
  $build['sensor_type'] = array(
    '#markup' => '<p><strong>Sensor type:</strong> ' . $sensor_type_label . '</p>',
  );

  // Ask other modules for sensor asset view content.
  $module_content = module_invoke_all('farm_sensor_view', $asset);

  // Merge the asset view content into the build array.
  if (!empty($module_content)) {
    $build = array_merge_recursive($build, $module_content);
  }
}