DEV Community

Discussion on: Content Editor defined dropdowns/checkboxlists and radiobuttonlists in Umbraco v8 with Contentment

Collapse
 
leekelleher profile image
Lee Kelleher

Hey @timgeyssens ! Thanks for trying out Contentment and writing up a how to guide on making a custom data source, very cool! 😎

The trouble I have with developing Contentment is knowing when to stop, I get carried away with refining the editor/developer experience. From reading this guide, I mind went "hmm, what if...?" 🤔

What if for the Property Alias field, we replaced it with a dropdown, so to prevent any typos? I recall seeing something on the Template editor to let you pick from an existing property... can we leverage that? Ah yes, it's a parameter editor called PropertyTypeParameterEditor.

OK, then we can try taking that config and add it in our custom data source...

new ConfigurationField
{
    Key = "propAlias",
    Name = "Property",
    Description = "Select the property to populate the data source with.",
    View = "~/umbraco/views/propertyeditors/entitypicker/entitypicker.html",
    Config = new Dictionary<string, object>
    {
        { "multiple", "0" },
        { "entityType", "PropertyType" },
        { "publishBy", "alias" },
    }
}

Now that gives us...

screengrab of property picker in custom data source

A friendly incremental enhancement. 🤗

Next I saw the use of DependencyResolver.Current.GetService(), but this is Umbraco v8... DEPENDENCY INJECT ALL THE THINGS!!!1 💪

We could inject the IUmbracoContextAccessor? A-la...

var content = _umbracoContextAccessor.UmbracoContext.Content.GetAtRoot().First();

I haven't gone to the full extend of writing unit-tests for every custom data source, but with using DI, it's a step towards that, (or so I'm told!)

I tinkered around with a couple of other bits, but mostly to satisfy my own opinionated coding style! 😆 Here's my latest gist: gist.github.com/leekelleher/d786f4...

Thanks again! Happy coding! 🎉

Collapse
 
timgeyssens profile image
Tim Geyssens

Woot, wasn't sure if DI would work... Why did I doubt you! Lovely!

Collapse
 
leekelleher profile image
Lee Kelleher

I still don't fully understand how DI all works - feels like a lot of dark magic. The main thing to watch out for is circular dependencies, it's a headwrecker! 😆