Like I said in an earlier post, I just make a field in my webpart called "widgetcontent" and use the HtmlEditor. Then, to get it to save that field's data as page content, I had to edit the file stored in /CMSModules/Widgets/Controls/WidgetProperties.ascx.cs and change the SaveFormToWidget method like this
/// <summary>
/// Saves the given DataRow data to the web part properties.
/// </summary>
/// <param name="form">Form to save</param>
private void SaveFormToWidget(BasicForm form)
{
if (form.Visible && (widgetInstance != null))
{
// Keep the old ID to check the change of the ID
string oldId = widgetInstance.ControlID.ToLower();
DataRow dr = form.DataRow;
// Load default values for new widget
if (IsNewWidget)
{
form.FormInformation.LoadDefaultValues(dr, wi.WidgetDefaultValues);
}
foreach (DataColumn column in dr.Table.Columns)
{
//ADD THIS CODE HERE TO STORE THE WIDGET CONTENT INTO PAGE DATA
if (column.ColumnName.Equals("widgetcontent", StringComparison.InvariantCultureIgnoreCase))
{
try
{
string str2 = widgetInstance.ControlID.ToLower();
if (widgetInstance.InstanceGUID != Guid.Empty)
{
str2 = str2 + ";" + this.InstanceGUID.ToString().ToLower();
}
TreeNode node = DocumentHelper.GetDocument(pi.DocumentId, tree);
// Move the content in the page info
pi.EditableWebParts[str2] = dr[column];
// Update the document
node.SetValue("DocumentContent", pi.GetContentXml());
DocumentHelper.UpdateDocument(node, tree);
}
catch (Exception ex)
{
}
}
else
{
widgetInstance.MacroTable[column.ColumnName.ToLower()] = form.MacroTable[column.ColumnName.ToLower()];
widgetInstance.SetValue(column.ColumnName, dr[column]);
}
// If name changed, move the content
if (String.Compare(column.ColumnName, "widgetcontrolid", true) == 0)
{
try
{
string newId = ValidationHelper.GetString(dr[column], "").ToLower();
// Name changed
if (!String.IsNullOrEmpty(newId) && (String.Compare(newId, oldId, false) != 0))
{
mWidgetIdChanged = true;
WidgetId = newId;
// Move the document content if present
string currentContent = (string)(pi.EditableWebParts[oldId]);
if (currentContent != null)
{
TreeNode node = DocumentHelper.GetDocument(pi.DocumentId, tree);
// Move the content in the page info
pi.EditableWebParts[oldId] = null;
pi.EditableWebParts[newId] = currentContent;
// Update the document
node.SetValue("DocumentContent", pi.GetContentXml());
DocumentHelper.UpdateDocument(node, tree);
}
// Change the underlying zone names if layout web part
if ((wpi != null) && ((WebPartTypeEnum)wpi.WebPartType == WebPartTypeEnum.Layout))
{
string prefix = oldId + "_";
foreach (WebPartZoneInstance zone in pti.WebPartZones)
{
if (zone.ZoneID.StartsWith(prefix, StringComparison.InvariantCultureIgnoreCase))
{
// Change the zone prefix to the new one
zone.ZoneID = String.Format("{0}_{1}", newId, zone.ZoneID.Substring(prefix.Length));
}
}
}
}
}
catch (Exception ex)
{
EventLogProvider ev = new EventLogProvider();
ev.LogEvent("Content", "CHANGEWIDGET", ex);
}
}
}
}
}
And then also edit some code in the OnInit method right under where LoadDataRowFromWidget(dr); is called
// Load values from existing widget
LoadDataRowFromWidget(dr);
foreach (DataColumn dc in dr.Table.Columns)
{
if (dc.ColumnName.Equals("widgetcontent", StringComparison.InvariantCultureIgnoreCase))
{
try
{
string str2 = widgetInstance.ControlID.ToLower();
if (widgetInstance.InstanceGUID != Guid.Empty)
{
str2 = str2 + ";" + this.InstanceGUID.ToString().ToLower();
}
TreeNode node = DocumentHelper.GetDocument(pi.DocumentId, tree);
// Move the content in the page info
DataHelper.SetDataRowValue(dr, dc.ColumnName, pi.EditableWebParts[str2]);
}
catch (Exception ex)
{
}
}
}
This will work with any webpart where you want the data to be stored in PageData so that it is indexed in the search engine and you can have the html editor on the page as well as in the edit dialog if you use the Editable Text webpart as a base.