You are here

public function FarmAssetProcessor::setTargetElement in farmOS 7

Override setTargetElement to operate on a target item that is a farm asset.

File

modules/farm/farm_asset/includes/feeds/plugins/FarmAssetProcessor.inc, line 181
Class definition of FarmAssetProcessor.

Class

FarmAssetProcessor
Creates farm assets from feed items.

Code

public function setTargetElement(FeedsSource $source, $target_asset, $target_element, $value) {
  switch ($target_element) {
    case 'created':
      $target_asset->created = feeds_to_unixtime($value, REQUEST_TIME);
      break;
    case 'changed':

      // The 'changed' value will be set on the asset in
      // farm_asset_entity_presave(). This is because farm_asset_save()
      // always overwrites this value (though before invoking
      // hook_entity_presave()).
      $target_asset->feeds_item->asset_changed = feeds_to_unixtime($value, REQUEST_TIME);
      break;
    case 'archived':

      // If the 'archived' property is set to TRUE, then use the current
      // timestamp.
      if ($value == TRUE) {
        $target_asset->archived = REQUEST_TIME;
      }
      break;
    case 'user_name':
      if ($user = user_load_by_name($value)) {
        $target_asset->uid = $user->uid;
      }
      break;
    case 'user_mail':
      if ($user = user_load_by_mail($value)) {
        $target_asset->uid = $user->uid;
      }
      break;
    default:
      parent::setTargetElement($source, $target_asset, $target_element, $value);
      break;
  }
}