Skip to content

How to apply a element condition via plugin as a default rule? #11890

Answered by brandonkelly
vnali asked this question in Q&A
Discussion options

You must be logged in to vote

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.

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...
    }
);

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by brandonkelly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants