0

I want to expand functionality of perform plugin with generating pdf from message submission data and attaching it to email this plugin sends.

I can't use events for this, because this plugin doesnt emit any. Can i somehow overwrite specific method in craft cms plugin, without resorting do directly changing code in vendor directory?

1
  • You could try asking for the functionality to be added, or copy the plugin to a plugins folder in the craft directory and sym-link it via composer and make your additions there. Dec 15 '18 at 15:24
3

If the methods you need to alter are part of an auto-instantiated Service in the PerForm plugin, you might consider using Yii 2 “Behaviors.”

From the docs:

…to attach a behavior dynamically, call the yii\base\Component::attachBehavior() method of the component to which the behavior is being attached…

Source

So, in a custom Craft module, you might put something like this, in your init method:

use perfectus\perform\PerForm;
use modules\mymodule\MyBehavior;

// ...

PerForm::$plugin->emailService->attachBehavior('myBehaviorHandle', new MyBehavior);

This gives you a chance to monkey-patch the service with your own functionality… but I can't speak to how inheritance works, or whether you'll be able to call parent::myPatchedMethod($args) (or, in Behavior-land, $this->owner->myPatchedMethod($args)) to ensure the least code is duplicated.


Overall, I agree with Indigo: The best way to ensure this will continue to work is to make a PR to the plugin that adds support for events at key moments, and shuttles the right kind of data around to accomplish what you want. This is the only way to ensure you have a stable event API.

1
  • I agree with your agreement. I'd be more include to add the feature to that plugin, and send them a PR. Worst case, you can use your fork of the plugin. Dec 16 '18 at 22:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.