1

My setup:

Craft 3 installation with a multi-site setup. 3 languages, all enabled.

I have a custom plugin with a custom element type, FooBar that extends the Element class and a custom FooBar field type allowing me to link to an FooBar entry.

I've created 3 FooBar entries, one in each site. If I edit one of the FooBar entries, only that entries title updates. That all works fine.

I have a Single with a relation field linked to the FooBar field, with one of the FooBar entries selected.

All pretty standard relation setup.

If I edit the Single but click on the Foobar entry title, the slideout panel opens allowing me to edit FooBar entry...That's fine. Expected functionality...

When I click save in the slideout panel, the FooBar entry is saved, again as expected but the title value is also updated across all 3 sites. From what I can gather, its because propagation is happening.

How do I update the FooBar entry in the current site only, stopping propagation (basically not updating across all 3 sites) ?

Saving an element within a slideout panel is core Craft functionality, My beforeSave event listener on FooBar element is not firing.

So is there another event, or something that I've missed where I can prevent the FooBar entry from being updated across all 3 site.

1 Answer 1

0

Perhaps you mean propagation, can you try this in your custom plugin/module?

Event::on(
    Elements::class,
    Elements::EVENT_AFTER_SAVE_ELEMENT,
    static function (ElementEvent $e): void {
        // Skip propagating entries/elements
        if ($e->element->propagating) {
            return;
        }
    }
);

In fact, you can use this in any other event where the element is propagated

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.