Skip to content

Commit

Permalink
Code amends to be v9.0.0 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
leekelleher committed Oct 5, 2021
1 parent 11276a0 commit de3e709
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core.Models.Membership;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using UmbConstants = Umbraco.Core.Constants;
using Umbraco.Cms.Core.Models.Membership;
using Umbraco.Cms.Core.PropertyEditors;
using Umbraco.Cms.Core.Services;
using UmbConstants = Umbraco.Cms.Core.Constants;

namespace Umbraco.Community.Contentment.DataEditors
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,24 @@
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json.Linq;
using Umbraco.Core;
using Umbraco.Core.IO;
using Umbraco.Core.Models.Membership;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using UmbConstants = Umbraco.Core.Constants;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.IO;
using Umbraco.Cms.Core.Models.Membership;
using Umbraco.Cms.Core.PropertyEditors;
using Umbraco.Cms.Core.Services;
using Umbraco.Extensions;
using UmbConstants = Umbraco.Cms.Core.Constants;

namespace Umbraco.Community.Contentment.DataEditors
{
public sealed class UmbracoUsersDataListSource : IDataListSource, IDataListSourceValueConverter
{
private readonly IIOHelper _ioHelper;
private readonly IUserService _userService;

public UmbracoUsersDataListSource(IUserService userService)
public UmbracoUsersDataListSource(IIOHelper ioHelper, IUserService userService)
{
_ioHelper = ioHelper;
_userService = userService;
}

Expand Down Expand Up @@ -61,7 +64,7 @@ public IEnumerable<ConfigurationField> Fields
{ "enableFilter", items.Count > 5 ? Constants.Values.True : Constants.Values.False },
{ "items", items },
{ "listType", "list" },
{ "overlayView", IOHelper.ResolveUrl(ItemPickerDataListEditor.DataEditorOverlayViewPath) },
{ "overlayView", _ioHelper.ResolveRelativeOrVirtualUrl(ItemPickerDataListEditor.DataEditorOverlayViewPath) },
{ "maxItems", 1 },
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

using System.Collections.Generic;
using Umbraco.Core.IO;
using Umbraco.Core.PropertyEditors;
using UmbConstants = Umbraco.Core.Constants;
using Umbraco.Cms.Core.IO;
using Umbraco.Cms.Core.PropertyEditors;
using Umbraco.Extensions;
using UmbConstants = Umbraco.Cms.Core.Constants;

namespace Umbraco.Community.Contentment.DataEditors
{
internal sealed class TemplatedLabelConfigurationEditor : ConfigurationEditor
{
public TemplatedLabelConfigurationEditor()
public TemplatedLabelConfigurationEditor(IIOHelper ioHelper)
: base()
{
var valueTypes = new[]
Expand All @@ -36,15 +37,15 @@ public TemplatedLabelConfigurationEditor()
Key = UmbConstants.PropertyEditors.ConfigurationKeys.DataValueType,
Name = "Value type",
Description = "Select the value's type. This defines how the underlying value is stored in the database.",
View = IOHelper.ResolveUrl(DropdownListDataListEditor.DataEditorViewPath),
View = ioHelper.ResolveRelativeOrVirtualUrl(DropdownListDataListEditor.DataEditorViewPath),
Config = new Dictionary<string, object>
{
{ DropdownListDataListEditor.AllowEmpty, Constants.Values.False },
{ Constants.Conventions.ConfigurationFieldAliases.Items, valueTypes },
}
});

Fields.Add(new NotesConfigurationField(@"<details class=""well well-small umb-property-editor--limit-width"">
Fields.Add(new NotesConfigurationField(ioHelper, @"<details class=""well well-small umb-property-editor--limit-width"">
<summary><strong>Do you need help with your custom template?</strong></summary>
<p>Your custom template will be used to display the label on the property from the underlying value.</p>
<p>If you are familiar with AngularJS template syntax, you can display the value using an expression: e.g. <code ng-non-bindable>{{ model.value }}</code>.</p>
Expand All @@ -62,7 +63,7 @@ public TemplatedLabelConfigurationEditor()
Key = "notes",
Name = "Template",
Description = "Enter the AngularJS template to be displayed for the label.",
View = IOHelper.ResolveUrl(CodeEditorDataEditor.DataEditorViewPath),
View = ioHelper.ResolveRelativeOrVirtualUrl(CodeEditorDataEditor.DataEditorViewPath),
Config = new Dictionary<string, object>
{
{ CodeEditorConfigurationEditor.Mode, "razor" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

using System.Collections.Generic;
using Umbraco.Core;
using Umbraco.Core.PropertyEditors;
using Umbraco.Cms.Core.IO;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.PropertyEditors;
using Umbraco.Cms.Core.Serialization;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Strings;
using Umbraco.Extensions;

namespace Umbraco.Community.Contentment.DataEditors
{
Expand All @@ -16,6 +21,23 @@ public sealed class TemplatedLabelDataEditor : IDataEditor
internal const string DataEditorViewPath = NotesDataEditor.DataEditorViewPath;
internal const string DataEditorIcon = "icon-fa fa-codepen";

private readonly ILocalizedTextService _localizedTextService;
private readonly IShortStringHelper _shortStringHelper;
private readonly IJsonSerializer _jsonSerializer;
private readonly IIOHelper _ioHelper;

public TemplatedLabelDataEditor(
ILocalizedTextService localizedTextService,
IShortStringHelper shortStringHelper,
IJsonSerializer jsonSerializer,
IIOHelper ioHelper)
{
_localizedTextService = localizedTextService;
_shortStringHelper = shortStringHelper;
_jsonSerializer = jsonSerializer;
_ioHelper = ioHelper;
}

public string Alias => DataEditorAlias;

public EditorType Type => EditorType.PropertyValue;
Expand All @@ -32,13 +54,16 @@ public sealed class TemplatedLabelDataEditor : IDataEditor

public IPropertyIndexValueFactory PropertyIndexValueFactory => new DefaultPropertyIndexValueFactory();

public IConfigurationEditor GetConfigurationEditor() => new TemplatedLabelConfigurationEditor();
public IConfigurationEditor GetConfigurationEditor() => new TemplatedLabelConfigurationEditor(_ioHelper);

public IDataValueEditor GetValueEditor()
{
return new DataValueEditor
return new DataValueEditor(
_localizedTextService,
_shortStringHelper,
_jsonSerializer)
{
View = DataEditorViewPath,
View = _ioHelper.ResolveRelativeOrVirtualUrl(DataEditorViewPath),
};
}

Expand All @@ -51,11 +76,14 @@ public IDataValueEditor GetValueEditor(object configuration)
hideLabel = config[HideLabelConfigurationField.HideLabelAlias].TryConvertTo<bool>().Result;
}

return new DataValueEditor
return new DataValueEditor(
_localizedTextService,
_shortStringHelper,
_jsonSerializer)
{
Configuration = configuration,
HideLabel = hideLabel,
View = DataEditorViewPath,
View = _ioHelper.ResolveRelativeOrVirtualUrl(DataEditorViewPath),
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

using System;
using System.Collections.Generic;
using Umbraco.Core;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.PropertyEditors.ValueConverters;
using UmbConstants = Umbraco.Core.Constants;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core.PropertyEditors;
using Umbraco.Cms.Core.PropertyEditors.ValueConverters;
using Umbraco.Extensions;
using UmbConstants = Umbraco.Cms.Core.Constants;

namespace Umbraco.Community.Contentment.DataEditors
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
using System;
using System.Linq.Expressions;
using System.Reflection;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.ModelsBuilder.Embedded;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Infrastructure.ModelsBuilder;

namespace Umbraco.Web
namespace Umbraco.Extensions
{
public static class PublishedElementExtensions
{
Expand All @@ -21,13 +21,13 @@ public static bool HasValueFor<TModel, TValue>(this TModel model, Expression<Fun
}

// NOTE: Bah! `PublishedElementExtensions.GetAlias` is marked as private! It's either copy code, or reflection - here we go!
// https://github.com/umbraco/Umbraco-CMS/blob/release-8.14.0/src/Umbraco.ModelsBuilder.Embedded/PublishedElementExtensions.cs#L28
// https://github.com/umbraco/Umbraco-CMS/blob/release-9.0.0/src/Umbraco.Infrastructure/ModelsBuilder/PublishedElementExtensions.cs#L27
private static string GetAlias<TModel, TValue>(TModel model, Expression<Func<TModel, TValue>> property)
{
try
{
var assembly = typeof(ApiVersion).Assembly;
var type = assembly.GetType("Umbraco.Web.PublishedElementExtensions");
var type = assembly.GetType("Umbraco.Extensions.PublishedElementExtensions");
var method = type.GetMethod(nameof(GetAlias), BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod);
var generic = method.MakeGenericMethod(typeof(TModel), typeof(TValue));
return generic.Invoke(null, new object[] { model, property }) as string;
Expand Down

0 comments on commit de3e709

Please sign in to comment.