Feature request: Expose valiation of content as function

Add contentLib.validate(content)

Is it possible to expose the validation that is being run on contentLib.modify(), so that it can be run independently?

It can be useful when creating some tooling around updating content when modifying content-type xmls.

Wasn’t this in the content roadmap before? Now I can’t find it anymore.

I’m talking about this:

  • Checklist support on content API - custom tailored scripts that can validate content before being allowed for publishing.

Source: Highlights from PAB - September 2018

In XP 7.8 we plan to introduce a Content Validation API.
The good news - this work is mostly done.
The bad news - for now, only Java API will be available.

1 Like

I guess one would have to submit a complete “new” content document, in order for this to work. Also, there is the problem of attachments - which are uploaded asyncronously - and can be validated themself.

Are you aware of the “requirevalid” option when creating or modifying content with the current API? So, by setting requireValid=true, a new document or change will not be persisted. IMHO this seems to solve your requirement?

I’m familiar with requireValid. :slight_smile:


Part of my thought here is that I wouldn’t want get updates my version log unnecessary.

Some usecases

  1. Create an admin-tool that gives content creators a list of invalid content that they have to open and fix.
  2. I have some code that will migrate my content to match changes in the content-type-xml, and I want to perform a “dry run” before updating the data.

Upcoming validation API won’t solve your case directly.
Yet with some Java/OSGi knowledge it will be possible.

Receiving all the validators:

private final List<ContentValidator> contentValidators = new CopyOnWriteArrayList<>();

@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
public void addContentValidator( final ContentValidator contentValidator )
{
    this.contentValidators.add( contentValidator );
}

public void removeContentValidator( final ContentValidator contentValidator )
{
    this.contentValidators.remove( contentValidator );
}

And then using them:

for ( ContentValidator contentValidator : contentValidators )
    {
        if ( contentValidator.supports( contentTypeName ) )
        {
            contentValidator.validate( validatorParams, resultBuilder );
        }
    }

So we are getting closer to implement it as JS API at some point. Unfortunately not in XP 7.8

1 Like

Awesome! It’s not something I needed right now anyway.

I just had some ideas where I could use it, so I just wanted to put it on Enonics radar. :slight_smile: