Code reference for creating child items doesn't seem rig

Posted by Community Admin on 05-Aug-2018 14:30

Code reference for creating child items doesn't seem right

All Replies

Posted by Community Admin on 11-Aug-2017 00:00

I'm looking at the Code reference Sitefinity provides when you create a Dynamic Module with the Module Builder. 

When I look at the "Create a your content type Entry" something doesn't seem right. 

The following code is how you supposedly get the parent item ID: 

// Gets the id of the first item of the parent type
private Guid GetParentId(DynamicModuleManager dynamicModuleManager, Type parentType)
    DynamicContent parent = dynamicModuleManager.GetDataItems(parentType)
        .Where(i=>i.Status == ContentLifecycleStatus.Master).First();
    return parent.Id;

What doesn't make sense about this code is that at no point do you actually define 'which' parent you want. It's like it's grabbing the first parent item that has a Status of master, but that could be anyone. 

The code comment confirms this but surely the documentation around this, or at the very least a comment could suggest that you should get a specific parent item. 

Posted by Community Admin on 15-Aug-2017 00:00

Kriek kriek, kriek kriek. 

This thread is closed