With a PointerTypeConstants.WebsitesPage you can quickly map this type to a model or link using someting like:
var pageList = blockModel.Fields.GetValue<IList<PointerItem>>(BlockFieldNameConstants.PageLinkList)?.OfType<PointerPageItem>().ToList().Select(x => x.MapTo<LinkModel>()).Where(x => x.AccessibleByUser).ToList() ?? new List<LinkModel>();
But for PointerTypeConstants.ProductsCategory I can’t find an Automapping for either CategoryModel nor LinkModel.
I have solved this using a List of Guids and the CategoryService, but I’m guessing there is a built-in way/mapping of converting a list of category Guids to LinkModels or CategoryModels that I just can’t find?
This is what I want to resolve as links to the viewModel:
new FieldDefinition<BlockArea>(BlockFieldNameConstants.CategoryLinkList, SystemFieldTypeConstants.Pointer)
{
Option = new PointerOption { EntityType = PointerTypeConstants.ProductsCategory, MultiSelect = true}
},
Is this a good way of doing it?
foreach (var item in categoryIds)
{
CategoryModel categoryModel = item.EntitySystemId.MapTo<CategoryModel>();
LinkModel categoryLinkModel = new LinkModel();
if (categoryModel != null)
{
if (categoryModel.Category != null && categoryModel.Category.IsPublished(websiteSystemId, channelSystemId) || true)
{
categoryLinkModel.Text = categoryModel.Category.Fields.GetValue<string>("_name", CultureInfo.CurrentUICulture);
categoryLinkModel.Href = _urlService.GetUrl(categoryModel.Category) ?? "/not-set-in-admin";
categoryList.Add(categoryLinkModel);
}
}
}
Litium version: 7.1