Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added event hooks #63

Merged
merged 1 commit into from Jun 8, 2017
Merged

added event hooks #63

merged 1 commit into from Jun 8, 2017

Conversation

therealkevinard
Copy link
Contributor

@therealkevinard therealkevinard commented Jun 6, 2017

This PR causes the plugin to dispatch events through the October framework before and after saving a record, in order for others to extend the action with custom handlers.

This is to better support issues along the lines of:

A snippet implementation from my use-case:

<?php namespace Rwm\MfContactsView;

use Illuminate\Support\Facades\Event;
use System\Classes\PluginBase;

class Plugin extends PluginBase
{
    // ... other plugin setup ... 
    
    public function boot()
    {
        /**
         * In my particular use-case, I've used this event hook in a custom plugin to render the form data in a tailored way. A lightweight backend plugin in my namespace
         *  listend for the MF beforeSaveRecord, and performs custom mutation\persistence with the raw form data passed along with the event.
         *
         *  Magic Forms still manages all front-end display, and manages datastore for all forms - but client pushed for this specific form to have a certain view.
         */
        Event::listen('martin.forms.beforeSaveRecord', function ($formdata) {
            $contact = json_decode($formdata);
            xdebug_break();
            //-- Now do something with $formdata (which contains the complete json_encode of the original form data.)
        });

        Event::listen('martin.forms.afterSaveRecord', function ($formdata) {
            $contact = json_decode($formdata);
            xdebug_break();
        });
    }

    // ... other plugin setup ... 

}

@skydiver skydiver changed the base branch from master to BETA June 8, 2017 15:29
@skydiver skydiver merged commit 1467327 into skydiver:BETA Jun 8, 2017
@skydiver
Copy link
Owner

skydiver commented Jun 8, 2017

Hello @therealkevinard, excellent addition to the plugin.

I will be merging right now, thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants