1
votes

I've created custom treeview field - multiselect treeview.

This field inherited from Sitecore.Shell.Applications.ContentEditor.TreeList with overridden method 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();
                        }
                    }
                }
            }
        }
}

I've registered it in core database: /sitecore/system/Field types/Custom Types/Multiselect Tree List: filled Assembly and Class fields.

Added item with multiselect treelist field. Filled data. Multiple selection works OK.

But when I try to find References using Ribbon->Navigate->Links I don't see references to items (also missed TargetItemId in Links table in master Database).

When I changed it to Sitecore Treeview field - everything works fine.

As far as I understood crawler don't index my field and links not added to database.

Any ideas how to fix this?

2

2 Answers

3
votes

Register your field type in App_Config\FieldTypes.config. Once done, future writes to the field will be included in the LinkDatabase.

0
votes

Try also adding it to the index configuration:

<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>