Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Plugins

How to modify plugin behavior / how to extend plugin?

Started by Julien 8 years ago · 1 replies · 869 views
8 years ago

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!

8 years ago

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:

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 ..." 🙂

👍 1

Suggested topics

Topic Participants Replies Views Activity
Plugins · by Rene, 1 week ago
2 46 1 week ago
Plugins · by Xavier, 4 weeks ago
2 55 4 weeks ago
Plugins · by Luka Prinčič, 7 years ago
3 1181 1 month ago
Plugins · by Sebastian van de Meer, 1 month ago
1 49 1 month ago
Plugins · by PIERROT Alain, 2 months ago
3 73 2 months ago