The IContentTypesFilter interface, which lets developers limited allowed content types in the Combined content selector, requires specifying the Guid identifiers of all content types you want to allow:
public interface IContentTypesFilter
{
//
// Summary:
// Provides GUID identifiers of allowed content item types.
IEnumerable<Guid> AllowedContentTypeIdentifiers { get; }
}
In the past I would grab a Guid from the database and hardcode it in any filter classes I created:
SELECT ClassGUID
FROM CMS_Class
WHERE ClassName = 'MyApp.ContentTypeName'
Not a good practice. It's manual, requires comments to explain what the value represents, and isn't scalable across many content types.
But, Xperience's code generation doesn't include the ClassGuid in the generated C# classes. 🤷
Well, KentiCopilot gives us access to the Management API MCP server which I told my agent to use with the following prompt:
use the xperience management api mcp server to
- get list of all reusable and page content types and their Class GUID values
- go through src\App\ContentTypes\ReusableContentTypes and src\App\ContentTypes\PageContentTypes and add partial classes for each type in the same location as the generated code partial class
- the new partial class should follow C# partial class requirements (ex: be in the same namespace)
- add a new public static Guid CONTENT_TYPE_GUID { get; } = new Guide("<ClassGUIDValue>"); with the value coming from the content type MCP server response(s)
The agent generated 31 class files that looked like this in about 2 minutes:
namespace App;
public partial class ProductCoffee
{
/// <summary>
/// Unique identifier (GUID) of the ProductCoffee content type.
/// </summary>
public static Guid CONTENT_TYPE_GUID { get; } = new Guid("fabc3c81-299c-4880-838f-ea123dd4131a");
}
I can now easily use these in a content type filter implementation:
public class ProductTypesFilter : IContentTypesNameFilter, IContentTypesFilter
{
private static readonly string[] ContentTypeNames =
[
ProductCoffee.CONTENT_TYPE_NAME,
ProductGrinder.CONTENT_TYPE_NAME,
ProductClothing.CONTENT_TYPE_NAME
];
private static readonly Guid[] ContentTypeGuids =
[
ProductCoffee.CONTENT_TYPE_GUID,
ProductGrinder.CONTENT_TYPE_GUID,
ProductClothing.CONTENT_TYPE_GUID
];
public IEnumerable<string> AllowedContentTypeNames => ContentTypeNames;
public IEnumerable<Guid> AllowedContentTypeIdentifiers => ContentTypeGuids;
}
I wouldn't have ever done this manually in the past because it would take too long and be difficult to maintain.
I think this is a great use-case for KentiCopilot!
What have you tried using it for? Any creative ideas you would suggest others try?
Environment
Xperience by Kentico version: [31.1.0]
.NET version: 10