src/model/PageSlice.php
public function onAfterDuplicate(PageSlice $slice)
    {
        // Check if there are relations set
        // Loop over each set relation
        // Copy all items in the relation over to the new object
        if ($hasManyRelations = $slice->data()->hasMany()) {
            foreach ($hasManyRelations as $relation => $class) {
                foreach ($slice->$relation() as $object) {
                    /** @var DataObject $object */
                    $copy = $object->duplicate(true);
                    $this->$relation()->add($copy);
                }
            }
        }
    }
public function onAfterDuplicate(PageSlice $slice)
    {
        // Check if there are relations set
        // Loop over each set relation
        // Copy all items in the relation over to the new object
        if ($hasManyRelations = $slice->data()->hasMany()) {
            foreach ($hasManyRelations as $relation => $class) {
                foreach ($slice->$relation() as $object) {
                    /** @var DataObject $object */
                    $copy = $object->duplicate(true);
                    $this->$relation()->add($copy);
                }
            }
        }
    }
public function onAfterDuplicate ( PageSlice $ slice ) { // Check if there are relations set // Loop over each set relation // Copy all items in the relation over to the new object if ( $ hasManyRelations = $ slice -> data ( ) -> hasMany ( ) ) { foreach ( $ hasManyRelations as $ relation => $ class ) { foreach ( $ slice -> $ relation ( ) as $ object ) { /** @var DataObject $object */ $ copy = $ object -> duplicate ( true ) ; $ this -> $ relation ( ) -> add ( $ copy ) ; } } } }
If this slice holds has_many content
on duplicate copy the content over

@param PageSlice $slice
If this slice holds has_many content on duplicate copy the content over