0

I'm trying to auto publish child pages if they are rearrange. Right now when we arrange those child pages it says modified.

We're trying to achieve an automation on how to auto publish it once we started drag and drop to their position.

1 Answers1

0

The idea may be to check the change of the Sort field and execute the doPublish(). Please, note that you must check if the page wasn't in the Draft state.

class FooPage extends Page {

    private $wasPublishedBeforeWrite = false;

    protected function onBeforeWrite()
    {
        parent::onBeforeWrite();
        // check if the page is published
        $this->wasPublishedBeforeWrite = !$this->isArchived() && !$this->isOnDraftOnly() && !$this->isModifiedOnDraft();
    }

    protected function onAfterWrite()
    {
        parent::onAfterWrite();
        if ($this->isChanged('Sort') && $this->wasPublishedBeforeWrite) {
            $this->publishSingle();
        }
    }
}