+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / How to properly implement IHasParent and IHasContentChildren

How to properly implement IHasParent and IHasContentChildren

7 posts, 1 answered
  1. Augus
    Augus avatar
    34 posts
    Registered:
    29 Mar 2011
    12 May 2011
    Link to this post
    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
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    16 May 2011
    Link to this post
    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
    Answered
  3. Augus
    Augus avatar
    34 posts
    Registered:
    29 Mar 2011
    19 May 2011
    Link to this post
    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
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    19 May 2011
    Link to this post
    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
  5. Augus
    Augus avatar
    34 posts
    Registered:
    29 Mar 2011
    19 May 2011
    Link to this post
    Thanks Ivan, thanks for  the quick response :)

    how about
    this.ParentChanged(this, parentBlog);

    what this function do? can i safely skip it?
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    19 May 2011
    Link to this post
    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
  7. Denis
    Denis avatar
    105 posts
    Registered:
    27 Feb 2009
    27 Feb 2013
    Link to this post

    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.

7 posts, 1 answered