<p>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.”</p>

<p>From the docs:</p>

<blockquote>
  <p>…to attach a behavior dynamically, call the <code>yii\base\Component::attachBehavior()</code> method of the component to which the behavior is being attached…</p>
  
  <p><a href="https://www.yiiframework.com/doc/guide/2.0/en/concept-behaviors#attaching-behaviors" rel="nofollow noreferrer">Source</a></p>
</blockquote>

<p>So, in a custom Craft module, you might put something like this, in your <code>init</code> method:</p>

<pre><code>use perfectus\perform\PerForm;
use modules\mymodule\MyBehavior;

// ...

PerForm::$plugin-&gt;emailService-&gt;attachBehavior('myBehaviorHandle', new MyBehavior);
</code></pre>

<p>This gives you a chance to <a href="https://en.wikipedia.org/wiki/Monkey_patch" rel="nofollow noreferrer">monkey-patch</a> the service with your own functionality… but I can't speak to how inheritance works, or whether you'll be able to call <code>parent::myPatchedMethod($args)</code> (or, in Behavior-land, <code>$this-&gt;owner-&gt;myPatchedMethod($args)</code>) to ensure the least code is duplicated.</p>

<hr>

<p><em>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.</em></p>

CC BY-SA 4.0
2018-12-16T22:13:56.180Z
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.
andrew.welch
CC BY-SA 4.0
2018-12-15T20:57:12.783Z
2018-12-15T20:57:12.783Z
August Miller
<p>I want to expand functionality of <a href="https://github.com/ohlincik/craft-perform" rel="nofollow noreferrer">perform plugin</a> with generating pdf from message submission data and attaching it to email this plugin sends.</p>

<p>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 <code>vendor</code> directory?</p>

CC BY-SA 4.0
2018-12-15T15:24:42.907Z
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.
Chattervast
<plugin-development>
Overwriting specific method in plugin
# Overwriting specific method in plugin

(Asked by: username_0 on 2018-12-15)

I want to expand functionality of [perform plugin](https://github.com/ohlincik/craft-perform) 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?

**Tags:** plugin-development

> **Comments:**
> **username_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.  

---

## 1 answers

### Answer by username_2 on 2018-12-15. Score: 3 | Accepted answer

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.

> **Comments:**
> **username_3**: 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.  

---

