Yii2: Add/remove validation rules in Model from 3rd party module
<p>In the main Yii2 application, how can we add validation rules to a <a href="http://www.yiiframework.com/doc-2.0/yii-base-model.html" rel="nofollow noreferrer">Module</a> (or an <a href="http://www.yiiframework.com/doc-2.0/yii-db-activerecord.html" rel="nofollow noreferrer">ActiveRecord</a>) that comes with a 3rd party module?</p>
<p>Can we modify existing rules? Say we have the following rule:</p>
<pre><code>['currency', 'in', 'range' =&gt; ['USD', 'GBP', 'EUR']],
</code></pre>
<p>How would we add or remove any currencies inside the 'range' array?</p>
<p>Keep in mind that we cannot simply extend the class and override <code>rules()</code> since that would not change the parent class that the module is using. If the above is impossible, please shed some light on a proper way to design a module to support validation rule customization in its models/activerecords.</p>
<p>EDIT 2021: Upon revisiting this question ... Just don't do this. It may seem like the right approach, but it's not. You will end up pulling your hair out when you are getting mysterious validation errors that you have no idea where they are coming from.</p>