public function AssetClone::execute in farmOS 2.x
Executes the plugin.
Overrides ExecutableInterface::execute
File
- modules/
core/ asset/ src/ Plugin/ Action/ AssetClone.php, line 23
Class
- AssetClone
- Action that clones an asset.
Namespace
Drupal\asset\Plugin\ActionCode
public function execute(AssetInterface $asset = NULL) {
if ($asset) {
$cloned_asset = $asset
->createDuplicate();
$new_name = $asset
->getName() . ' ' . $this
->t('(clone of asset #@id)', [
'@id' => $asset
->id(),
]);
$cloned_asset
->setName($new_name);
$cloned_asset
->save();
$this
->messenger()
->addMessage($this
->t('Asset saved: <a href=":uri">%asset_label</a>', [
':uri' => $cloned_asset
->toUrl()
->toString(),
'%asset_label' => $cloned_asset
->label(),
]));
}
}