Jump to content

Neeks

Members
  • Posts

    93
  • Joined

  • Last visited

Community Answers

  1. Neeks's post in Copying image from one page to another...To clone or not to clone.... was marked as the answer   
    Solved it by reading how $pages->clone() does it, and just doing that....
    I also see that $pages->clone() has the ability to set an argument to specify a page ID which solves my issue of cloning a page and not having the the page ID I want after the clone.
    //copies the fields of one page to replace the fields of another page. function copyFields ($sourcePage, $destinationPage) { //Copy Fields between pages $destinationPage->of(false); $sourcePage->of(false); foreach ($destinationPage->template->fieldgroup as $field){ if($field->type instanceOf FieldtypeTable){ //You get duplicare SQL index errors if you don't use clone. $destinationPage->$field = clone $sourcePage->$field; }elseif($field->type instanceOf FieldtypeTextarea){ //Update image an file links in rich text fields $destinationPage->$field = str_replace("/files/{$sourcePage->id}/","/files/{$destinationPage->id}/",$sourcePage->$field); }else{ $destinationPage->$field = $sourcePage->$field; } } // Copy $sourcePage's files over to new page if(PagefilesManager::hasFiles($sourcePage)) { $destinationPage->filesManager->init($destinationPage); $sourcePage->filesManager->copyFiles($destinationPage->filesManager->path()); } return $destinationPage; }
×
×
  • Create New...