src/ElementsExtension.php
public function onAfterDelete()
    {
        $staged = Versioned::get_by_stage($this->owner->ClassName, Versioned::DRAFT)
            ->byID($this->owner->ID)
        ;

        $live = Versioned::get_by_stage($this->owner->ClassName, Versioned::LIVE)
            ->byID($this->owner->ID)
        ;

        if (!$staged && !$live)
        {
            foreach($this->owner->Elements() as $element)
            {
                $element->deleteFromStage(Versioned::LIVE);
                $element->deleteFromStage(Versioned::DRAFT);
                $element->delete();
            }
        }
        parent::onAfterDelete();
    }
public function onAfterDelete()
    {
        $staged = Versioned::get_by_stage($this->owner->ClassName, Versioned::DRAFT)
            ->byID($this->owner->ID)
        ;

        $live = Versioned::get_by_stage($this->owner->ClassName, Versioned::LIVE)
            ->byID($this->owner->ID)
        ;

        if (!$staged && !$live)
        {
            foreach($this->owner->Elements() as $element)
            {
                $element->deleteFromStage(Versioned::LIVE);
                $element->deleteFromStage(Versioned::DRAFT);
                $element->delete();
            }
        }
        parent::onAfterDelete();
    }
public function onAfterDelete ( ) { $ staged = Versioned :: get_by_stage ( $ this -> owner -> ClassName , Versioned :: DRAFT ) -> byID ( $ this -> owner -> ID ) ; $ live = Versioned :: get_by_stage ( $ this -> owner -> ClassName , Versioned :: LIVE ) -> byID ( $ this -> owner -> ID ) ; if ( ! $ staged && ! $ live ) { foreach ( $ this -> owner -> Elements ( ) as $ element ) { $ element -> deleteFromStage ( Versioned :: LIVE ) ; $ element -> deleteFromStage ( Versioned :: DRAFT ) ; $ element -> delete ( ) ; } } parent :: onAfterDelete ( ) ; }
Remove all related elements
Remove all related elements