function farm_asset_clone_action in farmOS 7
Action function for farm_asset_clone_action.
Clones an asset.
Parameters
FarmAsset $asset: The asset entity object.
array $context: Array with parameters for this action.
File
- modules/
farm/ farm_asset/ farm_asset.module, line 459 - Farm asset - A farm asset entity type.
Code
function farm_asset_clone_action(FarmAsset $asset, $context = array()) {
// Remember the asset ID.
$asset_id = $asset->id;
// Add "(clone of asset #[asset-id])" to the end of the asset's name.
$asset->name = $asset->name . ' ' . t('(clone of asset #@id)', array(
'@id' => $asset_id,
));
// Clear the asset ID.
unset($asset->id);
// Set the created and changed timestamps to now.
$asset->created = REQUEST_TIME;
$asset->changed = REQUEST_TIME;
// Save the asset.
farm_asset_save($asset);
// Set a message with a link to the new asset.
$asset_uri = entity_uri('farm_asset', $asset);
$asset_label = entity_label('farm_asset', $asset);
$message = t('Asset saved: <a href="@uri">%title</a>', array(
'@uri' => url($asset_uri['path']),
'%title' => $asset_label,
));
drupal_set_message($message);
}