Thanks Bart. Thought it might be something like that.
In the meantime, if anyone else has similar issues (although sounds like we are the only ones using it like this) this is what I've come up with for an EES Plugin. Add this to the EasyEditScreenLoad handler.
var config.options.mandatoryMetadata = ['My.Metadata.Field.Name'];
if (EasyEditScreens.currentScreenName == ‘Details’) {
EasyEditAssetManager.getCurrentAsset( function(asset) {
asset.metadataValues = null; // forces a refresh of the cached metadata values
asset.getMetadata( function(data) {
for (var i = 0; i < config.options.mandatoryMetadata.length; i++) {
if (!data[config.options.mandatoryMetadata.length[i]].length) {
$(’#ees_editStatus’).before($(’<div class=“ees-plugin-metadataRequired”><i class=“fa fa-exclamation-triangle”></i>This asset cannot be made live because some mandatory metadata fields are empty.</div>’));
break; // shortcircuit as soon as you have a failure
}
}
});
});
}
Oh yeah, and you may want to consider disabling the submit for approval and any similar option - I haven't got that far yet but it's something I'll be including.
Some notes about the above, in case some parts seem weird or pointless:
- You can't use JSAPI in the usual way as EES is already using it. Fortunately most JSAPI functions still seem available. Unfortunately they are not readily apparent, they are abstracted and encapsulated in the EasyEdit framework. To get the metadata you need to use the framework to get the asset first. Additionally, calling the functions in the standard JSAPI way don't work, most notably some arguments are altered/not required.
- The loop shortcircuits - I only wanted to display a single warning. But you could easily add more HTML to say which fields were missing content.
- You need to set asset.metadataValues to null as this field caches the values, so you'll be comparing old copies of the data rather than the most recent. Most likely this is a performance tuning. It seems to only refresh when you hit the metadata screen. If you manually clear it then it forces the framework to get the latest copy. Performance-wise this additional call is fast (only takes 170ms from work, 90ms at home). Nevertheless I've restricted it to only on the Details screen (depending on author needs I may need to display a warning on the workflow screen as well, in which case I'll clear it for that screen as well).
- The response from getMetadata returns field names and their corresponding values, not whether the the field is required or not. By itself not enough to tell us when to show a warning. See next point in how to configure.
-
config.options.mandatoryMetadata (not it's real name) is an array of strings, literally the metadata field names we are interested in. This needs to be configured elsewhere in the plugin (shown in the first line in the example code above). Add strings of the fieldnames you require filled in before submission - this will allow the flexibility of forcing fields you've specified filled in now, and other required fields able to be filled in later. Also allows you to configure it different on site-by-site basis (at least the way I set up EES plugins it does).
- I've only catered for text fields at the moment. Not sure how other field types, like multiple fields, selects, related assets, and especially dates, would work. Text is enough for us at the moment, but I'd imagine if it needed to be expanded out you'd have to handle the different types somehow, possibly requiring additional configuration options.
Hope that all makes sense and helps someone (even though it seems we're the only ones who want this behaviour).