A user create a Post (Entity) and define a UrlKey field (input type url-path)
I want prevent a duplicate value (if another entity of this type already had a urlkey with same content)
Is there a way to accomplish that ?
* Edited *
Looking to the 2sxc code I didnt found a simple way to do that.
One thing that I have in mind is to create a ApiController/Endpoint that I can call and make the validation that I want, but for this I need to change the view from the Edit Content (for the user, not the admin one).
I found to the save in /dist/ng-edit/main.js that is minified, there I could change and call my controller/endpoint, but to change to show some feedback messages to user and after call the original endpoint is difficult with minified file.
Is a possibility to have the code that generate the main.js ? (Maybe is already there, and I couldn´t found)
I am not aware of a built in (easy) way to accomplish this. But doing it in the View with a warning is probably a good fallback option. Assuming you have a View (ListContent) that shows a group of Posts, you could add something like this, though it is catching it AFTER the fact...
I just did something like this a few weeks ago because a client kept repeating Titles in the Blueimp Gallery app. So you can just drop this in to _AlbumList Bootstrap.cshtml
at line 4, create a few duplicates (Titles which will generate duplicate Paths) and you should see an option to fix them... So, after the fact, if there are duplicates and the current user is Super/Admin/ContentManager, then let them know the situation and make it easy to fix:
@using DotNetNuke.Entities.Portals @* used by IsAdminOrHost() *@
@using DotNetNuke.Entities.Users @* used by IsAdminOrHost(), IsContentManager() *@
@{
if(IsContentManager(Dnn.User)){
var query = AsDynamic(Data["Default"])
.GroupBy(x => x.Path)
.Where(g => g.Count() > 1)
.Select(y => y.Key)
.ToList();
if(query != null) {
<pre>
You have duplicates (@query.Count()), please fix them:
@foreach(var dupe in AsDynamic(Data["Default"])
.Where(p => query.Any(x => x == p.Path)) ) {
<span @Edit.TagToolbar(dupe)>-- @dupe.EntityId, @dupe.Path</span>
}
</pre>
}
}
}
@functions {
// is the current user an Admin or Host?
public bool IsAdminOrHost(UserInfo userInfo) {
return userInfo.IsSuperUser || userInfo.IsInRole(PortalSettings.Current.AdministratorRoleName);
}
// is the current user a Content or Site Manager (or Admin+)?
public bool IsContentManager(UserInfo userInfo) {
return userInfo.IsInRole("Content Managers")
|| userInfo.IsInRole("Site Managers")
|| IsAdminOrHost(userInfo);
}
}
Results should look something like this: