Allow for filtering of document type allowed children and allowed at root when creating new content. #18029
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Prerequisites
This addresses part of the discussion in #16329 relating to the removal of
SendingXNotifications
in 14+, to provide an alternative for theSendingAllowedChildrenNotification
.Description
This PR implements an alternative to the
SendingAllowedChildrenNotification
that isn't available in Umbraco 14+ but is documented as a feature.A filter is defined by the interface
IContentTypeFilter
. Methods are asynchronous. My guess is that most implementations won't need to use asynchronous methods, but given they might, it seemed better to define them this way.Originally I registered a single instance of this with a "no-op" implementation, but then realised it would be better as a collection. That way there could be more than one filter (perhaps one added by a package, and another explicitly by the implementor).
The registered filters are called in the
ContentTypeServiceBase
methods used for retrieving the "allowed children" and the "allowed at root" content types. So we get whatever we get from the Umbraco schema, and then run the results through the appropriate method on the filters, before returning the data to the front-end for rendering.An implementor could register their own filter that implements the features that this notification was used for - e.g. restricting the ability to create a node of a particular type if it already exists.
To Test:
This sample shows a couple of filters: