Add support for tags in block editors and nested content (#13412)

* feat: add tags extension points and remove hardcoded tags handling

* feat: allow tags editor in nested content and block editors

* Update src/Umbraco.Infrastructure/PropertyEditors/TagsPropertyEditor.cs

Co-authored-by: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com>

* Update src/Umbraco.Web.BackOffice/Controllers/ContentControllerBase.cs

Co-authored-by: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com>

Co-authored-by: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com>
This commit is contained in:
Rasmus John Pedersen
2022-11-28 11:20:46 +01:00
committed by GitHub
parent e366da8c83
commit c88ac85861
11 changed files with 209 additions and 30 deletions

View File

@@ -274,29 +274,59 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
{
foreach (IProperty property in entity.Properties)
{
TagConfiguration? tagConfiguration = property.GetTagConfiguration(PropertyEditors, DataTypeService);
if (tagConfiguration == null)
if (PropertyEditors.TryGet(property.PropertyType.PropertyEditorAlias, out var editor) is false)
{
continue; // not a tags property
continue;
}
if (editor.GetValueEditor() is not IDataValueTags tagsProvider)
{
// support for legacy tag editors, everything from here down to the last continue can be removed when TagsPropertyEditorAttribute is removed
TagConfiguration? tagConfiguration = property.GetTagConfiguration(PropertyEditors, DataTypeService);
if (tagConfiguration == null)
{
continue;
}
if (property.PropertyType.VariesByCulture())
{
var tags = new List<ITag>();
foreach (IPropertyValue pvalue in property.Values)
{
IEnumerable<string> tagsValue = property.GetTagsValue(PropertyEditors, DataTypeService, serializer, pvalue.Culture);
var languageId = LanguageRepository.GetIdByIsoCode(pvalue.Culture);
IEnumerable<Tag> cultureTags = tagsValue.Select(x => new Tag { Group = tagConfiguration.Group, Text = x, LanguageId = languageId });
tags.AddRange(cultureTags);
}
tagRepo.Assign(entity.Id, property.PropertyTypeId, tags);
}
else
{
IEnumerable<string> tagsValue = property.GetTagsValue(PropertyEditors, DataTypeService, serializer); // strings
IEnumerable<Tag> tags = tagsValue.Select(x => new Tag { Group = tagConfiguration.Group, Text = x });
tagRepo.Assign(entity.Id, property.PropertyTypeId, tags);
}
continue; // not implementing IDataValueTags, continue
}
object? configuration = DataTypeService.GetDataType(property.PropertyType.DataTypeId)?.Configuration;
if (property.PropertyType.VariesByCulture())
{
var tags = new List<ITag>();
foreach (IPropertyValue pvalue in property.Values)
{
IEnumerable<string> tagsValue = property.GetTagsValue(PropertyEditors, DataTypeService, serializer, pvalue.Culture);
var languageId = LanguageRepository.GetIdByIsoCode(pvalue.Culture);
IEnumerable<Tag> cultureTags = tagsValue.Select(x => new Tag { Group = tagConfiguration.Group, Text = x, LanguageId = languageId });
tags.AddRange(cultureTags);
tags.AddRange(tagsProvider.GetTags(pvalue.EditedValue, configuration, languageId));
}
tagRepo.Assign(entity.Id, property.PropertyTypeId, tags);
}
else
{
IEnumerable<string> tagsValue = property.GetTagsValue(PropertyEditors, DataTypeService, serializer); // strings
IEnumerable<Tag> tags = tagsValue.Select(x => new Tag { Group = tagConfiguration.Group, Text = x });
IEnumerable<ITag> tags = tagsProvider.GetTags(property.GetValue(), configuration, null);
tagRepo.Assign(entity.Id, property.PropertyTypeId, tags);
}
}