<p>It probably would be better to just write your own plugin to do this, so that you don't have to worry about patching in your changes every time the <code>guestEntries</code> plugin is updated — and it could technically be just one file, although the recommended craft method would be to create a <code>service</code> method to handle the events.</p>

<p>In your plugins main class file, just create an <code>init</code> method that listens for the <code>entries.saveEntry</code> event for the section in question:</p>

<pre><code>public function init()
{
    parent::init();

    craft()-&gt;on('entries.saveEntry', function(Event $event) 
    {
        $entry = $event-&gt;params['entry'];
        if ($entry-&gt;section == 'MySection') 
        {
            if ($event-&gt;params['isNewEntry']) 
            {
                craft()-&gt;myplugin-&gt;handleNewSectionEntry($entry);
                // or do something directly
            } 
            else 
            {   
                craft()-&gt;myplugin-&gt;handleUpdateSectionEntry($entry);
                // or do something directly
            }
        }
    }); // edited
}
</code></pre>

<p>If you need to test whether it is a 'guest' entry from the front-end vs the CP you can add:</p>

<pre><code>if (!$currentUser) { ... }
</code></pre>

CC BY-SA 3.0
2014-11-03T22:21:56.033Z
2015-04-25T14:24:41.870Z
2015-04-25T14:24:41.870Z
Douglas McDonald
<p>I'm currently working on a plugin that sends an email before the Guest Entries Plugin saves the entry. But one of the fields is an asset field and the file may be renamed when uploaded so I need to switch this up so the email being sent after the entry is saved.  I tried creating an onEntrySave event in the Guest Entries plugin by doing the following. </p>

<p>Added to GuestEntriesService.php: </p>

<pre><code>/**
     * Fires an 'onSaveEntry' event.
     *
     * @param GuestEntriesEvent $event
     *
     * @return null
     */
    public function onSaveEntry(GuestEntriesEvent $event)
    {
        $this-&gt;raiseEvent('onSaveEntry', $event);
    }
</code></pre>

<p>In GuestEntriesController.php I've added </p>

<pre><code>$this-&gt;onSaveEntry(new GuestEntriesEvent($this, array('entry'=&gt; $entry,'isNewEntry' =&gt; true)));
</code></pre>

<p>to the section of the code where the entry is saved.  </p>

<pre><code>if (craft()-&gt;entries-&gt;saveEntry($entry))
{
     $this-&gt;onSaveEntry(new GuestEntriesEvent($this, array('entry'=&gt; $entry,'isNewEntry' =&gt; true)));
     $this-&gt;_returnSuccess($entry);

}
</code></pre>

<p>But this is where I've gone wrong as I get the error:</p>

<p>Craft\GuestEntriesController and its behaviors do not have a method or closure named "onSaveEntry".</p>

<p>How do I go about modifying the plugin to trigger an onSaveEntry event?</p>

<plugin-development>
Creating an onSaveEntry event in Guest Entries Plugin
# Creating an onSaveEntry event in Guest Entries Plugin

(Asked by: username_0 on 2014-11-03)

I'm currently working on a plugin that sends an email before the Guest Entries Plugin saves the entry. But one of the fields is an asset field and the file may be renamed when uploaded so I need to switch this up so the email being sent after the entry is saved.  I tried creating an onEntrySave event in the Guest Entries plugin by doing the following. 
Added to GuestEntriesService.php: 
/**
     * Fires an 'onSaveEntry' event.
     *
     * @param GuestEntriesEvent $event
     *
     * @return null
     */
    public function onSaveEntry(GuestEntriesEvent $event)
    {
        $this->raiseEvent('onSaveEntry', $event);
    }

In GuestEntriesController.php I've added 
$this->onSaveEntry(new GuestEntriesEvent($this, array('entry'=> $entry,'isNewEntry' => true)));

to the section of the code where the entry is saved.  
if (craft()->entries->saveEntry($entry))
{
     $this->onSaveEntry(new GuestEntriesEvent($this, array('entry'=> $entry,'isNewEntry' => true)));
     $this->_returnSuccess($entry);

}

But this is where I've gone wrong as I get the error:
Craft\GuestEntriesController and its behaviors do not have a method or closure named "onSaveEntry".
How do I go about modifying the plugin to trigger an onSaveEntry event?

**Tags:** plugin-development


---

## 1 answers

### Answer by username_1 on 2014-11-03. Score: 4 | Accepted answer

It probably would be better to just write your own plugin to do this, so that you don't have to worry about patching in your changes every time the guestEntries plugin is updated — and it could technically be just one file, although the recommended craft method would be to create a service method to handle the events.
In your plugins main class file, just create an init method that listens for the entries.saveEntry event for the section in question:
public function init()
{
    parent::init();

    craft()->on('entries.saveEntry', function(Event $event) 
    {
        $entry = $event->params['entry'];
        if ($entry->section == 'MySection') 
        {
            if ($event->params['isNewEntry']) 
            {
                craft()->myplugin->handleNewSectionEntry($entry);
                // or do something directly
            } 
            else 
            {   
                craft()->myplugin->handleUpdateSectionEntry($entry);
                // or do something directly
            }
        }
    }); // edited
}

If you need to test whether it is a 'guest' entry from the front-end vs the CP you can add:
if (!$currentUser) { ... }


---

