From 1a4e6e564cf7f12b788268d9687d2e4e1c70c91a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Knippers?= Date: Fri, 14 Feb 2020 15:16:50 +0100 Subject: [PATCH] Review Perplex change for Segments (#7659) * Fixes incorrect property inheritance logic * Fixes crash in canVariantPublish when variant.language is null * Adds variant display name in dropdown * Logic for invariant properties updated to also support segment invariance * Properties varied by segment only now properly saved when multiple variants are saved/published * Logic for disabling property editors moved to function and corrected for all cases of culture/segment properties * Fixes syntax error in less file * Fixes empty variants returned from GetEmpty() for a ContentType set to vary by segment --- .../Models/Mapping/ContentVariantMapper.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Web/Models/Mapping/ContentVariantMapper.cs b/src/Umbraco.Web/Models/Mapping/ContentVariantMapper.cs index 5d076812f3..c5f7e1a37a 100644 --- a/src/Umbraco.Web/Models/Mapping/ContentVariantMapper.cs +++ b/src/Umbraco.Web/Models/Mapping/ContentVariantMapper.cs @@ -113,11 +113,25 @@ namespace Umbraco.Web.Models.Mapping /// /// /// - /// Returns all segments assigned to the content including 'null' values + /// Returns all segments assigned to the content including the default `null` segment. /// private IEnumerable GetSegments(IContent content) { - return content.Properties.SelectMany(p => p.Values.Select(v => v.Segment)).Distinct(); + // The current segments of a content item are determined + // entirely on the current property values of the content. + var segments = content.Properties + .SelectMany(p => p.Values.Select(v => v.Segment)) + .Distinct() + .ToList(); + + if(segments.Count == 0) + { + // The default segment is always there, + // even when there is no property data at all yet + segments.Add(null); + } + + return segments; } private ContentVariantDisplay CreateVariantDisplay(MapperContext context, IContent content, Language language, string segment)