You are here

function _farm_sensor_entity_save in farmOS 7

Helper function for saving farm sensor information on entity insert and update.

Parameters

$entity: The entity being saved.

$type: The type of entity being saved.

2 calls to _farm_sensor_entity_save()
farm_sensor_entity_insert in modules/farm/farm_sensor/farm_sensor.module
Implements hook_entity_insert().
farm_sensor_entity_update in modules/farm/farm_sensor/farm_sensor.module
Implements hook_entity_update().

File

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

Code

function _farm_sensor_entity_save($entity, $type) {

  // Only act on farm asset entities.
  if ($type != 'farm_asset') {
    return;
  }

  // Only act on sensor assets.
  if ($entity->type != 'sensor') {
    return;
  }

  // Only act if a sensor type is set.
  if (empty($entity->sensor_type)) {
    return;
  }

  // If sensor settings are not set, save an empty array.
  if (!isset($entity->sensor_settings)) {
    $entity->sensor_settings = array();
  }

  // Save the sensor record.
  farm_sensor_save($entity->id, $entity->sensor_type, $entity->sensor_settings);
}