You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When creating a custom content class without implementing the ICategorizedContent interface, you won't be able to save the content in the management area, because the error '' is given.
I think this is caused by the SaveAsync(ContentEditModel model) method in \core\Piranha.Manager\Services\ContentService.cs. This method retrieves the content as DynamicContent, which implements the ICategorizedContent interface:
var content = await _api.Content.GetByIdAsync(model.Id, model.LanguageId);
if (content == null)
{
content = await _factory.CreateAsync<DynamicContent>(contentType);
content.Id = model.Id;
}
But, when saving, the ContentEditModel has the UseCategory property set as false (expected) since the original content type does not implement the interface.
When actually saving the content in \core\Piranha\Services\ContentService.cs method SaveAsync<T>(T model, Guid? languageId = null) where T : GenericContent, an check on the ICategorizedContent interface is performed, requiring the category to be specified. Since the DynamicContent class implements this interface, it is required to have the category set:
// Ensure category
if (model is ICategorizedContent categorizedModel)
{
if (categorizedModel.Category == null || (string.IsNullOrWhiteSpace(categorizedModel.Category.Title) && string.IsNullOrWhiteSpace(categorizedModel.Category.Slug)))
{
throw new ValidationException("The Category field is required");
}
}
I do not know the reasoning behind this check, why it has been added (and if it has a real purpose, why not performing the same checks on ITaggedContent for instance), or if it can be removed safely.
The text was updated successfully, but these errors were encountered:
This is a bug. It will be fixed and released in a service release for 9.1. The condition is correct for typed models, but like you say, should be handled differently for dynamic models.
When creating a custom content class without implementing the
ICategorizedContent
interface, you won't be able to save the content in the management area, because the error '' is given.I think this is caused by the
SaveAsync(ContentEditModel model)
method in\core\Piranha.Manager\Services\ContentService.cs
. This method retrieves the content asDynamicContent
, which implements theICategorizedContent
interface:But, when saving, the
ContentEditModel
has theUseCategory
property set as false (expected) since the original content type does not implement the interface.When actually saving the content in
\core\Piranha\Services\ContentService.cs
methodSaveAsync<T>(T model, Guid? languageId = null) where T : GenericContent
, an check on theICategorizedContent
interface is performed, requiring the category to be specified. Since theDynamicContent
class implements this interface, it is required to have the category set:I do not know the reasoning behind this check, why it has been added (and if it has a real purpose, why not performing the same checks on
ITaggedContent
for instance), or if it can be removed safely.The text was updated successfully, but these errors were encountered: