Hi,
You will need to use
custom event handler to handle document events in
tree node handler. You will check the document type of the currently created document (e.g. OnBeforeInsert event) and create it under existing month or create new month document first. Below is a code sample fro handling cms.blogpost document type, so you can tak inspiration:
// Special treatment for blog post (ensure parent month)
if (newdocument && (ci != null) && (ci.ClassName.ToLower() == "cms.blogpost"))
{
// Get parent node
node = tree.SelectSingleNode(nodeId, TreeProvider.ALL_CULTURES);
if (node != null)
{
// Get parent blog ID when inserting post under blog month
if (node.NodeClassName.ToLower() == "cms.blogmonth")
{
node = tree.SelectSingleNode(node.NodeParentID, TreeProvider.ALL_CULTURES);
if (node != null)
{
parentId = node.NodeID;
}
}
// Get parent blog ID when inserting post under blog
else
{
parentId = nodeId;
}
if (node != null)
{
CultureInfo cultureInfo = new CultureInfo(CMSContext.PreferredCultureCode);
// Prepare the data
DateTime startDate = ValidationHelper.GetDateTime(formElem.BasicForm.GetFieldValue("BlogPostDate"), DateTimePicker.NOT_SELECTED);
string monthName = startDate.ToString("MMMM", cultureInfo.DateTimeFormat) + " " + startDate.Year;
// UpperCase first letter
monthName = monthName.Substring(0, 1).ToUpper() + monthName.Substring(1);
startDate = new DateTime(startDate.Year, startDate.Month, 1);
// Check existing
DataSet existingDS = tree.SelectNodes(CMSContext.CurrentSiteName, node.NodeAliasPath + "/%", TreeProvider.ALL_CULTURES, true, "cms.blogmonth", "BlogMonthStartingDate = '" + TableManager.GetDateTimeString(startDate) + "'", null, -1, false);
if (DataHelper.DataSourceIsEmpty(existingDS))
{
// Create the month node
node = new TreeNode("CMS.BlogMonth", tree);
node.DocumentCulture = CMSContext.PreferredCultureCode;
// Insert the month
node.SetValue("BlogMonthName", monthName);
node.SetValue("BlogMonthStartingDate", startDate);
node.DocumentName = monthName;
DocumentHelper.InsertDocument(node, parentId, tree);
formElem.NodeId = node.NodeID;
}
else
{
// Set existing
formElem.NodeId = ValidationHelper.GetInteger(existingDS.Tables[0].Rows[0]["NodeID"], 0);
}
}
}
}
Or, you can also add similar code to \CMSModules\Content\CMSDesk\Edit\Edit.aspx.cs file (but there is a risk that it will be overwritten by future upgrade).
Best regards,
Juraj Ondrus