diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 123f42758..15b3e36d9 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -41,6 +41,7 @@ - fixed #8802: isImage not functioning in Folders - added RFE #480: Apply button for assets - fixed #8807: _NewAsset.skeleton out of date + - added: "Duplicate this template and edit" now updates the asset we came from, if any 7.6.0 - added: users may now customize the post received page for the CS diff --git a/lib/WebGUI/Asset/Template.pm b/lib/WebGUI/Asset/Template.pm index 9c79c78e9..5a4568c53 100644 --- a/lib/WebGUI/Asset/Template.pm +++ b/lib/WebGUI/Asset/Template.pm @@ -440,9 +440,43 @@ Make a duplicate of this template and edit that instead. sub www_editDuplicate { my $self = shift; return $self->session->privilege->insufficient() unless $self->canEdit; - my $newAsset = $self->duplicate; - $newAsset->update( { isDefault => 0 } ); - return $newAsset->www_edit; + + my $session = $self->session; + my $form = $self->session->form; + + my $newTemplate = $self->duplicate; + $newTemplate->update( { + isDefault => 0, + title => $self->get( "title" ) . " (copy)", + menuTitle => $self->get( "menuTitle" ) . " (copy)", + } ); + + # Make our asset use our new template + if ( $self->session->form->get( "proceed" ) eq "goBackToPage" ) { + if ( my $asset = WebGUI::Asset->newByUrl( $session, $form->get( "returnUrl" ) ) ) { + # Find which property we should set by comparing namespaces and current values + DEF: for my $def ( @{ $asset->definition( $self->session ) } ) { + my $properties = $def->{ properties }; + PROP: for my $prop ( keys %{ $properties } ) { + next PROP unless lc $properties->{ $prop }->{ fieldType } eq "template"; + next PROP unless $asset->get( $prop ) eq $self->getId; + if ( $properties->{ $prop }->{ namespace } eq $self->get( "namespace" ) ) { + $asset->addRevision( { $prop => $newTemplate->getId } ); + + # Auto-commit our revision if necessary + # TODO: This needs to be handled automatically somehow... + if ($session->setting->get("autoRequestCommit")) { + my $tag = WebGUI::VersionTag->getWorking($session)->requestCommit; + } + + last DEF; + } + } + } + } + } + + return $newTemplate->www_edit; } #-------------------------------------------------------------------