Turning on listview by level?
d
I'm finding myself in a situation that I need to enable listview by level in the content tree. I have a package installed that creates content nodes and it so happens that the root node is the same type as some of the child nodes. These child nodes will have several 100s of children themselves, so they need to support listview Changing the node type of the root breaks the package unfortunately, so I need to conditionally enable listview on all non-root nodes of this specific type. Has anyone done this before?
n
perhaps SendingContentNotification and changing the available content apps would work
d
That's the path I'm chasing at the moment, yeah. Also the TreeRendering notification thing to render the tree properly
It turns out that you get 0 children in the content tree if listview is enabled. So even when disabling the flag for listview, it doesn't render any children
m
You can add list view as a property
d
Oh, I've never heard of list view as a property. I ended up hacking into the entity service and manually setting the
IsContainer
flag to false if the node was of the right type and was in the root
h
I'm assuming this is for the forum posts 😆 been wracking my brain on this one too 🤣 currently I just live with not having any children on the replies and created a custom view for the reply list
I was thinking maybe a custom content App would work, may have a play later 🤣
d
... maybe 😅 I snuck a decorator between the entityservice and the tree controller that sets the
IsContainer
flag to false on the root node of the forum. That seems to do the trick.
Copy code
csharp
public class DecoratorEntityServiceListViewDisabler : IEntityService
{
    private readonly IEntityService _decoratee;

    public DecoratorEntityServiceListViewDisabler(IEntityService decoratee)
    {
        _decoratee = decoratee;
    }

    // ... implement interface through _decoratee

    public IEntitySlim? Get(int id, UmbracoObjectTypes objectType)
    {
        var result = _decoratee.Get(id, objectType);
        if (objectType == UmbracoObjectTypes.Document && result is DocumentEntitySlim resultDocument && resultDocument.ParentId == -1)
        {
            // Disable isContainer
            resultDocument.IsContainer = false;
        }

        return result;
    }

    public IEntitySlim? Get(Guid key, UmbracoObjectTypes objectType)
    {
        var result = _decoratee.Get(key, objectType);
        if (objectType == UmbracoObjectTypes.Document && result is DocumentEntitySlim resultDocument && resultDocument.ParentId == -1)
        {
            // Disable isContainer
            resultDocument.IsContainer = false;
        }

        return result;
    }
}
h
I get an error if I try that, something about it not implementing the interface methods
31 Views