ContentLink Content Type

From Sense/Net Wiki
Jump to: navigation, search
  •  
  •  
  •  
  •  
  • 100%
  • 6.0
  • Enterprise
  • Community
  • Planned

Overview

The ContentLink is a special Content Type that acts as a link to another content, just like a symbolic link in file systems.

Details

If you want to create a symbolic link to a specific content in the Content Repository, you can use the Content Link type. A Content Link contains one single important field: the Link, that is a Reference to a repository content.

Linked content fields

A Content Link will return all fields of the linked content as if they were the fields of the Content Link content itself. So for example if the Content Link links to a document, then the document's binary field will be accessible from the Content Link itself. If the Content Link links to a user then the user's full name and password (and all other fields will be accessbile on the link itself.

The fields of the linked content will always appear as read-only on the UI via the content link.

There are a number of fields however that will always come from the Content Link instance and not the linked content. By default, these are the following:

"Id", "ParentId", "VersionId", "Name", "Path", "Index", "InTree", "InFolder", "Depth", "Type", "TypeIs", "Version"

To customize this list you could create a custom type inheriting from the Content Link with a custom Content Handler that overrides this list. See the #Examples/Tutorials section.

Parent type

Content handler

  • SenseNet.ContentRepository.ContentLink

Example/Tutorials

The following example shows how to create a custom content link implementation that will allow the DisplayName of the content link to be defined independent of the DisplayName of the linked content. The first thing is to create a custom content handler that overrides the NotLinkedFields list of the base type and returns with a list that also includes the DisplayName besides the default fields:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SenseNet.ContentRepository;
using SenseNet.ContentRepository.Schema;
using SenseNet.ContentRepository.Storage;
 
namespace MyNamespace
{
    [ContentHandler]
    public class MyContentLink : ContentLink
    {
        public MyContentLink(Node parent) : this(parent, "MyContentLink") { }
        public MyContentLink(Node parent, string nodeTypeName) : base(parent, nodeTypeName) { }
        protected MyContentLink(NodeToken nt) : base(nt) { }
 
        public override List<string> NotLinkedFields
        {
            get
            {
                var list = new List<string>(base.NotLinkedFields);
                list.Add("DisplayName");
                return list;
            }
        }
    }
}

Then we can define the CTD for our new type:

<ContentType name="MyContentLink" parentType="ContentLink" handler="MyNamespace.MyContentLink" xmlns="http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition">
  <DisplayName>MyContentLink</DisplayName>
  <Description>My Content Link type</Description>
  <Icon>Folder</Icon>
  <Fields>
    <Field name="DisplayName" type="ShortText">
      <Configuration>
        <VisibleNew>Show</VisibleNew>
        <VisibleEdit>Show</VisibleEdit>
        <VisibleBrowse>Show</VisibleBrowse>
      </Configuration>
    </Field>
  </Fields>
</ContentType>

This way whenever you create a MyContentLink, the DisplayName of the content link instance will be displayed and you also will be able to customize it.

Related links

References

There are no external references for this article.