具有多选功能的 Sitecore 自定义字段树视图
Sitecore custom field treeview with multiselect
我创建了自定义树视图字段 - 多选树视图。
此字段继承自 Sitecore.Shell.Applications.ContentEditor.TreeList,使用重写方法 Add():
public class MultiselectTreeList : TreeList
{
protected new virtual void Add()
{
bool alert = true;
if (this.Disabled) return;
string viewStateString = this.GetViewStateString("ID");
var treeviewEx = this.FindControl(viewStateString + "_all") as TreeviewEx;
Assert.IsNotNull(treeviewEx, typeof (DataTreeview));
var listbox = this.FindControl(viewStateString + "_selected") as Listbox;
Assert.IsNotNull(listbox, typeof (Listbox));
if (treeviewEx == null)
{
SheerResponse.Alert("TreeviewEx control not found..", new string[0]);
}
else
{
Item[] selectionItems = treeviewEx.GetSelectedItems();
if (selectionItems == null)
{
SheerResponse.Alert("Select an item in the Content Tree.", new string[0]);
}
else
{
foreach (Item selectionItem in selectionItems)
{
if (this.HasExcludeTemplateForSelection(selectionItem)) return;
if (this.IsDeniedMultipleSelection(selectionItem, listbox))
{
if (alert)
{
SheerResponse.Alert("You cannot select the same item twice.", new string[0]);
alert = false;
}
}
else
{
if (!this.HasIncludeTemplateForSelection(selectionItem)) return;
SheerResponse.Eval("scForm.browser.getControl('" + viewStateString +
"_selected').selectedIndex=-1");
var listItem = new ListItem {ID = GetUniqueID("L")};
Sitecore.Context.ClientPage.AddControl(listbox, listItem);
listItem.Header = this.GetHeaderValue(selectionItem);
listItem.Value = listItem.ID + (object) "|" + selectionItem.ID;
SheerResponse.Refresh(listbox);
SetModified();
}
}
}
}
}
}
我已经在核心数据库中注册了它:/sitecore/system/Field types/Custom Types/Multiselect 树列表:已填充程序集和 Class 字段。
添加了带有多选树列表字段的项目。填充的数据。多项选择正常。
但是当我尝试使用 Ribbon->Navigate->Links 查找引用时,我没有看到对项目的引用(也错过了 master 数据库中链接 table 中的 TargetItemId)。
当我将其更改为 Sitecore Treeview 字段时 - 一切正常。
据我了解,爬虫不会为我的字段编制索引,也不会将链接添加到数据库中。
有什么解决办法吗?
在 App_Config\FieldTypes.config 中注册您的字段类型。完成后,以后对该字段的写入将包含在 LinkDatabase 中。
也尝试将其添加到索引配置中:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:x="http://www.sitecore.net/xmlconfig/">
<sitecore>
<fieldTypes>
<fieldType name="Multiselect Treelist" type="Sitecore.Data.Fields.MultilistField,Sitecore.Kernel" />
</fieldTypes>
<contentSearch>
<indexConfigurations>
<defaultLuceneIndexConfiguration>
<fieldMap type="Sitecore.ContentSearch.FieldMap, Sitecore.ContentSearch">
<fieldTypes hint="raw:AddFieldByFieldTypeName">
<fieldType fieldTypeName="multiselect treelist" storageType="NO" indexType="TOKENIZED" vectorType="NO" boost="1f" type="System.String" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider" />
</fieldTypes>
</fieldMap>
<fieldReaders type="Sitecore.ContentSearch.FieldReaders.FieldReaderMap, Sitecore.ContentSearch">
<mapFieldByTypeName>
<fieldReader fieldTypeName="multiselect treelist" fieldNameFormat="{0}" fieldReaderType="Sitecore.ContentSearch.FieldReaders.MultiListFieldReader, Sitecore.ContentSearch" />
</mapFieldByTypeName>
</fieldReaders>
</defaultLuceneIndexConfiguration>
</indexConfigurations>
</contentSearch>
</sitecore>
</configuration>
我创建了自定义树视图字段 - 多选树视图。
此字段继承自 Sitecore.Shell.Applications.ContentEditor.TreeList,使用重写方法 Add():
public class MultiselectTreeList : TreeList
{
protected new virtual void Add()
{
bool alert = true;
if (this.Disabled) return;
string viewStateString = this.GetViewStateString("ID");
var treeviewEx = this.FindControl(viewStateString + "_all") as TreeviewEx;
Assert.IsNotNull(treeviewEx, typeof (DataTreeview));
var listbox = this.FindControl(viewStateString + "_selected") as Listbox;
Assert.IsNotNull(listbox, typeof (Listbox));
if (treeviewEx == null)
{
SheerResponse.Alert("TreeviewEx control not found..", new string[0]);
}
else
{
Item[] selectionItems = treeviewEx.GetSelectedItems();
if (selectionItems == null)
{
SheerResponse.Alert("Select an item in the Content Tree.", new string[0]);
}
else
{
foreach (Item selectionItem in selectionItems)
{
if (this.HasExcludeTemplateForSelection(selectionItem)) return;
if (this.IsDeniedMultipleSelection(selectionItem, listbox))
{
if (alert)
{
SheerResponse.Alert("You cannot select the same item twice.", new string[0]);
alert = false;
}
}
else
{
if (!this.HasIncludeTemplateForSelection(selectionItem)) return;
SheerResponse.Eval("scForm.browser.getControl('" + viewStateString +
"_selected').selectedIndex=-1");
var listItem = new ListItem {ID = GetUniqueID("L")};
Sitecore.Context.ClientPage.AddControl(listbox, listItem);
listItem.Header = this.GetHeaderValue(selectionItem);
listItem.Value = listItem.ID + (object) "|" + selectionItem.ID;
SheerResponse.Refresh(listbox);
SetModified();
}
}
}
}
}
}
我已经在核心数据库中注册了它:/sitecore/system/Field types/Custom Types/Multiselect 树列表:已填充程序集和 Class 字段。
添加了带有多选树列表字段的项目。填充的数据。多项选择正常。
但是当我尝试使用 Ribbon->Navigate->Links 查找引用时,我没有看到对项目的引用(也错过了 master 数据库中链接 table 中的 TargetItemId)。
当我将其更改为 Sitecore Treeview 字段时 - 一切正常。
据我了解,爬虫不会为我的字段编制索引,也不会将链接添加到数据库中。
有什么解决办法吗?
在 App_Config\FieldTypes.config 中注册您的字段类型。完成后,以后对该字段的写入将包含在 LinkDatabase 中。
也尝试将其添加到索引配置中:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:x="http://www.sitecore.net/xmlconfig/">
<sitecore>
<fieldTypes>
<fieldType name="Multiselect Treelist" type="Sitecore.Data.Fields.MultilistField,Sitecore.Kernel" />
</fieldTypes>
<contentSearch>
<indexConfigurations>
<defaultLuceneIndexConfiguration>
<fieldMap type="Sitecore.ContentSearch.FieldMap, Sitecore.ContentSearch">
<fieldTypes hint="raw:AddFieldByFieldTypeName">
<fieldType fieldTypeName="multiselect treelist" storageType="NO" indexType="TOKENIZED" vectorType="NO" boost="1f" type="System.String" settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider" />
</fieldTypes>
</fieldMap>
<fieldReaders type="Sitecore.ContentSearch.FieldReaders.FieldReaderMap, Sitecore.ContentSearch">
<mapFieldByTypeName>
<fieldReader fieldTypeName="multiselect treelist" fieldNameFormat="{0}" fieldReaderType="Sitecore.ContentSearch.FieldReaders.MultiListFieldReader, Sitecore.ContentSearch" />
</mapFieldByTypeName>
</fieldReaders>
</defaultLuceneIndexConfiguration>
</indexConfigurations>
</contentSearch>
</sitecore>
</configuration>