@@ -2122,40 +2122,53 @@ private void MapValuesForPersistence(ContentItemSave contentSave)
2122
2122
}
2123
2123
2124
2124
var variantIndex = 0 ;
2125
+ var defaultCulture = _allLangs . Value . Values . FirstOrDefault ( x => x . IsDefault ) ? . IsoCode ;
2125
2126
2126
- //loop through each variant, set the correct name and property values
2127
+ // loop through each variant, set the correct name and property values
2127
2128
foreach ( var variant in contentSave . Variants )
2128
2129
{
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
+ }
2131
2135
2132
- //Don't update the name if it is empty
2136
+ // Don't update the name if it is empty
2133
2137
if ( ! variant . Name . IsNullOrWhiteSpace ( ) )
2134
2138
{
2135
2139
if ( contentSave . PersistedContent . ContentType . VariesByCulture ( ) )
2136
2140
{
2137
2141
if ( variant . Culture . IsNullOrWhiteSpace ( ) )
2142
+ {
2138
2143
throw new InvalidOperationException ( $ "Cannot set culture name without a culture.") ;
2144
+ }
2145
+
2139
2146
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
+ }
2140
2153
}
2141
2154
else
2142
2155
{
2143
2156
contentSave . PersistedContent . Name = variant . Name ;
2144
2157
}
2145
2158
}
2146
2159
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
2148
2161
// we need to exclude invariant properties from being processed, otherwise they will be double processed for the
2149
2162
// same value which can cause some problems with things such as file uploads.
2150
2163
var propertyCollection = variantIndex == 0
2151
2164
? variant . PropertyCollectionDto
2152
2165
: new ContentPropertyCollectionDto
2153
2166
{
2154
2167
Properties = variant . PropertyCollectionDto . Properties . Where (
2155
- x => ! x . Culture . IsNullOrWhiteSpace ( ) || ! x . Segment . IsNullOrWhiteSpace ( ) )
2168
+ x => ! x . Culture . IsNullOrWhiteSpace ( ) || ! x . Segment . IsNullOrWhiteSpace ( ) ) ,
2156
2169
} ;
2157
2170
2158
- //for each variant, map the property values
2171
+ // for each variant, map the property values
2159
2172
MapPropertyValuesForPersistence < IContent , ContentItemSave > (
2160
2173
contentSave ,
2161
2174
propertyCollection ,
@@ -2176,6 +2189,12 @@ private void MapValuesForPersistence(ContentItemSave contentSave)
2176
2189
variantIndex ++ ;
2177
2190
}
2178
2191
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
+
2179
2198
// handle template
2180
2199
if ( string . IsNullOrWhiteSpace ( contentSave . TemplateAlias ) ) // cleared: clear if not already null
2181
2200
{
@@ -2186,10 +2205,10 @@ private void MapValuesForPersistence(ContentItemSave contentSave)
2186
2205
}
2187
2206
else // set: update if different
2188
2207
{
2189
- var template = _fileService . GetTemplate ( contentSave . TemplateAlias ) ;
2190
- if ( template == null )
2208
+ ITemplate template = _fileService . GetTemplate ( contentSave . TemplateAlias ) ;
2209
+ if ( template is null )
2191
2210
{
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);
2193
2212
_logger . LogWarning ( "No template exists with the specified alias: {TemplateAlias}" , contentSave . TemplateAlias ) ;
2194
2213
}
2195
2214
else if ( template . Id != contentSave . PersistedContent . TemplateId )
0 commit comments