How to modify plugin behavior / how to extend plugin?

I need to modify the behavior of the forms plugin (so I can get the form data and the uploaded files to end up in the same, unique directory). How would I go about this?

  • Can I extend a plugin? If so, how?
  • Should I just modify the forms plugin’s files? This way, an update would undo my changes.
  • Should I copy the forms plugin, call it “forms2” and make my changes there? But then how do I tell Grav to use that instead of the original?
  • Any other way?

Thanks!

I haven’t actually done this, but my first impulse would be to try and find a hook in order to modify the behaviour of Grav or one of its plugins. Looking at form.php, I see the event onFormValidationProcessed with the comment “Custom field logic can go in here”. You can hook into that event from your theme’s PHP:

    public function onFormValidationProcessed(\RocketTheme\Toolbox\Event\Event $e)
    {
        dump($e['form']->fields());
        
    }

My first impulse would be to try to modify destination with some setter function from classes/Form.php. Even if that works, though, I’d very carefully test my code before I trust my data on an approach from random strangers that start their advice with “I haven’t actually done this …” :slight_smile:

1 Like