Skip to content

Commit

Permalink
Merge branch 'v8/8.13' into v8/8.14
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/SolutionInfo.cs
  • Loading branch information
nul800sebastiaan committed May 19, 2021
2 parents df8b2d5 + 7c2f956 commit 7b77d21
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -789,10 +789,10 @@ function contentEditingHelper(fileManager, $q, $location, $routeParams, editorSt
*/
sortVariants: function (a, b) {
const statesOrder = {'PublishedPendingChanges':1, 'Published': 1, 'Draft': 2, 'NotCreated': 3};
const compareDefault = (a,b) => (!a.language.isDefault ? 1 : -1) - (!b.language.isDefault ? 1 : -1);
const compareDefault = (a,b) => (a.language && a.language.isDefault ? -1 : 1) - (b.language && b.language.isDefault ? -1 : 1);

// Make sure mandatory variants goes on top, unless they are published, cause then they already goes to the top and then we want to mix them with other published variants.
const compareMandatory = (a,b) => (a.state === 'PublishedPendingChanges' || a.state === 'Published') ? 0 : (!a.language.isMandatory ? 1 : -1) - (!b.language.isMandatory ? 1 : -1);
const compareMandatory = (a,b) => (a.state === 'PublishedPendingChanges' || a.state === 'Published') ? 0 : (a.language && a.language.isMandatory ? -1 : 1) - (b.language && b.language.isMandatory ? -1 : 1);
const compareState = (a, b) => (statesOrder[a.state] || 99) - (statesOrder[b.state] || 99);
const compareName = (a, b) => a.displayName.localeCompare(b.displayName);

Expand All @@ -813,17 +813,18 @@ function contentEditingHelper(fileManager, $q, $location, $routeParams, editorSt
*/
getSortedVariantsAndSegments: function (variantsAndSegments) {
const sortedVariants = variantsAndSegments.filter(variant => !variant.segment).sort(this.sortVariants);
let segments = variantsAndSegments.filter(variant => variant.segment);
let variantsWithSegments = variantsAndSegments.filter(variant => variant.segment);
let sortedAvailableVariants = [];

sortedVariants.forEach((variant) => {
const sortedMatchedSegments = segments.filter(segment => segment.language.culture === variant.language.culture).sort(this.sortVariants);
segments = segments.filter(segment => segment.language.culture !== variant.language.culture);
const sortedMatchedSegments = variantsWithSegments.filter(segment => segment.language && variant.language && segment.language.culture === variant.language.culture).sort(this.sortVariants);
// remove variants for this culture
variantsWithSegments = variantsWithSegments.filter(segment => !segment.language || segment.language && variant.language && segment.language.culture !== variant.language.culture);
sortedAvailableVariants = [...sortedAvailableVariants, ...[variant], ...sortedMatchedSegments];
})

// if we have segments without a parent language variant we need to add the remaining segments to the array
sortedAvailableVariants = [...sortedAvailableVariants, ...segments.sort(this.sortVariants)];
// if we have segments without a parent language variant we need to add the remaining variantsWithSegments to the array
sortedAvailableVariants = [...sortedAvailableVariants, ...variantsWithSegments.sort(this.sortVariants)];

return sortedAvailableVariants;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Umbraco.Web/PublishedContentExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
Expand Down Expand Up @@ -174,7 +174,7 @@ public static T Value<T>(this IPublishedContent content, string alias, string cu

// else... if we have a property, at least let the converter return its own
// vision of 'no value' (could be an empty enumerable) - otherwise, default
return property == null ? default : property.Value<T>(culture, segment, fallback, defaultValue);
return property == null ? default : property.Value<T>(culture, segment);
}

#endregion
Expand Down
30 changes: 5 additions & 25 deletions src/Umbraco.Web/PublishedPropertyExtension.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Models.PublishedContent;
Expand Down Expand Up @@ -36,16 +37,9 @@ public static T Value<T>(this IPublishedProperty property, string culture = null
// we have a value
// try to cast or convert it
var value = property.GetValue(culture, segment);
if (value is T valueAsT)
{
return valueAsT;
}

if (value is T valueAsT) return valueAsT;
var valueConverted = value.TryConvertTo<T>();
if (valueConverted)
{
return valueConverted.Result;
}
if (valueConverted) return valueConverted.Result;

// cannot cast nor convert the value, nothing we can return but 'default'
// note: we don't want to fallback in that case - would make little sense
Expand All @@ -54,28 +48,14 @@ public static T Value<T>(this IPublishedProperty property, string culture = null

// we don't have a value, try fallback
if (PublishedValueFallback.TryGetValue(property, culture, segment, fallback, defaultValue, out var fallbackValue))
{
return fallbackValue;
}

// we don't have a value - neither direct nor fallback
// give a chance to the converter to return something (eg empty enumerable)
var noValue = property.GetValue(culture, segment);
if (noValue == null)
{
return default;
}

if (noValue is T noValueAsT)
{
return noValueAsT;
}

if (noValue is T noValueAsT) return noValueAsT;
var noValueConverted = noValue.TryConvertTo<T>();
if (noValueConverted)
{
return noValueConverted.Result;
}
if (noValueConverted) return noValueConverted.Result;

// cannot cast noValue nor convert it, nothing we can return but 'default'
return default;
Expand Down

0 comments on commit 7b77d21

Please sign in to comment.