Skip to content

[4.x]: Change propagation method programmatically #16091

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

You must be logged in to vote

I think the only problem is the isDraftOrRevision() check. When you first create a new entry, and when you are making edits to an entry, it’s usually going to be a draft, so this condition is preventing your code from working when it should.

Instead, you should be checking to make sure the entry isn’t already propagating.

Here’s updated code that should work. (I also simplified a couple things that didn’t need to be there.)

use craft\elements\Entry;
use craft\events\ModelEvent;
use yii\base\Event;

Event::on(Entry::class, Entry::EVENT_BEFORE_SAVE, function(ModelEvent $event) {
    /** @var Entry $entry */
    $entry = $event->sender;

    if (
        !$entry->propagating &&
        $entry->

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
2 participants
Converted from issue

This discussion was converted from issue #16084 on November 12, 2024 16:32.