Jump to main content Jump to doc navigation

modResource.duplicate

Creates a copy of the Resource with a fresh ID. The pagetitle is kept unless newName or prefixDuplicate is given, and publication fields follow publishedMode. Template Variable values and Resource Group memberships are copied too.

Returns the new modResource, the resource_err_duplicate lexicon string when the copy cannot be saved, or false outside modX. Children are duplicated recursively unless duplicateChildren is disabled; recursion stops when the user lacks the add_children policy.

Syntax

mixed duplicate ([array $options = array()])
  • newName (string) pagetitle for the copy
  • prefixDuplicate (boolean) prefix the pagetitle with the duplicate_of lexicon entry
  • publishedMode (string) preserve (default), publish or unpublish
  • overrides (array) field values merged into the copy
  • parent (int) parent of the copy, by default the same parent
  • preserve_alias (boolean) keep the original alias instead of rebuilding it, by default false
  • preserve_menuindex (boolean) keep the original menuindex instead of appending, by default false
  • global_duplicate_uri_check (boolean) check alias uniqueness across all contexts, by default false
  • duplicateChildren (boolean) duplicate descendants as well, by default true

Example

$resource = $modx->getObject('modResource', array('id' => 5));
$copy = $resource->duplicate(array(
    'newName' => 'foobar copy',
    'publishedMode' => 'unpublish',
));

See Also

Support the team building MODX with a monthly donation.

The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.

Backers

  • modmore
  • STERC
  • Digital Penguin
  • Jens Wittmann – Gestaltung & Entwicklung
  • CrewMark
  • Fabian Christen
  • Sepia River Studios
  • Dannevang Digital
  • Alex
  • A. Moreno
  • Chris Fickling
  • Stéphane Jäggi
  • Murray Wood
  • Anton Tarasov
  • JT Skaggs
  • deJaya
  • Lefthandmedia
  • eydolan
  • Following Sea
  • Guido Gallenkamp
  • YJ
  • Raffy
  • Snow Creative
  • Nick Clark
  • Guest
  • Helen
  • krisznet
  • Yanni
  • Richard

Budget

$194 per month—let's make that $500!

Learn more