craft()->on('entries.saveEntry', function(Event $event)
{
// entry slug, will be used as image name
$EntryTitle = $event->params['entry']['slug'];
// Get attached image
$entry = $event->params['entry']['imgdir'][0];
craft()->assets->renameFile($entry, $EntryTitle);
$entry->setAttribute('filename', $EntryTitle);
craft()->assets->storeFile($entry);
});
This init()
code gets the current entry title right after it was saved, and is supposed to use it to rename an attached file.
I used a method given by another developer in the context of a saveAsset, but it doesn't seem to work in this new context (→ see Change asset name on upload).
I'm not sure i've set the $entry
variable to correct data. Fact is I'm able trough the path you see above, to get access to the asset.
Please tell me where this code is wrong.