You are here

function farm_inventory_entity_load in farmOS 7

Implements hook_entity_load().

File

modules/farm/farm_inventory/farm_inventory.module, line 97

Code

function farm_inventory_entity_load($entities, $type) {

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

  // Load asset type inventory settings.
  $settings = array();
  $result = db_query('SELECT * FROM {farm_inventory_asset_type}');
  foreach ($result as $row) {
    if (!empty($row->type)) {
      $settings[$row->type] = array(
        'enabled' => $row->enabled,
        'individual' => $row->individual,
      );
    }
  }

  // Iterate through the entities and add inventory settings.
  foreach ($entities as $entity) {

    // Get the asset type machine name.
    $asset_type = $entity->type;

    // If settings are available for the entity's bundle, add them.
    if (!empty($settings[$asset_type])) {
      $entity->inventory = $settings[$asset_type];
    }
  }
}