Skip to content

Instantly share code, notes, and snippets.

@JasonElkin
Created March 15, 2022 23:44
Show Gist options
  • Save JasonElkin/55b6e3a8610ed9c9b10850bd94438c83 to your computer and use it in GitHub Desktop.
Save JasonElkin/55b6e3a8610ed9c9b10850bd94438c83 to your computer and use it in GitHub Desktop.
Enable non-unique node names based on parent content type in Umbraco v9
public class CustomDocumentRepository : DocumentRepository
{
private static readonly string[] allowNonUniqueChildNames = { EventsPage.ModelTypeAlias, NewsPage.ModelTypeAlias };
public CustomDocumentRepository(
IScopeAccessor scopeAccessor,
AppCaches appCaches,
ILogger<DocumentRepository> logger,
ILoggerFactory loggerFactory,
IContentTypeRepository contentTypeRepository,
ITemplateRepository templateRepository,
ITagRepository tagRepository,
ILanguageRepository languageRepository,
IRelationRepository relationRepository,
IRelationTypeRepository relationTypeRepository,
PropertyEditorCollection propertyEditors,
DataValueReferenceFactoryCollection dataValueReferenceFactories,
IDataTypeService dataTypeService,
IJsonSerializer serializer,
IEventAggregator eventAggregator) : base(scopeAccessor, appCaches, logger, loggerFactory, contentTypeRepository, templateRepository, tagRepository, languageRepository, relationRepository, relationTypeRepository, propertyEditors, dataValueReferenceFactories, dataTypeService, serializer, eventAggregator)
{
}
protected override string EnsureUniqueNodeName(int parentId, string nodeName, int id = 0)
{
var parent = this.Get(parentId);
if (allowNonUniqueChildNames.InvariantContains(parent.ContentType.Alias))
{
return nodeName;
}
return base.EnsureUniqueNodeName(parentId, nodeName, id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment