Prevent users from removing block from content area


Let's say I have a page with a content area, and there are couple of blocks predefined (e.g. by administrator). Is it possible to prevent regular editors (who can edit the page) from removing those block from content area?

They still should be able to create/add blocks, but I definitely don't want them to remove some of them.

Jun 09, 2020 9:31

You could create a custom validator, as described here:

I am not sure exactly what logic you want, but it the blocks should always be there, maybe (pseudo-code):

if (!user.isAdmin() && !contentArea.containsRequiredBlocks())
   return new ValidationError("Stop deleting the blocks, common user!");
Edited, Jun 09, 2020 9:49

You could also place the content area on a tab only available to administrators. That way only administrators will be able to delete the blocks.

You can create another content area for the other users, on a tab where everyone can access the property.

Not sure if this fits your use case, though.

Edited, Jun 09, 2020 9:54

You could hook into the OnSavingContent-event, then load the previous version of the page using IContentVersionRepository and then compare the content area of the different versions to see if any items have been removed. 

If you detect that an item has been removed that shouldn't have, you can trigger a validation error and cancel the save. 

Jun 09, 2020 9:57

What would be the experience for the editor with the validator approach? I think he would be able to remove the block, validation error would occur and in order to be able to save the page, he would need to restore the block manually. Or revert page version. Correct?

Jun 09, 2020 9:57
Tomas Hensrud Gulla - Jun 09, 2020 10:03
Yes, I think that sums it up.
Jørgen Tonvang - Jun 09, 2020 10:36
If you take my approach, you could reset only the ContentArea-property to the previous version and issue a warning, without the editor having to manually do anything.

I would personally just put the configuration of the default blocks somewhere other than the page then render them both out. I did this on a previous project and it worked well.

Jun 10, 2020 10:20
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.