From 262826338472760814c8ba056ecc9fd6fe8d8846 Mon Sep 17 00:00:00 2001 From: Scott Walters Date: Wed, 7 Sep 2011 15:43:23 -0400 Subject: [PATCH] Mobile template is not being inherited (#12246) added extra_www_add_properties method to Asset.pm and subclassed it in as Layout.pm as properties fix-up hook in child for www_add --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Asset.pm | 19 +++++++++++++++++++ lib/WebGUI/Asset/Wobject/Layout.pm | 19 +++++++++++++++++++ t/Asset/Wobject/Layout.t | 24 +++++++++++++++++++++++- 4 files changed, 62 insertions(+), 1 deletion(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 642a0876c..0045678bf 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -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: added extra_www_add_properties as properties fix-up hook in child for www_add 7.10.22 - rfe #12223: Add date type to content profiling (metadata) diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index c669e2441..3d2a69c22 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -2927,6 +2927,7 @@ sub www_add { url=>scalar($self->session->form->param("url")), ); $properties{isHidden} = 1 unless $self->session->config->get("assets/".$class."/isContainer"); + $class->extra_www_add_properties($self->session, $self, \%properties ); my $newAsset = WebGUI::Asset->newByPropertyHashRef($self->session,\%properties); $newAsset->{_parent} = $self; return $newAsset->www_edit(); @@ -2934,6 +2935,24 @@ sub www_add { #------------------------------------------------------------------- +=head2 extra_www_add_properties ( $session, $parentAsset, \%properties ) + +Called from C by the parent asset on the class of the new asset being constructed. +The asset class has the chance to modify or augment C<$properties> before the new asset +is presented for edit. +This base version does nothing. It should be overridden as needed. + +=cut + +sub extra_www_add_properties { + my $self = shift; + my $session = shift; + my $parentAsset = shift; + my $properties = shift; +} + +#------------------------------------------------------------------- + =head2 www_ajaxInlineView ( ) Returns the view() method of the asset object if the requestor canView. diff --git a/lib/WebGUI/Asset/Wobject/Layout.pm b/lib/WebGUI/Asset/Wobject/Layout.pm index fdcd62e1a..e4cd45d9a 100644 --- a/lib/WebGUI/Asset/Wobject/Layout.pm +++ b/lib/WebGUI/Asset/Wobject/Layout.pm @@ -514,5 +514,24 @@ sub www_view { return $self->SUPER::www_view; } +#------------------------------------------------------------------- + +=head2 extra_www_add_properties () + +Inherit C and C from the parent asset if it is an instance of +L. + +=cut + +sub extra_www_add_properties { + my $self = shift; + my $session = shift; + my $parentAsset = shift; + my $properties = shift; + return unless $parentAsset->isa('WebGUI::Asset::Wobject::Layout'); + $properties->{ mobileStyleTemplateId } = $parentAsset->get("mobileStyleTemplateId"); + $properties->{ mobileTemplateId } = $parentAsset->get("mobileTemplateId"); +} + 1; diff --git a/t/Asset/Wobject/Layout.t b/t/Asset/Wobject/Layout.t index c69cb794b..7e0a72c40 100644 --- a/t/Asset/Wobject/Layout.t +++ b/t/Asset/Wobject/Layout.t @@ -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';