Fix the default URL for an Asset. It should be based on the parent, if available, and the menutitle.
This commit is contained in:
parent
193223c678
commit
dd716fa796
2 changed files with 15 additions and 2 deletions
|
|
@ -80,7 +80,7 @@ property url => (
|
||||||
builder => '_default_url',
|
builder => '_default_url',
|
||||||
);
|
);
|
||||||
sub _default_url {
|
sub _default_url {
|
||||||
return $_[0]->assetId;
|
return $_[0]->fixUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
around url => sub {
|
around url => sub {
|
||||||
|
|
@ -701,7 +701,9 @@ sub fixUrl {
|
||||||
|
|
||||||
# build a URL from the parent
|
# build a URL from the parent
|
||||||
unless ($url) {
|
unless ($url) {
|
||||||
$url = $self->getParent->url;
|
if (my $parent = $self->getParent) {
|
||||||
|
$url = $parent->url;
|
||||||
|
}
|
||||||
$url =~ s/(.*)\..*/$1/;
|
$url =~ s/(.*)\..*/$1/;
|
||||||
$url .= '/'.$self->menuTitle;
|
$url .= '/'.$self->menuTitle;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
11
t/Asset.t
11
t/Asset.t
|
|
@ -389,4 +389,15 @@ my $session = WebGUI::Test->session;
|
||||||
cmp_deeply($classes, [qw/WebGUI::Asset/], 'Any asset okay');
|
cmp_deeply($classes, [qw/WebGUI::Asset/], 'Any asset okay');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
note "url, inherited URLs from parent";
|
||||||
|
my $home = WebGUI::Asset->getDefault($session);
|
||||||
|
my $asset = $home->addChild({
|
||||||
|
className => 'WebGUI::Asset::Wobject::Article',
|
||||||
|
title => 'sub',
|
||||||
|
});
|
||||||
|
WebGUI::Test->addToCleanup($asset);
|
||||||
|
is $asset->url, 'home/sub', 'by default, asset gets a url from the title, and the parent';
|
||||||
|
}
|
||||||
|
|
||||||
done_testing;
|
done_testing;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue