Fix inheritUrlFromParent, using trigger instead of around.

This commit is contained in:
Colin Kuskie 2010-01-22 11:07:46 -08:00
parent 6573884db6
commit 5c3a3d440b
2 changed files with 13 additions and 11 deletions

View file

@ -220,12 +220,11 @@ property inheritUrlFromParent => (
uiLevel => 9,
fieldType => 'yesNo',
default => 0,
trigger => \&_set_inheritUrlFromParent,
);
around inheritUrlFromParent => sub {
my $orig = shift;
my $self = shift;
$self->$orig(@_);
if (@_ > 0 && $_[0]) {
sub _set_inheritUrlFromParent {
my ($self, $new, $old) = @_;
if ($new && ($new != $old)) {
$self->url($self->url);
}
};
@ -686,9 +685,8 @@ sub fixUrl {
# if we're inheriting the URL from our parent, set that appropriately
my @parts = split(m{/}, $url);
# don't do anything unless we need to
if($url ne $self->getParent->get('url') . '/' . $parts[-1]) {
$url = $self->getParent->get('url') . '/' . $parts[-1];
}
my $inheritUrl = $self->getParent->get('url') . '/' . $parts[-1];
$url = $inheritUrl if $url ne $inheritUrl;
}
$url = $self->session->url->urlize($url);

View file

@ -499,15 +499,17 @@ is($rootAsset->get('isExportable'), 1, 'isExportable exists, defaults to 1');
# getSeparator
#
################################################################
is($rootAsset->getSeparator, '~~~PBasset000000000000001~~~', 'getSeparator, known assetId');
is($rootAsset->getSeparator('!'), '!!!PBasset000000000000001!!!', 'getSeparator, given pad character');
isnt($rootAsset->getSeparator, $mediaFolder->getSeparator, 'getSeparator: unique string');
note "getSeparator";
is($rootAsset->getSeparator, '~~~PBasset000000000000001~~~', '... known assetId');
is($rootAsset->getSeparator('!'), '!!!PBasset000000000000001!!!', '... given pad character');
isnt($rootAsset->getSeparator, $mediaFolder->getSeparator, '... unique string');
################################################################
#
# get
#
################################################################
note "get";
my $assetProps = $rootAsset->get();
my $funkyTitle = q{Miss Annie's Whoopie Emporium and Sasparilla Shop};
$assetProps->{title} = $funkyTitle;
@ -555,6 +557,7 @@ $product3->purge;
# inheritUrlFromParent
#
################################################################
note "inheritUrlFromParent";
my $versionTag4 = WebGUI::VersionTag->getWorking($session);
WebGUI::Test->tagsToRollback($versionTag4);
@ -581,6 +584,7 @@ $properties2 = {
my $iufpAsset2 = $iufpAsset->addChild($properties2, $properties2->{id});
$iufpAsset2->update( { inheritUrlFromParent => 1 } );
is $iufpAsset2->inheritUrlFromParent, 1, 'inheritUrlFromParent set';
$iufpAsset2->commit;
is($iufpAsset2->get('url'), 'inheriturlfromparent01/inheriturlfromparent02', 'inheritUrlFromParent works');