Site structure
Version 5.x > Site structure > CMS Desk Icon - Switch Programmatically Based on Field View modes: 
User avatar
Certified Developer 11
Certified Developer 11
lee-craftedmedia - 1/10/2011 7:50:31 AM
   
CMS Desk Icon - Switch Programmatically Based on Field
I know that you can provide a custom icon in app_themes per document type but is it possible to programmatically switch the icon shown in CMS Desk based on a field value?

For example, I have one document type that has a 'type' field that is a dropdown list with values "article", "case study", "news" etc. I would like the icon shown to be dependant on the value from this field.

I know I could create multiple document types but as you can't inherit document types it seems a shame when the document types are identical except for this 'type' value.

Thanks

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 1/11/2011 8:26:52 AM
   
RE:CMS Desk Icon - Switch Programmatically Based on Field
Hi,

you could modify file: ~/CMSModules/Content/Controls/ContentTree.ascx.cs its CreateNode method. You could change "else" part of following code:


if (UseCMSFileIcons && (className == "cms.file"))
{
string extension = ValidationHelper.GetString(container.GetValue("DocumentType"), "");
imageUrl = GetFileIconUrl(extension, CMSFileIconSet);
tooltip = " title=\"" + extension.ToLower().TrimStart('.') + "\" ";
}
// Use class icons
else
{
imageUrl = ResolveUrl(GetDocumentTypeIconUrl(className));

}



and add condition for your document type (in this example is used cms.blog document type):


if (className == "cms.blog")
{

// Tree node
CMS.TreeEngine.TreeNode node = null;

// Tree provider
CMS.SiteProvider.UserInfo ui = CMS.SiteProvider.UserInfoProvider.GetUserInfo("administrator");
CMS.TreeEngine.TreeProvider tree = new CMS.TreeEngine.TreeProvider(ui);
// Get Single node specified by it`s ID

node = tree.SelectSingleNode(sourceNodeId);
string decide = ValidationHelper.GetString(node.GetValue("BlogTeaser"), "");

if (decide.Equals("some value"))
{
imageUrl = "/url/image.jpg";
}
else
{
imageUrl = "/url/image2.jpg";
}
}


Alternatively, you could decide for cloning your document type to avoid above customization.

Best regards,
Ivana Tomanickova

User avatar
Certified Developer 11
Certified Developer 11
lee-craftedmedia - 1/11/2011 8:32:25 AM
   
RE:CMS Desk Icon - Switch Programmatically Based on Field
thank you exactly what I was after