Skip to content

Commit 413a278

Browse files
nikolajlauridsennikolajlauridsenZeegaan
authored
V9: Fix missing EditedCultures and Name in content saving notifications (#12070)
* Map dirty culture to EditedCultures before saving And set the name of the content when setting default culture variant name * Update src/Umbraco.Web.BackOffice/Controllers/ContentController.cs Co-authored-by: Nikolaj Geisle <[email protected]> Co-authored-by: nikolajlauridsen <[email protected]> Co-authored-by: Nikolaj Geisle <[email protected]>
1 parent 5d6fc60 commit 413a278

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

src/Umbraco.Web.BackOffice/Controllers/ContentController.cs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,40 +2122,53 @@ private void MapValuesForPersistence(ContentItemSave contentSave)
21222122
}
21232123

21242124
var variantIndex = 0;
2125+
var defaultCulture = _allLangs.Value.Values.FirstOrDefault(x => x.IsDefault)?.IsoCode;
21252126

2126-
//loop through each variant, set the correct name and property values
2127+
// loop through each variant, set the correct name and property values
21272128
foreach (var variant in contentSave.Variants)
21282129
{
2129-
//Don't update anything for this variant if Save is not true
2130-
if (!variant.Save) continue;
2130+
// Don't update anything for this variant if Save is not true
2131+
if (!variant.Save)
2132+
{
2133+
continue;
2134+
}
21312135

2132-
//Don't update the name if it is empty
2136+
// Don't update the name if it is empty
21332137
if (!variant.Name.IsNullOrWhiteSpace())
21342138
{
21352139
if (contentSave.PersistedContent.ContentType.VariesByCulture())
21362140
{
21372141
if (variant.Culture.IsNullOrWhiteSpace())
2142+
{
21382143
throw new InvalidOperationException($"Cannot set culture name without a culture.");
2144+
}
2145+
21392146
contentSave.PersistedContent.SetCultureName(variant.Name, variant.Culture);
2147+
2148+
// If the variant culture is the default culture we also want to update the name on the Content itself.
2149+
if (variant.Culture.Equals(defaultCulture, StringComparison.InvariantCultureIgnoreCase))
2150+
{
2151+
contentSave.PersistedContent.Name = variant.Name;
2152+
}
21402153
}
21412154
else
21422155
{
21432156
contentSave.PersistedContent.Name = variant.Name;
21442157
}
21452158
}
21462159

2147-
//This is important! We only want to process invariant properties with the first variant, for any other variant
2160+
// This is important! We only want to process invariant properties with the first variant, for any other variant
21482161
// we need to exclude invariant properties from being processed, otherwise they will be double processed for the
21492162
// same value which can cause some problems with things such as file uploads.
21502163
var propertyCollection = variantIndex == 0
21512164
? variant.PropertyCollectionDto
21522165
: new ContentPropertyCollectionDto
21532166
{
21542167
Properties = variant.PropertyCollectionDto.Properties.Where(
2155-
x => !x.Culture.IsNullOrWhiteSpace() || !x.Segment.IsNullOrWhiteSpace())
2168+
x => !x.Culture.IsNullOrWhiteSpace() || !x.Segment.IsNullOrWhiteSpace()),
21562169
};
21572170

2158-
//for each variant, map the property values
2171+
// for each variant, map the property values
21592172
MapPropertyValuesForPersistence<IContent, ContentItemSave>(
21602173
contentSave,
21612174
propertyCollection,
@@ -2176,6 +2189,12 @@ private void MapValuesForPersistence(ContentItemSave contentSave)
21762189
variantIndex++;
21772190
}
21782191

2192+
// Map IsDirty cultures to edited cultures, to make it easier to verify changes on specific variants on Saving and Saved events.
2193+
IEnumerable<string> editedCultures = contentSave.PersistedContent.CultureInfos.Values
2194+
.Where(x => x.IsDirty())
2195+
.Select(x => x.Culture);
2196+
contentSave.PersistedContent.SetCultureEdited(editedCultures);
2197+
21792198
// handle template
21802199
if (string.IsNullOrWhiteSpace(contentSave.TemplateAlias)) // cleared: clear if not already null
21812200
{
@@ -2186,10 +2205,10 @@ private void MapValuesForPersistence(ContentItemSave contentSave)
21862205
}
21872206
else // set: update if different
21882207
{
2189-
var template = _fileService.GetTemplate(contentSave.TemplateAlias);
2190-
if (template == null)
2208+
ITemplate template = _fileService.GetTemplate(contentSave.TemplateAlias);
2209+
if (template is null)
21912210
{
2192-
//ModelState.AddModelError("Template", "No template exists with the specified alias: " + contentItem.TemplateAlias);
2211+
// ModelState.AddModelError("Template", "No template exists with the specified alias: " + contentItem.TemplateAlias);
21932212
_logger.LogWarning("No template exists with the specified alias: {TemplateAlias}", contentSave.TemplateAlias);
21942213
}
21952214
else if (template.Id != contentSave.PersistedContent.TemplateId)

0 commit comments

Comments
 (0)