How to properly implement IHasParent and IHasContentChildren
Hi all, i'm trying to create a parent child module. From this thread it said i need to implement IHasParent and IHasContentChildren. can anyone help me point out how to implement these two interface? especially the IHasContentChildren. i don't know what to do with ChildContentItems.
also in the fluent mapping class what field should I use as parameter in WithOpposite()? I tried the ChildContentItems but it give me an error can't convert from IEnumerable to a single object
slideItemMapping.HasAssociation(p => p.Parent).WithOpposite(c => c.ChildContentItems).ToColumn(p => p.Id);
Hello Augus,
Bellow are the default implementations for our parent/child modules. The example is with blog posts and blog
BlogPost:
/// <summary>
/// Get or sets the posts blog
/// </summary>
[FieldAlias(
"parent"
)]
[HideField]
[Searchable(
false
)]
[NonSerializableProperty]
public
Blog Parent
get
if
(
this
.parent !=
null
)
((IDataItem)
this
.parent).Provider = ((IDataItem)
this
).Provider;
return
this
.parent;
set
Blog parentBlog = value;
if
(
this
.ParentChanged !=
null
)
this
.ParentChanged(
this
, parentBlog);
this
.parent = parentBlog;
/// <summary>
/// Type of the child content
/// </summary>
Type IHasContentChildren.ChildItemType
get
return
this
.GetChildItemType();
/// <summary>
/// Get child content items
/// </summary>
IEnumerable<Content> IHasContentChildren.ChildContentItems
get
return
this
.GetChildContentItems();
/// <summary>
/// Overridable logic for IHasContentChildren.ChildItemType
/// </summary>
/// <returns>Child content type</returns>
protected
virtual
Type GetChildItemType()
return
typeof
(BlogPost);
/// <summary>
/// Overridable logic for IHasContentChildren.ChildContentItems
/// </summary>
/// <returns>Child content items</returns>
protected
virtual
IEnumerable<Content> GetChildContentItems()
return
this
.BlogPosts;
Hi Georgiev, thanks for the answer.
would you mind telling me more about
this
.ParentChanged(
this
, parentBlog);
return
this
.BlogPosts;
this
.BlogPosts
is a private property? like below?private
IEnumerable<Content> BlogPosts
;
Hi Augus,
These are private variables
private Blog parent;
[Depend]
private ProviderTrackedList<BlogPost> blogPosts;
Best wishes,
Ivan Dimitrov
the Telerik team
Thanks Ivan, thanks for the quick response :)
how about
this
.ParentChanged(
this
, parentBlog);
Hi Augus,
This is a delegate
public delegate void ParentChangeHandler(ChildItem sender, ParentItem parent);
public event ParentChangeHandler ParentChanged;
Kind regards,
Ivan Dimitrov
the Telerik team
Hello,
What fields should be added to parent and child content metadata?
Could you please post example for blog and blogposts? And what additional steps need to be performed in module in order to appropriately register second content item. Right now I have only one content item in my module.
Also that would be really cool if somewhere exist example of module with to parent-child content types?
Thanks, Denis.