How to properly implement IHasParent and IHasContentChildren

Posted by Community Admin on 03-Aug-2018 09:00

How to properly implement IHasParent and IHasContentChildren

All Replies

Posted by Community Admin on 12-May-2011 00:00

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

thanks in advance,

Augus

Posted by Community Admin on 16-May-2011 00:00

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;
    

Blog:
/// <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;

You should substitute the BlogPost and Blog types with your child/parent types.

Greetings,
Radoslav Georgiev
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 19-May-2011 00:00

Hi Georgiev, thanks for the answer.
would you mind telling me more about

this.ParentChanged(this, parentBlog);

and

return this.BlogPosts;

i assume this.BlogPosts is a private property? like below?

private IEnumerable<Content> BlogPosts;

please correct me if i'm wrong.

Thank you

Augus

Posted by Community Admin on 19-May-2011 00:00

Hi Augus,

These are private variables

private Blog parent;

[Depend]
private ProviderTrackedList<BlogPost> blogPosts;

Best wishes,
Ivan Dimitrov
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 19-May-2011 00:00

Thanks Ivan, thanks for  the quick response :)

how about

this.ParentChanged(this, parentBlog);

what this function do? can i safely skip it?

Posted by Community Admin on 19-May-2011 00:00

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

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 27-Feb-2013 00:00

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.

This thread is closed