The following section describes what you need to know when using related content in your modules or pages.
When you create a Related data custom field, the system creates a corresponding meta field. Meta fields in Sitefinity CMS are stored in the [sf_meta_fields] table. The meta field has a property AllowMultipleRelations, which defines whether the field allows multiple items to be related. Meta fields for Related data custom fields are created with the following meta attributes:
Related data field controls and widgets
Related data custom fields use separate controls to display relations in the backend and the frontend. By default, the RelatedDataField control is used to display and edit related data in the backend. The control is located in Telerik.Sitefinity.Web.UI.Fields namespace.
Depending on the type of the relation, different frontend widgets are used. For example, if you have created a relation to a News content, the News widget is one of the options for displaying the relation in the frontend. Another option is to use the default Simple link widget, which is only a simple repeater for the items.
Following is the code for the generated custom field template:
The property descriptor for related data fields is called RelatedDataPropertyDescriptor. The GetValue method of the property descriptor returns the actual related items (not the content links). The property descriptor also applies filter for the status of the related items, which depends on the status of the parent item. This means that, if the parent item’s status is Master, only
Master related items are returned. If the request is made from a widget in the frontend, only live and visible items are returned.
When you create a relation to an item, the system creates a content link that is made available for the current state of the parent item. The content link represents the relation and contains information about both the parent item (ParentItemType, ParentItemProviderName, ParentItemId, ParentItemAdditionalInfo) and the child item (ChildItemType, ChildItemProviderName, ChildItemId, ChildItemAdditionalInfo) of the relation.
You can order item relations created via content links directly from the user interface. The specified order of the related items is saved in the ordinal property of the created content links.
The name of the Related data field is used to specify the ComponentPropertyName of the content links that are displayed in the RelatedDataField. As a result, many relations can be added to different content types via different fields.
Content links have three properties:
You can order related items from the user interface using drag-and-drop of the RelatedDataField. Updated ordinals are saved to the ordinal property of the created content link.
If there are no other filters applied, related items are displayed on the frontend in the same order as they are displayed in the backend.
The parent is defined as the item that contains the RelatedData field and the child is the item that is being related to the parent item. For example, if you add a custom RelatedDataField to a Sessions content type and set its Data type to be Locations, when you create a new session, you will have the option to select related locations. In this case, the session item will be the parent and the location – the child.
In the backend, you can see the child items displayed via the RelatedDataField control in the details view of the parent item. Parent items, on the other hand, are displayed in the details view of the child item on the right, under the link Items linking to this item.
In the frontend, related items are displayed by adding the related data field to the widget template of the parent item. For dynamic parent items, this happens, by default, when the widget templates are regenerated. For static parent items, such as News or Events, you need to manually insert the automatically generated field template to the parent widget template.
If item relations are created through the user interface, content links are marked as available for the Temp state. When the parent item is saved as draft or published, the content links’ availability statuses change from Temp to Master and finally to Live. This ensures that different related items can be supported for different parent item’s statuses.
If item relations are created through the Related data API (defined in the RelatedDataExtensions class), the status of the content link is set to the status of the parent item. In this case, you have to ensure the transition to statuses other than this.
Back To Top