Skip to main content
Added more info, benefits to using events
Source Link
Alec Ritson
  • 4.5k
  • 1
  • 20
  • 34

I think your best bet here would be to make use of the entries.onSaveEntry event, because at the moment $entry doesn't relate to the entry you have just saved, but the entry you wanted to save so it makes sense the entry asset paths are still pointing to the temp locations.

As far as i'm aware craft()->entries->saveEntry() just returns a bool, whether or not the save was a success, and not the entry model that was just saved.

So your controller could look like this:

if (!craft()->entries->saveEntry($entry))
{
 // Only worry if something goes wrong
}

Then in an init function in your main plugin class you could do something like:

craft()->on('entries.saveEntry', function(Event $event){

 // Is this a new entry?
 if($event->params['isNewEntry'])
 {
    // This is an EntryModel object of the entry that was just saved
    $entry = $event->params['entry'];

    // Is the entry in the right section?
    if($entry->sectionId == 1)
    {
      // Send the $entry to your email function
      craft()->yourPlugin->sendEmail($entry);
    }
 }

});

I would assume at this point the asset paths are all correct as it would have been saved to the database and all the backend work done etc

This would help you out in the future as well as it wouldn't matter where the entry was created, whether in the admin or through your plugin or anywhere else, and you could be sure the email will still get triggered :)

Failing that you could also try the assets.onSaveAsset event and see if you get better results with that?

http://buildwithcraft.com/docs/plugins/events-reference

I hope this helps in some way!

I think your best bet here would be to make use of the entries.onSaveEntry event, because at the moment $entry doesn't relate to the entry you have just saved, but the entry you wanted to save so it makes sense the entry asset paths are still pointing to the temp locations.

As far as i'm aware craft()->entries->saveEntry() just returns a bool, whether or not the save was a success, and not the entry model that was just saved.

So your controller could look like this:

if (!craft()->entries->saveEntry($entry))
{
 // Only worry if something goes wrong
}

Then in an init function in your main plugin class you could do something like:

craft()->on('entries.saveEntry', function(Event $event){

 // Is this a new entry?
 if($event->params['isNewEntry'])
 {
    // This is an EntryModel object of the entry that was just saved
    $entry = $event->params['entry'];

    // Is the entry in the right section?
    if($entry->sectionId == 1)
    {
      // Send the $entry to your email function
      craft()->yourPlugin->sendEmail($entry);
    }
 }

});

I would assume at this point the asset paths are all correct as it would have been saved to the database and all the backend work done etc

Failing that you could also try the assets.onSaveAsset event and see if you get better results with that?

http://buildwithcraft.com/docs/plugins/events-reference

I hope this helps in some way!

I think your best bet here would be to make use of the entries.onSaveEntry event, because at the moment $entry doesn't relate to the entry you have just saved, but the entry you wanted to save so it makes sense the entry asset paths are still pointing to the temp locations.

As far as i'm aware craft()->entries->saveEntry() just returns a bool, whether or not the save was a success, and not the entry model that was just saved.

So your controller could look like this:

if (!craft()->entries->saveEntry($entry))
{
 // Only worry if something goes wrong
}

Then in an init function in your main plugin class you could do something like:

craft()->on('entries.saveEntry', function(Event $event){

 // Is this a new entry?
 if($event->params['isNewEntry'])
 {
    // This is an EntryModel object of the entry that was just saved
    $entry = $event->params['entry'];

    // Is the entry in the right section?
    if($entry->sectionId == 1)
    {
      // Send the $entry to your email function
      craft()->yourPlugin->sendEmail($entry);
    }
 }

});

I would assume at this point the asset paths are all correct as it would have been saved to the database and all the backend work done etc

This would help you out in the future as well as it wouldn't matter where the entry was created, whether in the admin or through your plugin or anywhere else, and you could be sure the email will still get triggered :)

Failing that you could also try the assets.onSaveAsset event and see if you get better results with that?

http://buildwithcraft.com/docs/plugins/events-reference

I hope this helps in some way!

Source Link
Alec Ritson
  • 4.5k
  • 1
  • 20
  • 34

I think your best bet here would be to make use of the entries.onSaveEntry event, because at the moment $entry doesn't relate to the entry you have just saved, but the entry you wanted to save so it makes sense the entry asset paths are still pointing to the temp locations.

As far as i'm aware craft()->entries->saveEntry() just returns a bool, whether or not the save was a success, and not the entry model that was just saved.

So your controller could look like this:

if (!craft()->entries->saveEntry($entry))
{
 // Only worry if something goes wrong
}

Then in an init function in your main plugin class you could do something like:

craft()->on('entries.saveEntry', function(Event $event){

 // Is this a new entry?
 if($event->params['isNewEntry'])
 {
    // This is an EntryModel object of the entry that was just saved
    $entry = $event->params['entry'];

    // Is the entry in the right section?
    if($entry->sectionId == 1)
    {
      // Send the $entry to your email function
      craft()->yourPlugin->sendEmail($entry);
    }
 }

});

I would assume at this point the asset paths are all correct as it would have been saved to the database and all the backend work done etc

Failing that you could also try the assets.onSaveAsset event and see if you get better results with that?

http://buildwithcraft.com/docs/plugins/events-reference

I hope this helps in some way!