Sometimes when working with
MediaData or other inherited
IContentMedia in EPiServer you need to add extra fields and properties. If you do – resist the temptation to make them Required.
The standard behaviour when uploading a document it becomes
Published upon upload completion. When adding properties (fields) with the
[Required] attribute, EPiServer cannot by itself populate these properties, and is therefore unable to automatically publish these resources.
So, why is this bad?
The behaviour by itself is not bad, if I've not added values to mandatory fields, then it shouldn't just 'go ahead and get published'.
The problems occur because while a resource is unpublished, it's always available for selection. And when accessed 'from outside' it renders a 404 response.
One even worse design flaw is that the editor never gets the feedback that the resource isn't published until it's actively gets selected for editing.
So, the scenarios is this:
Unpublished content can be used in a published context; rendering in a nice 404 response if accessed.
Unpublished content does not alter state when added to a published context. Still rendering a 404 response.
Unpublished content does not differentiate itself from published content in Edit mode; not providing any kind of visible feedback to the editor while viewing (outside explicit object editing) and selecting the resource. This is NOT okay.
Recently I had a case where one client had 300+ documents, used site wide, that where not published and gave them a big headache and grumpy visitors.
It was not that fun telling them that they needed manually publish all documents to be accessed publicly. Luckily we built a small (but powerful!) tool to help them with that; a tool which I hope to be able to get back to in future posts...