Mobile template is not being inherited (#12246)
Break get_add_instance out of www_add; subclass it in Layout to pull mobileTemplateId and mobileStyleTemplateId from the parent if the parent is also a Layout.
This commit is contained in:
parent
b05c7ea810
commit
ee121e9460
4 changed files with 110 additions and 25 deletions
|
|
@ -7,6 +7,7 @@
|
|||
- fixed #12239: Still get cart error message after removing extra recurring items from the cart
|
||||
- fixed #12240: Empty Extend Calendar Recurrance version tags
|
||||
- fixed #12241: Account Shop
|
||||
- fixed #12246: Layout inherits mobileStyleTemplateId and mobileTemplateId from parent Layouts
|
||||
|
||||
7.10.22
|
||||
- rfe #12223: Add date type to content profiling (metadata)
|
||||
|
|
|
|||
|
|
@ -2891,20 +2891,51 @@ sub view {
|
|||
|
||||
=head2 www_add ( )
|
||||
|
||||
Adds a new Asset based upon the class of the current form. Returns the Asset calling method www_edit(); The
|
||||
new Asset will inherit security and style properties from the current asset, the parent.
|
||||
Create a new, unsaved asset with a parent of this asset from C<class>, C<url>, and optional C<prototype> parameters and present the
|
||||
edit screen for it.
|
||||
Calls C<get_add_instance> to configure the new asset; the default implementation inherits security and
|
||||
style properties from the current asset, the parent.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_add {
|
||||
my $self = shift;
|
||||
my %prototypeProperties;
|
||||
my $class = $self->loadModule($self->session, $self->session->form->process("class","className"));
|
||||
my $prototype = $self->session->form->process('prototype');
|
||||
my $url = scalar($self->session->form->param("url"));
|
||||
|
||||
return undef unless (defined $class);
|
||||
return $self->session->privilege->insufficient() unless ($class->canAdd($self->session));
|
||||
if ($self->session->form->process('prototype')) {
|
||||
my $prototype = WebGUI::Asset->new($self->session, $self->session->form->process("prototype"),$class);
|
||||
foreach my $definition (@{$prototype->definition($self->session)}) { # cycle through rather than copying properties to avoid grabbing stuff we shouldn't grab
|
||||
|
||||
my $newAsset = $class->get_add_instance( $self->session, $self, $url, $prototype );
|
||||
|
||||
$newAsset->{_parent} = $self;
|
||||
return $newAsset->www_edit();
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 get_add_instance ( $session, $parentAsset, $url, $prototype )
|
||||
|
||||
Class method.
|
||||
Called from C<www_add> by the parent asset on the class of the new asset being constructed.
|
||||
Configures the new asset with defaults, including inheriting security and style properties from the current asset.
|
||||
C<$prototype> is the optional assetId of an asset to initialize the new asset from.
|
||||
|
||||
=cut
|
||||
|
||||
sub get_add_instance {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my $parentAsset = shift;
|
||||
my $url = shift;
|
||||
my $prototype = shift;
|
||||
|
||||
my %prototypeProperties;
|
||||
|
||||
if ($prototype) {
|
||||
my $prototype = WebGUI::Asset->new($session, $prototype, $class);
|
||||
foreach my $definition (@{$prototype->definition($session)}) { # cycle through rather than copying properties to avoid grabbing stuff we shouldn't grab
|
||||
foreach my $property (keys %{$definition->{properties}}) {
|
||||
next if (isIn($property,qw(title menuTitle url isPrototype isPackage)));
|
||||
next if ($definition->{properties}{$property}{noFormPost});
|
||||
|
|
@ -2912,24 +2943,25 @@ sub www_add {
|
|||
}
|
||||
}
|
||||
}
|
||||
my %properties = (
|
||||
%prototypeProperties,
|
||||
parentId => $self->getId,
|
||||
groupIdView => $self->get("groupIdView"),
|
||||
groupIdEdit => $self->get("groupIdEdit"),
|
||||
ownerUserId => $self->get("ownerUserId"),
|
||||
encryptPage => $self->get("encryptPage"),
|
||||
styleTemplateId => $self->get("styleTemplateId"),
|
||||
printableStyleTemplateId => $self->get("printableStyleTemplateId"),
|
||||
isHidden => $self->get("isHidden"),
|
||||
className=>$class,
|
||||
assetId=>"new",
|
||||
url=>scalar($self->session->form->param("url")),
|
||||
);
|
||||
$properties{isHidden} = 1 unless $self->session->config->get("assets/".$class."/isContainer");
|
||||
my $newAsset = WebGUI::Asset->newByPropertyHashRef($self->session,\%properties);
|
||||
$newAsset->{_parent} = $self;
|
||||
return $newAsset->www_edit();
|
||||
|
||||
my %properties = (
|
||||
%prototypeProperties,
|
||||
parentId => $parentAsset->getId,
|
||||
groupIdView => $parentAsset->get("groupIdView"),
|
||||
groupIdEdit => $parentAsset->get("groupIdEdit"),
|
||||
ownerUserId => $parentAsset->get("ownerUserId"),
|
||||
encryptPage => $parentAsset->get("encryptPage"),
|
||||
styleTemplateId => $parentAsset->get("styleTemplateId"),
|
||||
printableStyleTemplateId => $parentAsset->get("printableStyleTemplateId"),
|
||||
isHidden => $parentAsset->get("isHidden"),
|
||||
className => $class,
|
||||
assetId => "new",
|
||||
url => $url,
|
||||
);
|
||||
$properties{isHidden} = 1 unless $session->config->get("assets/".$class."/isContainer");
|
||||
|
||||
return WebGUI::Asset->newByPropertyHashRef($session, \%properties);
|
||||
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -514,5 +514,35 @@ sub www_view {
|
|||
return $self->SUPER::www_view;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 get_add_instance ()
|
||||
|
||||
Subclass the standard C<get_add_instance> to inherit
|
||||
C<mobileStyleTemplateId> and C<mobileTemplateId> from the parent asset if it is an instance of
|
||||
L<WebGUI::Asset::Wobject::Layout>.
|
||||
|
||||
=cut
|
||||
|
||||
sub get_add_instance {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my $parentAsset = shift;
|
||||
my $url = shift;
|
||||
my $prototype = shift;
|
||||
|
||||
my $instance = $class->SUPER::get_add_instance( $session, $parentAsset, $url, $prototype, @_ );
|
||||
|
||||
if( $parentAsset->isa('WebGUI::Asset::Wobject::Layout') ) {
|
||||
$instance->update({
|
||||
mobileStyleTemplateId => $parentAsset->get("mobileStyleTemplateId"),
|
||||
mobileTemplateId => $parentAsset->get("mobileTemplateId"),
|
||||
});
|
||||
}
|
||||
|
||||
return $instance;
|
||||
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
|
|
|||
|
|
@ -16,8 +16,9 @@ use lib "$FindBin::Bin/../../lib";
|
|||
use Test::MockTime qw/:all/; ##Must be loaded before all other code
|
||||
use WebGUI::Test;
|
||||
use WebGUI::Session;
|
||||
use Test::More tests => 3; # increment this value for each test you create
|
||||
use Test::More tests => 5; # increment this value for each test you create
|
||||
use WebGUI::Asset::Wobject::Layout;
|
||||
use WebGUI::Asset::Template;
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
|
|
@ -64,4 +65,25 @@ set_relative_time(-100);
|
|||
$snip1 = $snip1->addRevision({ title => 'titular', }, 18);
|
||||
is $page->getContentLastModifiedBy, $revised_user1->userId, '... check that a new revision tracks';
|
||||
|
||||
# inheriting mobileStyleTemplateId and mobileTemplateId; from ``Mobile template is not being inherited (#12246)''
|
||||
|
||||
my $importNode = WebGUI::Asset::Template->getImportNode($session);
|
||||
my $template1 = $importNode->addChild({className=>"WebGUI::Asset::Template"});
|
||||
my $template2 = $importNode->addChild({className=>"WebGUI::Asset::Template"});
|
||||
WebGUI::Test->addToCleanup($template1, $template2);
|
||||
|
||||
my $mobileStyleTemplateId = $template1->getId;
|
||||
my $mobileTemplateId = $template2->getId;
|
||||
$page->update({ mobileStyleTemplateId => $mobileStyleTemplateId, mobileTemplateId => $mobileTemplateId });
|
||||
my $url = $page->get('url') . '/layout_child_test';
|
||||
my $html = WebGUI::Test->getPage($page, "www_add", {
|
||||
userId => 3,
|
||||
formParams => {
|
||||
class => 'WebGUI::Asset::Wobject::Layout',
|
||||
url => $page->get('url') . '/layout_child_test',
|
||||
},
|
||||
});
|
||||
|
||||
like $html, qr/name="mobileTemplateId" value="$mobileTemplateId"/, 'child PageLayout inherited parents mobileTempaleId';
|
||||
like $html, qr/name="mobileStyleTemplateId" value="$mobileStyleTemplateId"/, 'child PageLayout inherited parents mobileStyleTempaleId';
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue