Devise\Pages\PageVersionManager::copyPageVersionToAnotherPage PHP Method

copyPageVersionToAnotherPage() public method

Copies a page version to another page this is useful when creating different languages of the same page
public copyPageVersionToAnotherPage ( $fromVersion, $toPage ) : PageVersion
$fromVersion
$toPage
return PageVersion
    public function copyPageVersionToAnotherPage($fromVersion, $toPage)
    {
        // create a new page version
        $newVersion = $this->createNewPageVersion($toPage->id, $fromVersion->name, $this->UserHelper->currentUserId());
        $this->copyFieldsFromVersionToVersion($fromVersion, $newVersion);
        $this->copyCollectionsFromVersionToVersion($fromVersion, $newVersion);
        return $newVersion;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Takes the input provided and runs the create method after stripping necessary fields.
  *
  * @param  integer $fromPageId
  * @param  array   $input
  * @return DvsPage
  */
 public function copyPage($fromPageId, $input)
 {
     $fromPage = $this->Page->findOrFail($fromPageId);
     if (isset($input['page_version_id'])) {
         // a specific version has been requested to copy
         $fromPageVersion = $fromPage->versions()->findOrFail($input['page_version_id']);
         $fromPageVersion->name = 'Default';
     } else {
         // we'll use the current live version to copy
         $fromPageVersion = $fromPage->getLiveVersion();
     }
     // get translated page id, if page copy is translation and langauges are different
     if (array_get($input, 'copy_reason') == 'translate' && array_get($input, 'language_id') !== $fromPage->language_id) {
         $input = $this->getTranslatedFromPageId($fromPageId, $input);
     }
     $toPage = $this->createPageFromInput($input);
     if (!$toPage) {
         return false;
     }
     $this->PageVersionManager->copyPageVersionToAnotherPage($fromPageVersion, $toPage);
     $this->cacheDeviseRoutes();
     return $toPage;
 }