From 36eb8db8fce571c21637e19fd44e7c054af44077 Mon Sep 17 00:00:00 2001 From: Chris Nehren Date: Thu, 21 Aug 2008 18:51:16 +0000 Subject: [PATCH] add ability to show metadata values in head blocks. --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Asset.pm | 8 +----- lib/WebGUI/Asset/Event.pm | 2 +- lib/WebGUI/Asset/File.pm | 2 +- lib/WebGUI/Asset/File/GalleryFile.pm | 2 +- lib/WebGUI/Asset/File/Image.pm | 2 +- lib/WebGUI/Asset/File/ZipArchive.pm | 2 +- lib/WebGUI/Asset/Post/Thread.pm | 2 +- lib/WebGUI/Asset/RSSFromParent.pm | 2 +- lib/WebGUI/Asset/Shortcut.pm | 2 +- lib/WebGUI/Asset/Sku/Donation.pm | 2 +- lib/WebGUI/Asset/Sku/FlatDiscount.pm | 2 +- lib/WebGUI/Asset/Sku/Product.pm | 2 +- lib/WebGUI/Asset/Sku/Subscription.pm | 2 +- lib/WebGUI/Asset/Template.pm | 11 +++++--- lib/WebGUI/Asset/Wobject/Article.pm | 2 +- lib/WebGUI/Asset/Wobject/Calendar.pm | 2 +- lib/WebGUI/Asset/Wobject/Collaboration.pm | 2 +- .../Asset/Wobject/EventManagementSystem.pm | 2 +- lib/WebGUI/Asset/Wobject/Folder.pm | 2 +- lib/WebGUI/Asset/Wobject/Gallery.pm | 2 +- lib/WebGUI/Asset/Wobject/GalleryAlbum.pm | 2 +- lib/WebGUI/Asset/Wobject/HttpProxy.pm | 2 +- lib/WebGUI/Asset/Wobject/InOutBoard.pm | 2 +- lib/WebGUI/Asset/Wobject/Matrix.pm | 2 +- lib/WebGUI/Asset/Wobject/MessageBoard.pm | 2 +- lib/WebGUI/Asset/Wobject/MultiSearch.pm | 2 +- lib/WebGUI/Asset/Wobject/Navigation.pm | 2 +- lib/WebGUI/Asset/Wobject/Poll.pm | 2 +- lib/WebGUI/Asset/Wobject/ProjectManager.pm | 2 +- lib/WebGUI/Asset/Wobject/SQLReport.pm | 2 +- lib/WebGUI/Asset/Wobject/Search.pm | 2 +- lib/WebGUI/Asset/Wobject/Shelf.pm | 2 +- lib/WebGUI/Asset/Wobject/StockData.pm | 2 +- lib/WebGUI/Asset/Wobject/Survey.pm | 2 +- lib/WebGUI/Asset/Wobject/SyndicatedContent.pm | 2 +- lib/WebGUI/Asset/Wobject/Thingy.pm | 2 +- lib/WebGUI/Asset/Wobject/TimeTracking.pm | 2 +- lib/WebGUI/Asset/Wobject/UserList.pm | 2 +- lib/WebGUI/Asset/Wobject/WSClient.pm | 2 +- lib/WebGUI/Asset/Wobject/WeatherData.pm | 2 +- lib/WebGUI/AssetMetaData.pm | 22 +++++++++++++++ t/Asset/AssetMetaData.t | 27 ++++++++++++++++++- 43 files changed, 96 insertions(+), 49 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 0e236b486..86689a45d 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -28,6 +28,7 @@ - fixed: Thingy: default thing property hidden (Yung Han Khoe) - fixed: Ad Space Description Text Keeps Repopulating - fixed: Disabled Shipping methods still available + - added: ability to have metadata tags in head blocks 7.5.20 - fixed: DataForm acknowledgement screen shows incorrect value for Date/Time fields diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 21cabd782..aff5de518 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -2044,13 +2044,7 @@ sub processTemplate { $template = WebGUI::Asset->new($self->session, $templateId,"WebGUI::Asset::Template") unless (defined $template); if (defined $template) { - my $meta = {}; - if ($self->session->setting->get("metaDataEnabled")) { - $meta = $self->getMetaDataFields(); - } - foreach my $field (keys %$meta) { - $var->{$meta->{$field}{fieldName}} = $meta->{$field}{value}; - } + $var = { %{ $var }, %{ $self->getMetaDataAsTemplateVariables } }; $var->{'controls'} = $self->getToolbar; my %vars = ( %{$self->{_properties}}, diff --git a/lib/WebGUI/Asset/Event.pm b/lib/WebGUI/Asset/Event.pm index 07dc1c5c9..f25b7a39b 100644 --- a/lib/WebGUI/Asset/Event.pm +++ b/lib/WebGUI/Asset/Event.pm @@ -1435,7 +1435,7 @@ sub prepareView { } my $template = WebGUI::Asset::Template->new($self->session,$templateId); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; } diff --git a/lib/WebGUI/Asset/File.pm b/lib/WebGUI/Asset/File.pm index faa21c226..889b4f7d0 100644 --- a/lib/WebGUI/Asset/File.pm +++ b/lib/WebGUI/Asset/File.pm @@ -314,7 +314,7 @@ sub prepareView { my $self = shift; $self->SUPER::prepareView(); my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId")); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; } diff --git a/lib/WebGUI/Asset/File/GalleryFile.pm b/lib/WebGUI/Asset/File/GalleryFile.pm index 1af64457e..04a2dfaad 100644 --- a/lib/WebGUI/Asset/File/GalleryFile.pm +++ b/lib/WebGUI/Asset/File/GalleryFile.pm @@ -601,7 +601,7 @@ sub prepareView { my $template = WebGUI::Asset::Template->new($self->session, $self->getGallery->get("templateIdViewFile")); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; } diff --git a/lib/WebGUI/Asset/File/Image.pm b/lib/WebGUI/Asset/File/Image.pm index ade792952..d57309348 100644 --- a/lib/WebGUI/Asset/File/Image.pm +++ b/lib/WebGUI/Asset/File/Image.pm @@ -224,7 +224,7 @@ sub prepareView { my $self = shift; $self->SUPER::prepareView(); my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId")); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; } diff --git a/lib/WebGUI/Asset/File/ZipArchive.pm b/lib/WebGUI/Asset/File/ZipArchive.pm index 9237a42f9..a08e7dd4e 100644 --- a/lib/WebGUI/Asset/File/ZipArchive.pm +++ b/lib/WebGUI/Asset/File/ZipArchive.pm @@ -145,7 +145,7 @@ sub prepareView { my $self = shift; $self->SUPER::prepareView(); my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId")); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; } diff --git a/lib/WebGUI/Asset/Post/Thread.pm b/lib/WebGUI/Asset/Post/Thread.pm index e02b09c01..bd16a5095 100644 --- a/lib/WebGUI/Asset/Post/Thread.pm +++ b/lib/WebGUI/Asset/Post/Thread.pm @@ -564,7 +564,7 @@ sub prepareView { my $self = shift; $self->SUPER::prepareView(); my $template = WebGUI::Asset::Template->new($self->session, $self->getParent->get("threadTemplateId")); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; } diff --git a/lib/WebGUI/Asset/RSSFromParent.pm b/lib/WebGUI/Asset/RSSFromParent.pm index 25c5c1bf2..0963c8c91 100644 --- a/lib/WebGUI/Asset/RSSFromParent.pm +++ b/lib/WebGUI/Asset/RSSFromParent.pm @@ -99,7 +99,7 @@ sub www_view { return '' unless $self->getParent->canView; # Go to parent for auth my $parent = $self->getParent; my $template = WebGUI::Asset::Template->new($self->session, $parent->get('rssCapableRssTemplateId')); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->session->http->setMimeType('text/xml'); my $var = {}; diff --git a/lib/WebGUI/Asset/Shortcut.pm b/lib/WebGUI/Asset/Shortcut.pm index 0fa2099f2..7a7ce6b2a 100644 --- a/lib/WebGUI/Asset/Shortcut.pm +++ b/lib/WebGUI/Asset/Shortcut.pm @@ -656,7 +656,7 @@ sub prepareView { my $self = shift; $self->SUPER::prepareView(); my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId")); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; my $shortcut = $self->getShortcut; $shortcut->prepareView if defined $shortcut; diff --git a/lib/WebGUI/Asset/Sku/Donation.pm b/lib/WebGUI/Asset/Sku/Donation.pm index 03fb5c3c9..328744ffb 100644 --- a/lib/WebGUI/Asset/Sku/Donation.pm +++ b/lib/WebGUI/Asset/Sku/Donation.pm @@ -132,7 +132,7 @@ sub prepareView { $self->SUPER::prepareView(); my $templateId = $self->get("templateId"); my $template = WebGUI::Asset::Template->new($self->session, $templateId); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; } diff --git a/lib/WebGUI/Asset/Sku/FlatDiscount.pm b/lib/WebGUI/Asset/Sku/FlatDiscount.pm index 694eccbfd..d49cd2177 100644 --- a/lib/WebGUI/Asset/Sku/FlatDiscount.pm +++ b/lib/WebGUI/Asset/Sku/FlatDiscount.pm @@ -211,7 +211,7 @@ sub prepareView { $self->SUPER::prepareView(); my $templateId = $self->get("templateId"); my $template = WebGUI::Asset::Template->new($self->session, $templateId); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; } diff --git a/lib/WebGUI/Asset/Sku/Product.pm b/lib/WebGUI/Asset/Sku/Product.pm index 63dd0b926..8dad6061f 100644 --- a/lib/WebGUI/Asset/Sku/Product.pm +++ b/lib/WebGUI/Asset/Sku/Product.pm @@ -676,7 +676,7 @@ sub prepareView { my $self = shift; $self->SUPER::prepareView(); my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId")); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; } diff --git a/lib/WebGUI/Asset/Sku/Subscription.pm b/lib/WebGUI/Asset/Sku/Subscription.pm index febd1e662..c51e48a29 100644 --- a/lib/WebGUI/Asset/Sku/Subscription.pm +++ b/lib/WebGUI/Asset/Sku/Subscription.pm @@ -445,7 +445,7 @@ sub prepareView { $self->SUPER::prepareView(); my $templateId = $self->get("templateId"); my $template = WebGUI::Asset::Template->new($self->session, $templateId); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; } diff --git a/lib/WebGUI/Asset/Template.pm b/lib/WebGUI/Asset/Template.pm index 61ccf258e..0d98a4fa1 100644 --- a/lib/WebGUI/Asset/Template.pm +++ b/lib/WebGUI/Asset/Template.pm @@ -284,22 +284,27 @@ sub indexContent { #------------------------------------------------------------------- -=head2 prepare ( ) +=head2 prepare ( headerTemplateVariables ) This method sets the tags from the head block parameter of the template into the HTML head block in the style. You only need to call this method if you're using the HTML streaming features of WebGUI, like is done in the prepareView()/view()/www_view() methods of WebGUI assets. +=head3 headerTemplateVariables + +A hash reference containing template variables to be processed for the head block. Typically obtained via $asset->getMetaDataAsTemplateVariables. + =cut sub prepare { my $self = shift; + my $vars = shift; $self->{_prepared} = 1; my $templateHeadersSent = $self->session->stow->get("templateHeadersSent") || []; my @sent = @{$templateHeadersSent}; unless (isIn($self->getId, @sent)) { # don't send head block if we've already sent it for this template if ($self->session->style->sent) { - $self->session->output->print($self->get("headBlock")); + $self->session->output->print($self->getParser($self->session, $self->get('parser'))->process($self->get('headBlock'), $vars)); } else { - $self->session->style->setRawHeadTags($self->get("headBlock")); + $self->session->style->setRawHeadTags($self->getParser($self->session, $self->get('parser'))->process($self->get('headBlock'), $vars)); } } push(@sent, $self->getId); diff --git a/lib/WebGUI/Asset/Wobject/Article.pm b/lib/WebGUI/Asset/Wobject/Article.pm index f66d564d9..04e0c1996 100644 --- a/lib/WebGUI/Asset/Wobject/Article.pm +++ b/lib/WebGUI/Asset/Wobject/Article.pm @@ -217,7 +217,7 @@ sub prepareView { $templateId = $self->session->form->process("overrideTemplateId"); } my $template = WebGUI::Asset::Template->new($self->session, $templateId); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; } diff --git a/lib/WebGUI/Asset/Wobject/Calendar.pm b/lib/WebGUI/Asset/Wobject/Calendar.pm index 12ec7ccb9..27f2e077a 100644 --- a/lib/WebGUI/Asset/Wobject/Calendar.pm +++ b/lib/WebGUI/Asset/Wobject/Calendar.pm @@ -930,7 +930,7 @@ sub prepareView { #$self->session->errorHandler->warn("Prepare view ".$view." with template ".$self->get("templateId".$view)); my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId".$view)); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; } diff --git a/lib/WebGUI/Asset/Wobject/Collaboration.pm b/lib/WebGUI/Asset/Wobject/Collaboration.pm index 784c4f275..e1260e54f 100644 --- a/lib/WebGUI/Asset/Wobject/Collaboration.pm +++ b/lib/WebGUI/Asset/Wobject/Collaboration.pm @@ -1180,7 +1180,7 @@ sub prepareView { if ($self->get('rssCapableRssEnabled')) { $self->session->style->setLink($self->getRssUrl,{ rel=>'alternate', type=>'application/rss+xml', title=>$self->get('title') . ' RSS' }); } - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; } diff --git a/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm b/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm index 0fbb237cc..532b6ae59 100644 --- a/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm +++ b/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm @@ -334,7 +334,7 @@ sub prepareView { my $self = shift; $self->SUPER::prepareView(); my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId")); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; } diff --git a/lib/WebGUI/Asset/Wobject/Folder.pm b/lib/WebGUI/Asset/Wobject/Folder.pm index 460dc3c65..242707d1b 100644 --- a/lib/WebGUI/Asset/Wobject/Folder.pm +++ b/lib/WebGUI/Asset/Wobject/Folder.pm @@ -136,7 +136,7 @@ sub prepareView { my $self = shift; $self->SUPER::prepareView(); my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId")); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; } diff --git a/lib/WebGUI/Asset/Wobject/Gallery.pm b/lib/WebGUI/Asset/Wobject/Gallery.pm index 271599c0c..c6f63cbf1 100644 --- a/lib/WebGUI/Asset/Wobject/Gallery.pm +++ b/lib/WebGUI/Asset/Wobject/Gallery.pm @@ -961,7 +961,7 @@ sub prepareViewListAlbums { my $self = shift; my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateIdListAlbums")); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; } diff --git a/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm b/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm index 4918f6ebe..ea85f3ab6 100644 --- a/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm +++ b/lib/WebGUI/Asset/Wobject/GalleryAlbum.pm @@ -629,7 +629,7 @@ sub prepareView { my $template = WebGUI::Asset::Template->new($self->session, $templateId); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; } diff --git a/lib/WebGUI/Asset/Wobject/HttpProxy.pm b/lib/WebGUI/Asset/Wobject/HttpProxy.pm index a52a33555..e444412c1 100644 --- a/lib/WebGUI/Asset/Wobject/HttpProxy.pm +++ b/lib/WebGUI/Asset/Wobject/HttpProxy.pm @@ -202,7 +202,7 @@ sub prepareView { my $self = shift; $self->SUPER::prepareView(); my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId")); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; } diff --git a/lib/WebGUI/Asset/Wobject/InOutBoard.pm b/lib/WebGUI/Asset/Wobject/InOutBoard.pm index c85cd3ef6..fffc08f88 100644 --- a/lib/WebGUI/Asset/Wobject/InOutBoard.pm +++ b/lib/WebGUI/Asset/Wobject/InOutBoard.pm @@ -153,7 +153,7 @@ sub prepareView { my $self = shift; $self->SUPER::prepareView(); my $template = WebGUI::Asset::Template->new($self->session, $self->getValue("inOutTemplateId")); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; } diff --git a/lib/WebGUI/Asset/Wobject/Matrix.pm b/lib/WebGUI/Asset/Wobject/Matrix.pm index e298b3e40..6e32bcab8 100644 --- a/lib/WebGUI/Asset/Wobject/Matrix.pm +++ b/lib/WebGUI/Asset/Wobject/Matrix.pm @@ -192,7 +192,7 @@ sub prepareView { my $self = shift; $self->SUPER::prepareView(); my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId")); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; } diff --git a/lib/WebGUI/Asset/Wobject/MessageBoard.pm b/lib/WebGUI/Asset/Wobject/MessageBoard.pm index d26854fe2..0c340ef0a 100644 --- a/lib/WebGUI/Asset/Wobject/MessageBoard.pm +++ b/lib/WebGUI/Asset/Wobject/MessageBoard.pm @@ -70,7 +70,7 @@ sub prepareView { my $self = shift; $self->SUPER::prepareView(); my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId")); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; } diff --git a/lib/WebGUI/Asset/Wobject/MultiSearch.pm b/lib/WebGUI/Asset/Wobject/MultiSearch.pm index 86592a413..b576918a0 100644 --- a/lib/WebGUI/Asset/Wobject/MultiSearch.pm +++ b/lib/WebGUI/Asset/Wobject/MultiSearch.pm @@ -92,7 +92,7 @@ sub prepareView { my $self = shift; $self->SUPER::prepareView(); my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId")); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; } diff --git a/lib/WebGUI/Asset/Wobject/Navigation.pm b/lib/WebGUI/Asset/Wobject/Navigation.pm index e4b82c79d..ea9c1e6d6 100644 --- a/lib/WebGUI/Asset/Wobject/Navigation.pm +++ b/lib/WebGUI/Asset/Wobject/Navigation.pm @@ -348,7 +348,7 @@ sub prepareView { my $self = shift; $self->SUPER::prepareView(); my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId")); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; } diff --git a/lib/WebGUI/Asset/Wobject/Poll.pm b/lib/WebGUI/Asset/Wobject/Poll.pm index 4c35a8fd8..57d170607 100644 --- a/lib/WebGUI/Asset/Wobject/Poll.pm +++ b/lib/WebGUI/Asset/Wobject/Poll.pm @@ -330,7 +330,7 @@ sub prepareView { my $self = shift; $self->SUPER::prepareView(); my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId")); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; } diff --git a/lib/WebGUI/Asset/Wobject/ProjectManager.pm b/lib/WebGUI/Asset/Wobject/ProjectManager.pm index e0d3fdf83..747514e62 100644 --- a/lib/WebGUI/Asset/Wobject/ProjectManager.pm +++ b/lib/WebGUI/Asset/Wobject/ProjectManager.pm @@ -511,7 +511,7 @@ sub prepareView { my $self = shift; $self->SUPER::prepareView(); my $template = WebGUI::Asset::Template->new($self->session, $self->get("projectDashboardTemplateId")); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; } diff --git a/lib/WebGUI/Asset/Wobject/SQLReport.pm b/lib/WebGUI/Asset/Wobject/SQLReport.pm index c2dc9c8fe..2b93aad6c 100644 --- a/lib/WebGUI/Asset/Wobject/SQLReport.pm +++ b/lib/WebGUI/Asset/Wobject/SQLReport.pm @@ -437,7 +437,7 @@ sub prepareView { my $self = shift; $self->SUPER::prepareView(); my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId")); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; } diff --git a/lib/WebGUI/Asset/Wobject/Search.pm b/lib/WebGUI/Asset/Wobject/Search.pm index df4e8056c..231d60912 100644 --- a/lib/WebGUI/Asset/Wobject/Search.pm +++ b/lib/WebGUI/Asset/Wobject/Search.pm @@ -127,7 +127,7 @@ sub prepareView { my $self = shift; $self->SUPER::prepareView(); my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId")); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; } diff --git a/lib/WebGUI/Asset/Wobject/Shelf.pm b/lib/WebGUI/Asset/Wobject/Shelf.pm index 37f5ab20b..3436f62bd 100644 --- a/lib/WebGUI/Asset/Wobject/Shelf.pm +++ b/lib/WebGUI/Asset/Wobject/Shelf.pm @@ -251,7 +251,7 @@ sub prepareView { my $self = shift; $self->SUPER::prepareView(); my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId")); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; } diff --git a/lib/WebGUI/Asset/Wobject/StockData.pm b/lib/WebGUI/Asset/Wobject/StockData.pm index ab3eb5fb0..0cb3fdcf7 100644 --- a/lib/WebGUI/Asset/Wobject/StockData.pm +++ b/lib/WebGUI/Asset/Wobject/StockData.pm @@ -324,7 +324,7 @@ sub prepareView { my $self = shift; $self->SUPER::prepareView(); my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId")); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; } diff --git a/lib/WebGUI/Asset/Wobject/Survey.pm b/lib/WebGUI/Asset/Wobject/Survey.pm index b14bc2626..deb651292 100644 --- a/lib/WebGUI/Asset/Wobject/Survey.pm +++ b/lib/WebGUI/Asset/Wobject/Survey.pm @@ -573,7 +573,7 @@ sub prepareView { my $self = shift; $self->SUPER::prepareView(); my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId")); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; } diff --git a/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm b/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm index 93ce38042..6086bd6ee 100644 --- a/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm +++ b/lib/WebGUI/Asset/Wobject/SyndicatedContent.pm @@ -595,7 +595,7 @@ sub prepareView { my $self = shift; $self->SUPER::prepareView(); my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId")); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; my $i18n = WebGUI::International->new($self->session,'Asset_SyndicatedContent'); my $rssFeedSuffix=$i18n->get('RSS Feed Title Suffix'); diff --git a/lib/WebGUI/Asset/Wobject/Thingy.pm b/lib/WebGUI/Asset/Wobject/Thingy.pm index c54e79a6f..9ec58e2a3 100644 --- a/lib/WebGUI/Asset/Wobject/Thingy.pm +++ b/lib/WebGUI/Asset/Wobject/Thingy.pm @@ -946,7 +946,7 @@ sub prepareView { my $self = shift; $self->SUPER::prepareView(); my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId")); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; return undef; } diff --git a/lib/WebGUI/Asset/Wobject/TimeTracking.pm b/lib/WebGUI/Asset/Wobject/TimeTracking.pm index 95e78573c..85abdc2ec 100644 --- a/lib/WebGUI/Asset/Wobject/TimeTracking.pm +++ b/lib/WebGUI/Asset/Wobject/TimeTracking.pm @@ -91,7 +91,7 @@ sub prepareView { #} else { $template = WebGUI::Asset::Template->new($self->session, $self->get("userViewTemplateId")); #} - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; } diff --git a/lib/WebGUI/Asset/Wobject/UserList.pm b/lib/WebGUI/Asset/Wobject/UserList.pm index 0394ffdf7..911a9efed 100644 --- a/lib/WebGUI/Asset/Wobject/UserList.pm +++ b/lib/WebGUI/Asset/Wobject/UserList.pm @@ -322,7 +322,7 @@ sub prepareView { $templateId = $self->session->form->process("overrideTemplateId"); } my $template = WebGUI::Asset::Template->new($self->session, $templateId); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; return undef; diff --git a/lib/WebGUI/Asset/Wobject/WSClient.pm b/lib/WebGUI/Asset/Wobject/WSClient.pm index 2bacaae4e..8f7fc1879 100644 --- a/lib/WebGUI/Asset/Wobject/WSClient.pm +++ b/lib/WebGUI/Asset/Wobject/WSClient.pm @@ -227,7 +227,7 @@ sub prepareView { my $self = shift; $self->SUPER::prepareView(); my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId")); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; } diff --git a/lib/WebGUI/Asset/Wobject/WeatherData.pm b/lib/WebGUI/Asset/Wobject/WeatherData.pm index ee7a54cbb..663644db5 100644 --- a/lib/WebGUI/Asset/Wobject/WeatherData.pm +++ b/lib/WebGUI/Asset/Wobject/WeatherData.pm @@ -98,7 +98,7 @@ sub prepareView { my $self = shift; $self->SUPER::prepareView(); my $template = WebGUI::Asset::Template->new($self->session, $self->get("templateId")); - $template->prepare; + $template->prepare($self->getMetaDataAsTemplateVariables); $self->{_viewTemplate} = $template; } diff --git a/lib/WebGUI/AssetMetaData.pm b/lib/WebGUI/AssetMetaData.pm index ed3140a22..8ba18a263 100644 --- a/lib/WebGUI/AssetMetaData.pm +++ b/lib/WebGUI/AssetMetaData.pm @@ -115,6 +115,28 @@ sub deleteMetaDataField { } +#------------------------------------------------------------------- + +=head2 getMetaDataAsTemplateVariables + +Returns the metadata as template variables for use in the head block. + +=cut + +sub getMetaDataAsTemplateVariables { + my $self = shift; + my $var = {}; + my $meta = {}; + + if ($self->session->setting->get("metaDataEnabled")) { + $meta = $self->getMetaDataFields(); + } + foreach my $field (keys %$meta) { + $var->{$meta->{$field}{fieldName}} = $meta->{$field}{value}; + } + return $var; +} + #------------------------------------------------------------------- =head2 getMetaDataFields ( [fieldId] ) diff --git a/t/Asset/AssetMetaData.t b/t/Asset/AssetMetaData.t index 7c4e5b687..b263d9ad1 100644 --- a/t/Asset/AssetMetaData.t +++ b/t/Asset/AssetMetaData.t @@ -23,7 +23,7 @@ use WebGUI::VersionTag; use Test::More; # increment this value for each test you create use Test::Deep; -plan tests => 12; +plan tests => 13; my $session = WebGUI::Test->session; $session->user({userId => 3}); @@ -189,6 +189,31 @@ cmp_deeply( 'Snippet does not have a value, yet' ); +#################################################### +# +# getMetaDataAsTemplateVariables +# +#################################################### + +# add another field for comparison +$folder->addMetaDataField('new', 'book', '', 'Favorite book', 'radioList', "1984\nDune\nLord of the Rings\nFoundation Trilogy"); + +# set it; need to update $foMetaData and $byName. +$foMetaData = $folder->getMetaDataFields; +$byName = buildNameIndex($foMetaData); +$folder->updateMetaData( $byName->{'book'}, '1984' ); + +# check that they're equal +cmp_deeply( + $folder->getMetaDataAsTemplateVariables, + { + 'book' => '1984', + 'sport' => 'underwaterHockey', + 'searchEngine' => undef, + }, + 'getMetaDataAsTemplateVariables returns proper values for folder' +); + sub buildNameIndex { my ($fidStruct) = @_; my $nameStruct;