How to apply a element condition via plugin as a default rule? #11890
-
I am trying to figure out how to automatically apply an element condition rule to an element type index page via a plugin. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
If you don’t need users to be able to edit the condition, you don’t really need a condition in the first place. Instead you can modify the element criteria for your element sources, by adding an event handler to the element use craft\elements\Entry;
use craft\events\RegisterElementSourcesEvent;
use yii\base\Event;
Event::on(
Entry::class,
Entry::EVENT_REGISTER_SOURCES,
function (RegisterElementSourcesEvent $event) {
// Make adjustments to $event->sources here...
}
); |
Beta Was this translation helpful? Give feedback.
If you don’t need users to be able to edit the condition, you don’t really need a condition in the first place. Instead you can modify the element criteria for your element sources, by adding an event handler to the element
EVENT_REGISTER_SOURCES
event.