With the advent of the WebGUI asset
system all wobjects and templates, among other things, are now
assets. This change could present a problem for developers. What if
the new wobject or template we created doesn't really have an obvious
place to be attached in the asset tree? Most developers would attach
it to the root. Since we don't know what anybody's site looks like
that may use our wobject or template, this could clutter up the root
very quickly and cause a potential slow down of the asset tree.
Because of this issue, the Import Node was created. The import node
gives us a place to attach new templates and wobjects we create
without them directly being children of the root. As the import node
itself is a child of the root all new assets we add in this way will
be children of the import node instead. Because the import node is
hidden from navigation and marked, system, we shouldn't have to
worry about it showing up in different navigations or slowing down
the asset tree.
For an example of how to to use the import node, we'll assume we are adding a new template. We enter the following code:
my
$importNode = WebGUI::Asset->getImportNode;
$importNode->addChild((
className=>"webGUI::Asset::Template",
template=>$template,
....
),
$assetId);
We need to make special note of the
$assetId variable at the end.
WebGUI will generate a default asset id for us when we call
addChild(). This second
paramater allows us to specify an asset id. This is most important,
because when we import our new asset, we probably want to give it the
same asset id on all systems. That way if we ever need to upgrade
the new asset, we have an easy way of doing it because we know the
id.
When specifying and asset id, it is
recommended that they don't look like regular WebGUI id's. Make sure
it is 22 characters, but we should use something like this:
YourNameTMPL0000000001
Using that format makes the asset id
easily recognizable as one that was not generated, and it is unlikely
it will conflict with anything else in the system.
We also highly recommend putting all of your inserted assets into a folder of your own creation. Something like this:
my $importNode = WebGUI::Asset->getImportNode($session);
my $folder = $importNode->addChild({
className=>"WebGUI::Asset::Wobject::Folder",
.....
});
my $asset = $folder->addChild({
.....
});
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->commit;
Big Bad
Some developers would like to be tricky and attach content to a
folder they think will exist in all sites. For instance, on most sites
there's a "Templates" folder under the import node that got created by
the upgrade process. So they might wish to include their templates into
that folder. How they'd do this is to get the folder by URL like this:
$folder = WebGUI::Asset->newByUrl("templates");
The
problem with this is that there's nothing guaranteeing the existence of
such a folder. An end user could rename it or even delete it completely
because there's nothing special about the folder what-so-ever.
The
import node on the other hand is protected by WebGUI. It cannot be
deleted by the end user, and it doesn't matter if the end user renames
it, because the getImportNode method will always be able to find it
regardless.