This property editor makes use of AWS Cloud 9's Ace editor library that is distributed with Umbraco. By default, Umbraco ships a streamlined set of programming language modes and themes.
If you would like to add more modes and themes, you can do this by downloading the latest pre-packaged version of the Ace editor and copy any of the mode-* or theme-* files from the src-min-noconflict folder over to the {targetPath} folder in this Umbraco installation.
@@ -102,7 +112,7 @@ public CodeEditorConfigurationEditor()
Key = FontSize,
Name = "Font size",
Description = @"Set the font size. The value must be a valid CSS font-size value. The default size is 'small'.",
- View = IOHelper.ResolveUrl(TextInputDataEditor.DataEditorViewPath),
+ View = ioHelper.ResolveRelativeOrVirtualUrl(TextInputDataEditor.DataEditorViewPath),
Config = new Dictionary
{
{ Constants.Conventions.ConfigurationFieldAliases.Items, new[] {
@@ -149,7 +159,7 @@ public CodeEditorConfigurationEditor()
Key = MinLines,
Name = "Minimum lines",
Description = "Set the minimum number of lines that the editor will be. The default is 12 lines.",
- View = IOHelper.ResolveUrl(NumberInputDataEditor.DataEditorViewPath)
+ View = ioHelper.ResolveRelativeOrVirtualUrl(NumberInputDataEditor.DataEditorViewPath)
});
DefaultConfiguration.Add(MaxLines, 30);
@@ -158,7 +168,7 @@ public CodeEditorConfigurationEditor()
Key = MaxLines,
Name = "Maximum lines",
Description = "Set the maximum number of lines that the editor can be. If left empty, the editor will not auto-scale.",
- View = IOHelper.ResolveUrl(NumberInputDataEditor.DataEditorViewPath)
+ View = ioHelper.ResolveRelativeOrVirtualUrl(NumberInputDataEditor.DataEditorViewPath)
});
}
}
diff --git a/src/Umbraco.Community.Contentment/DataEditors/CodeEditor/CodeEditorDataEditor.cs b/src/Umbraco.Community.Contentment/DataEditors/CodeEditor/CodeEditorDataEditor.cs
index bc0331de..c50cc19b 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/CodeEditor/CodeEditorDataEditor.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/CodeEditor/CodeEditorDataEditor.cs
@@ -3,9 +3,22 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
+#if NET472
+using Umbraco.Core.Hosting;
+using Umbraco.Core.IO;
using Umbraco.Core.Logging;
using Umbraco.Core.PropertyEditors;
using Umbraco.Web.PropertyEditors;
+#else
+using Microsoft.Extensions.Logging;
+using Umbraco.Cms.Core.Hosting;
+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;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
@@ -24,12 +37,61 @@ internal sealed class CodeEditorDataEditor : DataEditor
internal const string DataEditorViewPath = Constants.Internals.EditorsPathRoot + "code-editor.html";
internal const string DataEditorIcon = "icon-fa fa-code";
- public CodeEditorDataEditor(ILogger logger)
+ private readonly IHostingEnvironment _hostingEnvironment;
+ private readonly IIOHelper _ioHelper;
+
+#if NET472
+ public CodeEditorDataEditor(
+ IHostingEnvironment hostingEnvironment,
+ IIOHelper ioHelper,
+ ILogger logger)
: base(logger)
- { }
+ {
+ _hostingEnvironment = hostingEnvironment;
+ _ioHelper = ioHelper;
+ }
+#else
+ private readonly IDataTypeService _dataTypeService;
+ private readonly ILocalizationService _localizationService;
+ private readonly ILocalizedTextService _localizedTextService;
+ private readonly IShortStringHelper _shortStringHelper;
+ private readonly IJsonSerializer _jsonSerializer;
+
+ public CodeEditorDataEditor(
+ IDataValueEditorFactory dataValueEditorFactory,
+ IHostingEnvironment hostingEnvironment,
+ IIOHelper ioHelper,
+ ILoggerFactory loggerFactory,
+ IDataTypeService dataTypeService,
+ ILocalizationService localizationService,
+ ILocalizedTextService localizedTextService,
+ IShortStringHelper shortStringHelper,
+ IJsonSerializer jsonSerializer)
+ : base(dataValueEditorFactory)
+ {
+ _hostingEnvironment = hostingEnvironment;
+ _ioHelper = ioHelper;
+ _dataTypeService = dataTypeService;
+ _localizationService = localizationService;
+ _localizedTextService = localizedTextService;
+ _shortStringHelper = shortStringHelper;
+ _jsonSerializer = jsonSerializer;
+ }
+#endif
- protected override IConfigurationEditor CreateConfigurationEditor() => new CodeEditorConfigurationEditor();
+ protected override IConfigurationEditor CreateConfigurationEditor() => new CodeEditorConfigurationEditor(
+ _hostingEnvironment,
+ _ioHelper);
+#if NET472
protected override IDataValueEditor CreateValueEditor() => new TextOnlyValueEditor(Attribute);
+#else
+ protected override IDataValueEditor CreateValueEditor() => new TextOnlyValueEditor(
+ Attribute,
+ _localizedTextService,
+ _shortStringHelper,
+ _jsonSerializer,
+ _ioHelper);
+#endif
}
}
diff --git a/src/Umbraco.Community.Contentment/DataEditors/CodeEditor/CodeEditorValueConverter.cs b/src/Umbraco.Community.Contentment/DataEditors/CodeEditor/CodeEditorValueConverter.cs
index 2c331f35..7771fdf8 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/CodeEditor/CodeEditorValueConverter.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/CodeEditor/CodeEditorValueConverter.cs
@@ -4,9 +4,15 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
+#if NET472
using Umbraco.Core;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
+#else
+using Umbraco.Cms.Core.Models.PublishedContent;
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Extensions;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
diff --git a/src/Umbraco.Community.Contentment/DataEditors/ConfigurationEditor/ConfigurationEditorDataEditor.cs b/src/Umbraco.Community.Contentment/DataEditors/ConfigurationEditor/ConfigurationEditorDataEditor.cs
index e5f9dbb1..5dc2c356 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/ConfigurationEditor/ConfigurationEditorDataEditor.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/ConfigurationEditor/ConfigurationEditorDataEditor.cs
@@ -3,6 +3,12 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
+#if NET472
+using UmbConstants = Umbraco.Core.Constants;
+#else
+using UmbConstants = Umbraco.Cms.Core.Constants;
+#endif
+
namespace Umbraco.Community.Contentment.DataEditors
{
internal sealed class ConfigurationEditorDataEditor
@@ -11,6 +17,6 @@ internal sealed class ConfigurationEditorDataEditor
internal const string DataEditorName = Constants.Internals.DataEditorNamePrefix + "Configuration Editor";
internal const string DataEditorViewPath = Constants.Internals.EditorsPathRoot + "configuration-editor.html";
internal const string DataEditorOverlayViewPath = Constants.Internals.EditorsPathRoot + "configuration-editor.overlay.html";
- internal const string DataEditorIcon = Core.Constants.Icons.Macro;
+ internal const string DataEditorIcon = UmbConstants.Icons.Macro;
}
}
diff --git a/src/Umbraco.Community.Contentment/DataEditors/ConfigurationEditor/ConfigurationEditorModel.cs b/src/Umbraco.Community.Contentment/DataEditors/ConfigurationEditor/ConfigurationEditorModel.cs
index 78505d1a..0005fcb1 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/ConfigurationEditor/ConfigurationEditorModel.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/ConfigurationEditor/ConfigurationEditorModel.cs
@@ -7,7 +7,11 @@
using System.ComponentModel;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
+#if NET472
using Umbraco.Core.PropertyEditors;
+#else
+using Umbraco.Cms.Core.PropertyEditors;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
diff --git a/src/Umbraco.Community.Contentment/DataEditors/ConfigurationEditor/ConfigurationEditorUtility.cs b/src/Umbraco.Community.Contentment/DataEditors/ConfigurationEditor/ConfigurationEditorUtility.cs
index 5e248f66..d34c2785 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/ConfigurationEditor/ConfigurationEditorUtility.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/ConfigurationEditor/ConfigurationEditorUtility.cs
@@ -8,8 +8,18 @@
using System.ComponentModel;
using System.Linq;
using Umbraco.Community.Contentment.Composing;
+#if NET472
using Umbraco.Core;
using Umbraco.Core.PropertyEditors;
+using Umbraco.Core.Strings;
+using UmbConstants = Umbraco.Core.Constants;
+#else
+using Umbraco.Cms.Core;
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Cms.Core.Strings;
+using Umbraco.Extensions;
+using UmbConstants = Umbraco.Cms.Core.Constants;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
@@ -40,13 +50,13 @@ public T GetConfigurationEditor(string key)
return default;
}
- public ConfigurationEditorModel GetConfigurationEditorModel(bool ignoreFields = false)
+ public ConfigurationEditorModel GetConfigurationEditorModel(IShortStringHelper shortStringHelper, bool ignoreFields = false)
where T : IContentmentEditorItem
{
- return GetConfigurationEditorModel(GetConfigurationEditor(typeof(T).GetFullNameWithAssembly()), ignoreFields);
+ return GetConfigurationEditorModel(GetConfigurationEditor(typeof(T).GetFullNameWithAssembly()), shortStringHelper, ignoreFields);
}
- public ConfigurationEditorModel GetConfigurationEditorModel(T item, bool ignoreFields = false)
+ public ConfigurationEditorModel GetConfigurationEditorModel(T item, IShortStringHelper shortStringHelper, bool ignoreFields = false)
where T : IContentmentEditorItem
{
var type = item.GetType();
@@ -58,9 +68,9 @@ public ConfigurationEditorModel GetConfigurationEditorModel(T item, bool igno
return new ConfigurationEditorModel
{
Key = type.GetFullNameWithAssembly(),
- Name = item.Name ?? type.Name.SplitPascalCasing(),
+ Name = item.Name ?? type.Name.SplitPascalCasing(shortStringHelper),
Description = item.Description,
- Icon = item.Icon ?? Core.Constants.Icons.DefaultIcon,
+ Icon = item.Icon ?? UmbConstants.Icons.DefaultIcon,
Group = item.Group,
Fields = fields,
DefaultValues = item.DefaultValues,
@@ -68,8 +78,8 @@ public ConfigurationEditorModel GetConfigurationEditorModel(T item, bool igno
};
}
- public IEnumerable GetConfigurationEditorModels(bool ignoreFields = false)
- where T : IContentmentEditorItem
+ public IEnumerable GetConfigurationEditorModels(IShortStringHelper shortStringHelper, bool ignoreFields = false)
+ where T : IContentmentEditorItem
{
var models = new List();
@@ -77,7 +87,7 @@ public IEnumerable GetConfigurationEditorModels(boo
{
if (item is T editorItem)
{
- models.Add(GetConfigurationEditorModel(editorItem, ignoreFields));
+ models.Add(GetConfigurationEditorModel(editorItem, shortStringHelper, ignoreFields));
}
}
diff --git a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlockPreview.cshtml b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlockPreview.cshtml
index 2426238d..4cd7bd3e 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlockPreview.cshtml
+++ b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlockPreview.cshtml
@@ -2,7 +2,7 @@
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. *@
-@inherits Umbraco.Web.Mvc.ContentBlockPreviewView
+@inherits ContentBlockPreviewView
@Model.Element.Key
diff --git a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlockPreviewModel.cs b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlockPreviewModel.cs
index 4bf97bf9..463132c8 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlockPreviewModel.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlockPreviewModel.cs
@@ -3,8 +3,13 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
+#if NET472
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web.Models;
+#else
+using Umbraco.Cms.Core.Models;
+using Umbraco.Cms.Core.Models.PublishedContent;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
diff --git a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlockPreviewView.cs b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlockPreviewView.cs
index f8851469..2c7faede 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlockPreviewView.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlockPreviewView.cs
@@ -4,12 +4,23 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
+#if NET472
using System.Web.Mvc;
using Umbraco.Community.Contentment.DataEditors;
using Umbraco.Core;
using Umbraco.Core.Models.PublishedContent;
+#else
+using Microsoft.AspNetCore.Mvc.Rendering;
+using Umbraco.Cms.Core.Models.PublishedContent;
+using Umbraco.Community.Contentment.DataEditors;
+using Umbraco.Extensions;
+#endif
+#if NET472
namespace Umbraco.Web.Mvc
+#else
+namespace Umbraco.Cms.Web.Common.Views
+#endif
{
public abstract class ContentBlockPreviewView
: ContentBlockPreviewView
@@ -20,6 +31,7 @@ public abstract class ContentBlockPreviewView(string key, Action action)
@@ -52,5 +64,45 @@ void setProperty(string key, Action action)
base.SetViewData(viewData);
}
+#else
+ public override ViewContext ViewContext
+ {
+ get => base.ViewContext;
+ set => base.ViewContext = SetViewData(value);
+ }
+
+ protected ViewContext SetViewData(ViewContext viewCtx)
+ {
+ void setProperty(string key, Action action)
+ {
+ if (viewCtx.ViewData.TryGetValueAs(key, out T value) == true)
+ {
+ action(value);
+ }
+ }
+
+ var model = new ContentBlockPreviewModel();
+
+ setProperty("content", (x) => model.Content = x);
+ setProperty("element", (x) => model.Element = x);
+ setProperty("elementIndex", (x) => model.ElementIndex = x);
+ setProperty("contentIcon", (x) => model.ContentTypeIcon = x);
+ setProperty("elementIcon", (x) => model.ElementTypeIcon = x);
+
+ if (model.Element == null && viewCtx.ViewData.Model is TPublishedElement element)
+ {
+ model.Element = element;
+ }
+
+ if (model.Content == null && UmbracoContext?.PublishedRequest?.PublishedContent is TPublishedContent content)
+ {
+ model.Content = content;
+ }
+
+ viewCtx.ViewData.Model = model;
+
+ return viewCtx;
+ }
+#endif
}
}
diff --git a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksApiController.cs b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksApiController.cs
index 42503c2b..7cc451bd 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksApiController.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksApiController.cs
@@ -3,6 +3,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
+#if NET472
using System;
using System.Collections.Generic;
using System.Net;
@@ -15,9 +16,32 @@
using Umbraco.Web.Editors;
using Umbraco.Web.Mvc;
using Umbraco.Web.WebApi;
+#else
+using System;
+using System.Collections.Generic;
+using System.IO;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.Abstractions;
+using Microsoft.AspNetCore.Mvc.ModelBinding;
+using Microsoft.AspNetCore.Mvc.Razor;
+using Microsoft.AspNetCore.Mvc.Rendering;
+using Microsoft.AspNetCore.Mvc.ViewEngines;
+using Microsoft.AspNetCore.Mvc.ViewFeatures;
+using Microsoft.AspNetCore.Routing;
+using Microsoft.Extensions.Logging;
+using Newtonsoft.Json.Linq;
+using Umbraco.Cms.Core.Models.PublishedContent;
+using Umbraco.Cms.Core.Services;
+using Umbraco.Cms.Core.Web;
+using Umbraco.Cms.Web.BackOffice.Controllers;
+using Umbraco.Cms.Web.Common.Attributes;
+using Umbraco.Community.Contentment.Web.PublishedCache;
+using Umbraco.Extensions;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
+#if NET472
[PluginController(Constants.Internals.PluginControllerName), IsBackOffice]
public sealed class ContentBlocksApiController : UmbracoAuthorizedJsonController
{
@@ -83,7 +107,7 @@ public HttpResponseMessage GetPreviewMarkup([FromBody] JObject item, int element
viewData.Add(nameof(elementIcon), elementIcon);
}
- var markup = default(string);
+ string markup;
try
{
@@ -107,4 +131,160 @@ public HttpResponseMessage GetPreviewMarkup([FromBody] JObject item, int element
return Request.CreateResponse(HttpStatusCode.OK, new { elementKey, markup });
}
}
+#else
+ [PluginController(Constants.Internals.PluginControllerName), IsBackOffice]
+ public sealed class ContentBlocksApiController : UmbracoAuthorizedJsonController
+ {
+ private readonly ILogger _logger;
+ private readonly IPublishedModelFactory _publishedModelFactory;
+ private readonly IContentTypeService _contentTypeService;
+ private readonly IUmbracoContextAccessor _umbracoContextAccessor;
+ private readonly IModelMetadataProvider _modelMetadataProvider;
+ private readonly IRazorViewEngine _viewEngine;
+ private readonly ITempDataProvider _tempDataProvider;
+
+ public ContentBlocksApiController(
+ ILogger logger,
+ IPublishedModelFactory publishedModelFactory,
+ IContentTypeService contentTypeService,
+ IUmbracoContextAccessor umbracoContextAccessor,
+ IModelMetadataProvider modelMetadataProvider,
+ IRazorViewEngine viewEngine,
+ ITempDataProvider tempDataProvider)
+ {
+ _logger = logger;
+ _publishedModelFactory = publishedModelFactory;
+ _contentTypeService = contentTypeService;
+ _umbracoContextAccessor = umbracoContextAccessor;
+ _modelMetadataProvider = modelMetadataProvider;
+ _viewEngine = viewEngine;
+ _tempDataProvider = tempDataProvider;
+ }
+
+ [HttpPost]
+ public ActionResult GetPreviewMarkup([FromBody] JObject item, int elementIndex, Guid elementKey, int contentId)
+ {
+ var preview = true;
+ var umbracoContext = _umbracoContextAccessor.GetRequiredUmbracoContext();
+
+ var content = umbracoContext.Content.GetById(true, contentId);
+ if (content == null)
+ {
+ _logger.LogDebug($"Unable to retrieve content for ID '{contentId}', it is most likely a new unsaved page.");
+ }
+
+ var element = default(IPublishedElement);
+ var block = item.ToObject();
+ if (block != null && block.ElementType.Equals(Guid.Empty) == false)
+ {
+ if (ContentTypeCacheHelper.TryGetAlias(block.ElementType, out var alias, _contentTypeService) == true)
+ {
+ var contentType = umbracoContext.PublishedSnapshot.Content.GetContentType(alias);
+ if (contentType != null && contentType.IsElement == true)
+ {
+ var properties = new List();
+
+ foreach (var thing in block.Value)
+ {
+ var propType = contentType.GetPropertyType(thing.Key);
+ if (propType != null)
+ {
+ properties.Add(new DetachedPublishedProperty(propType, null, thing.Value, preview));
+ }
+ }
+
+ element = _publishedModelFactory.CreateModel(new DetachedPublishedElement(block.Key, contentType, properties));
+ }
+ }
+ }
+
+ var viewData = new ViewDataDictionary(_modelMetadataProvider, new ModelStateDictionary())
+ {
+ Model = element,
+ [nameof(content)] = content,
+ [nameof(element)] = element,
+ [nameof(elementIndex)] = elementIndex,
+
+ };
+
+ if (ContentTypeCacheHelper.TryGetIcon(content.ContentType.Alias, out var contentIcon, _contentTypeService) == true)
+ {
+ viewData.Add(nameof(contentIcon), contentIcon);
+ }
+
+ if (ContentTypeCacheHelper.TryGetIcon(element.ContentType.Alias, out var elementIcon, _contentTypeService) == true)
+ {
+ viewData.Add(nameof(elementIcon), elementIcon);
+ }
+
+ string markup;
+
+ try
+ {
+ markup = RenderPartialViewToString(element.ContentType.Alias, viewData);
+ }
+ catch (InvalidCastException icex)
+ {
+ // NOTE: This type of exception happens on a new (unsaved) page, when the context becomes the parent page,
+ // and the preview view is strongly typed to the current page's model type.
+ markup = "
Unable to render the preview until the page has been saved.
";
+
+ _logger.LogError(ex, "Error rendering preview view.");
+ }
+
+ return new ObjectResult(new { elementKey, markup });
+ }
+
+ // HACK: [v9] [LK:2021-05-13] Got it working. Future rewrite, make nicer.
+ // The following code has been hacked and butchered from:
+ // https://github.com/aspnet/Entropy/blob/master/samples/Mvc.RenderViewToString/RazorViewToStringRenderer.cs
+ // https://gist.github.com/ahmad-moussawi/1643d703c11699a6a4046e57247b4d09
+ private string RenderPartialViewToString(string viewName, ViewDataDictionary viewData)
+ {
+ IView view = default;
+
+ // TODO: [v9] [LK:2021-05-13] Implement the custom partial-view paths.
+ // e.g. "~/Views/Partials/Blocks/{0}.cshtml", "~/Views/Partials/Blocks/Default.cshtml", "~/App_Plugins/Contentment/render/ContentBlockPreview.cshtml"
+
+ var getViewResult = _viewEngine.GetView(executingFilePath: null, viewPath: viewName, isMainPage: true);
+ if (getViewResult.Success)
+ {
+ view = getViewResult.View;
+ }
+
+ var actionContext = new ActionContext(HttpContext, new RouteData(), new ActionDescriptor());
+ var findViewResult = _viewEngine.FindView(actionContext, viewName, isMainPage: true);
+ if (findViewResult.Success)
+ {
+ view = findViewResult.View;
+ }
+
+ if (view == default)
+ {
+ var messages = new List { $"Unable to find view '{viewName}'. The following locations were searched:" };
+ messages.AddRange(getViewResult.SearchedLocations);
+ messages.AddRange(findViewResult.SearchedLocations);
+
+ var errorMessage = string.Join(Environment.NewLine, messages);
+
+ throw new InvalidOperationException(errorMessage);
+ }
+
+ using var output = new StringWriter();
+
+ var tempDataDictionary = new TempDataDictionary(actionContext.HttpContext, _tempDataProvider);
+ var viewContext = new ViewContext(actionContext, view, viewData, tempDataDictionary, output, new HtmlHelperOptions());
+
+ view.RenderAsync(viewContext).GetAwaiter().GetResult();
+
+ return output.ToString();
+ }
+ }
+#endif
}
diff --git a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksConfigurationEditor.cs b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksConfigurationEditor.cs
index 5f129175..ecb08c1f 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksConfigurationEditor.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksConfigurationEditor.cs
@@ -7,11 +7,21 @@
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json.Linq;
+#if NET472
using Umbraco.Core;
using Umbraco.Core.IO;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
+using Umbraco.Core.Strings;
+#else
+using Umbraco.Cms.Core.IO;
+using Umbraco.Cms.Core.Models;
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Cms.Core.Services;
+using Umbraco.Cms.Core.Strings;
+using Umbraco.Extensions;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
@@ -20,6 +30,7 @@ internal sealed class ContentBlocksConfigurationEditor : ConfigurationEditor
// TODO: expire the local cache `_elementTypes` when a new element type is added. [LK:2021-08-16]
private readonly Dictionary _elementTypes;
private readonly Lazy> _elementBlueprints;
+ private readonly IIOHelper _ioHelper;
private readonly ConfigurationEditorUtility _utility;
internal const string DisplayMode = "displayMode";
@@ -27,16 +38,19 @@ internal sealed class ContentBlocksConfigurationEditor : ConfigurationEditor
public ContentBlocksConfigurationEditor(
IContentService contentService,
IContentTypeService contentTypeService,
- ConfigurationEditorUtility utility)
+ ConfigurationEditorUtility utility,
+ IShortStringHelper shortStringHelper,
+ IIOHelper ioHelper)
: base()
{
+ _ioHelper = ioHelper;
_utility = utility;
// NOTE: Gets all the elementTypes and blueprints upfront, rather than several hits inside the loop.
_elementTypes = contentTypeService.GetAllElementTypes().ToDictionary(x => x.Key);
_elementBlueprints = new Lazy>(() => contentService.GetBlueprintsForContentTypes(_elementTypes.Values.Select(x => x.Id).ToArray()).ToLookup(x => x.ContentTypeId));
- var displayModes = utility.GetConfigurationEditorModels();
+ var displayModes = utility.GetConfigurationEditorModels(shortStringHelper);
// NOTE: Sets the default display mode to be the Blocks.
var defaultDisplayMode = displayModes.FirstOrDefault(x => x.Key.InvariantEquals(typeof(BlocksDisplayMode).GetFullNameWithAssembly()));
@@ -50,21 +64,21 @@ public ContentBlocksConfigurationEditor(
Key = DisplayMode,
Name = "Display mode",
Description = "Select and configure how to display the blocks in the editor.",
- View = IOHelper.ResolveUrl(ConfigurationEditorDataEditor.DataEditorViewPath),
+ View = ioHelper.ResolveRelativeOrVirtualUrl(ConfigurationEditorDataEditor.DataEditorViewPath),
Config = new Dictionary()
{
{ Constants.Conventions.ConfigurationFieldAliases.AddButtonLabelKey, "contentment_configureDisplayMode" },
{ Constants.Conventions.ConfigurationFieldAliases.Items, displayModes },
{ MaxItemsConfigurationField.MaxItems, 1 },
{ DisableSortingConfigurationField.DisableSorting, Constants.Values.True },
- { Constants.Conventions.ConfigurationFieldAliases.OverlayView, IOHelper.ResolveUrl(ConfigurationEditorDataEditor.DataEditorOverlayViewPath) },
+ { Constants.Conventions.ConfigurationFieldAliases.OverlayView, ioHelper.ResolveRelativeOrVirtualUrl(ConfigurationEditorDataEditor.DataEditorOverlayViewPath) },
{ EnableDevModeConfigurationField.EnableDevMode, Constants.Values.True },
}
});
- Fields.Add(new ContentBlocksTypesConfigurationField(_elementTypes.Values));
+ Fields.Add(new ContentBlocksTypesConfigurationField(_elementTypes.Values, ioHelper));
Fields.Add(new EnableFilterConfigurationField());
- Fields.Add(new MaxItemsConfigurationField());
+ Fields.Add(new MaxItemsConfigurationField(ioHelper));
Fields.Add(new DisableSortingConfigurationField());
Fields.Add(new EnableDevModeConfigurationField());
}
@@ -166,7 +180,7 @@ public override IDictionary ToValueEditor(object configuration)
if (config.ContainsKey(Constants.Conventions.ConfigurationFieldAliases.OverlayView) == false)
{
- config.Add(Constants.Conventions.ConfigurationFieldAliases.OverlayView, IOHelper.ResolveUrl(ContentBlocksDataEditor.DataEditorOverlayViewPath));
+ config.Add(Constants.Conventions.ConfigurationFieldAliases.OverlayView, _ioHelper.ResolveRelativeOrVirtualUrl(ContentBlocksDataEditor.DataEditorOverlayViewPath));
}
return config;
diff --git a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksDataEditor.cs b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksDataEditor.cs
index 24e9fa7a..a26422be 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksDataEditor.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksDataEditor.cs
@@ -6,9 +6,23 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
+#if NET472
using Umbraco.Core;
+using Umbraco.Core.IO;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
+using Umbraco.Core.Strings;
+using UmbConstants = Umbraco.Core.Constants;
+#else
+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;
+using UmbConstants = Umbraco.Cms.Core.Constants;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
@@ -24,21 +38,54 @@ public sealed class ContentBlocksDataEditor : IDataEditor
private readonly IContentTypeService _contentTypeService;
private readonly IDataTypeService _dataTypeService;
private readonly Lazy _propertyEditors;
+ private readonly IShortStringHelper _shortStringHelper;
private readonly ConfigurationEditorUtility _utility;
+ private readonly IIOHelper _ioHelper;
+#if NET472
public ContentBlocksDataEditor(
IContentService contentService,
IContentTypeService contentTypeService,
IDataTypeService dataTypeService,
Lazy propertyEditors,
- ConfigurationEditorUtility utility)
+ IShortStringHelper shortStringHelper,
+ ConfigurationEditorUtility utility,
+ IIOHelper ioHelper)
{
_contentService = contentService;
_contentTypeService = contentTypeService;
_dataTypeService = dataTypeService;
_propertyEditors = propertyEditors;
+ _shortStringHelper = shortStringHelper;
_utility = utility;
+ _ioHelper = ioHelper;
}
+#else
+ private readonly ILocalizedTextService _localizedTextService;
+ private readonly IJsonSerializer _jsonSerializer;
+
+ public ContentBlocksDataEditor(
+ IContentService contentService,
+ IContentTypeService contentTypeService,
+ Lazy propertyEditors,
+ IDataTypeService dataTypeService,
+ ILocalizedTextService localizedTextService,
+ IShortStringHelper shortStringHelper,
+ IJsonSerializer jsonSerializer,
+ ConfigurationEditorUtility utility,
+ IIOHelper ioHelper)
+ {
+ _contentService = contentService;
+ _contentTypeService = contentTypeService;
+ _dataTypeService = dataTypeService;
+ _localizedTextService = localizedTextService;
+ _shortStringHelper = shortStringHelper;
+ _jsonSerializer = jsonSerializer;
+ _propertyEditors = propertyEditors;
+ _utility = utility;
+ _ioHelper = ioHelper;
+ }
+#endif
public string Alias => DataEditorAlias;
@@ -48,7 +95,7 @@ public ContentBlocksDataEditor(
public string Icon => DataEditorIcon;
- public string Group => Core.Constants.PropertyEditors.Groups.RichContent;
+ public string Group => UmbConstants.PropertyEditors.Groups.RichContent;
public bool IsDeprecated => false;
@@ -56,20 +103,33 @@ public ContentBlocksDataEditor(
public IPropertyIndexValueFactory PropertyIndexValueFactory => new DefaultPropertyIndexValueFactory();
- public IConfigurationEditor GetConfigurationEditor() => new ContentBlocksConfigurationEditor(_contentService, _contentTypeService, _utility);
+ public IConfigurationEditor GetConfigurationEditor() => new ContentBlocksConfigurationEditor(_contentService, _contentTypeService, _utility, _shortStringHelper, _ioHelper);
public IDataValueEditor GetValueEditor()
{
- return new ContentBlocksDataValueEditor(_contentTypeService, _dataTypeService, _propertyEditors.Value)
+#if NET472
+ return new ContentBlocksDataValueEditor(
+ _contentTypeService,
+ _dataTypeService,
+ _propertyEditors.Value)
+#else
+ return new ContentBlocksDataValueEditor(
+ _contentTypeService,
+ _propertyEditors.Value,
+ _dataTypeService,
+ _localizedTextService,
+ _shortStringHelper,
+ _jsonSerializer)
+#endif
{
ValueType = ValueTypes.Json,
- View = DataEditorViewPath,
+ View = _ioHelper.ResolveRelativeOrVirtualUrl(DataEditorViewPath),
};
}
public IDataValueEditor GetValueEditor(object configuration)
{
- var view = DataEditorViewPath;
+ var view = default(string);
if (configuration is Dictionary config)
{
@@ -93,11 +153,21 @@ public IDataValueEditor GetValueEditor(object configuration)
}
}
+#if NET472
return new ContentBlocksDataValueEditor(_contentTypeService, _dataTypeService, _propertyEditors.Value)
+#else
+ return new ContentBlocksDataValueEditor(
+ _contentTypeService,
+ _propertyEditors.Value,
+ _dataTypeService,
+ _localizedTextService,
+ _shortStringHelper,
+ _jsonSerializer)
+#endif
{
Configuration = configuration,
ValueType = ValueTypes.Json,
- View = view,
+ View = _ioHelper.ResolveRelativeOrVirtualUrl(view ?? DataEditorViewPath),
};
}
}
diff --git a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksDataValueEditor.cs b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksDataValueEditor.cs
index 9b1f3e44..ca06b3c6 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksDataValueEditor.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksDataValueEditor.cs
@@ -15,11 +15,21 @@
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
+#if NET472
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Editors;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
+#else
+using Umbraco.Cms.Core.Models;
+using Umbraco.Cms.Core.Models.Editors;
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Cms.Core.Serialization;
+using Umbraco.Cms.Core.Services;
+using Umbraco.Cms.Core.Strings;
+using Umbraco.Extensions;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
@@ -29,29 +39,53 @@ internal sealed class ContentBlocksDataValueEditor : DataValueEditor
private readonly Lazy> _elementTypes;
private readonly PropertyEditorCollection _propertyEditors;
- public ContentBlocksDataValueEditor(
+#if NET472
+public ContentBlocksDataValueEditor(
IContentTypeService contentTypeService,
IDataTypeService dataTypeService,
PropertyEditorCollection propertyEditors)
: base()
+#else
+ public ContentBlocksDataValueEditor(
+ IContentTypeService contentTypeService,
+ PropertyEditorCollection propertyEditors,
+ IDataTypeService dataTypeService,
+ ILocalizedTextService localizedTextService,
+ IShortStringHelper shortStringHelper,
+ IJsonSerializer jsonSerializer)
+ : base(localizedTextService, shortStringHelper, jsonSerializer)
+#endif
{
_dataTypeService = dataTypeService;
_elementTypes = new Lazy>(() => contentTypeService.GetAllElementTypes().ToDictionary(x => x.Key));
_propertyEditors = propertyEditors;
}
+
+#if NET472
public override object ToEditor(Property property, IDataTypeService dataTypeService, string culture = null, string segment = null)
+#else
+ public override object ToEditor(IProperty property, string culture = null, string segment = null)
+#endif
{
var value = property.GetValue(culture, segment)?.ToString();
if (string.IsNullOrWhiteSpace(value) == true)
{
+#if NET472
return base.ToEditor(property, dataTypeService, culture, segment);
+#else
+ return base.ToEditor(property, culture, segment);
+#endif
}
var blocks = JsonConvert.DeserializeObject>(value);
if (blocks == null)
{
+#if NET472
return base.ToEditor(property, dataTypeService, culture, segment);
+#else
+ return base.ToEditor(property, culture, segment);
+#endif
}
foreach (var block in blocks)
@@ -86,7 +120,11 @@ public override object ToEditor(Property property, IDataTypeService dataTypeServ
continue;
}
+#if NET472
var convertedValue = propertyEditor.GetValueEditor()?.ToEditor(fakeProperty, dataTypeService);
+#else
+ var convertedValue = propertyEditor.GetValueEditor()?.ToEditor(fakeProperty);
+#endif
block.Value[key] = convertedValue != null
? JToken.FromObject(convertedValue)
diff --git a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksTypesConfigurationField.cs b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksTypesConfigurationField.cs
index 0fdf4c3a..3c2ef2e0 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksTypesConfigurationField.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksTypesConfigurationField.cs
@@ -5,10 +5,17 @@
using System.Collections.Generic;
using System.Linq;
+#if NET472
using Umbraco.Core;
using Umbraco.Core.IO;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
+#else
+using Umbraco.Cms.Core.IO;
+using Umbraco.Cms.Core.Models;
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Extensions;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
@@ -16,8 +23,12 @@ internal sealed class ContentBlocksTypesConfigurationField : ConfigurationField
{
internal const string ContentBlockTypes = "contentBlockTypes";
- public ContentBlocksTypesConfigurationField(IEnumerable elementTypes)
+ private readonly IIOHelper _ioHelper;
+
+ public ContentBlocksTypesConfigurationField(IEnumerable elementTypes, IIOHelper ioHelper)
{
+ _ioHelper = ioHelper;
+
var items = elementTypes
.OrderBy(x => x.Name)
.Select(x => new ConfigurationEditorModel
@@ -37,13 +48,13 @@ public ContentBlocksTypesConfigurationField(IEnumerable elementTyp
Key = ContentBlockTypes;
Name = "Block types";
Description = "Configure the block types to use.";
- View = IOHelper.ResolveUrl(ConfigurationEditorDataEditor.DataEditorViewPath);
+ View = ioHelper.ResolveRelativeOrVirtualUrl(ConfigurationEditorDataEditor.DataEditorViewPath);
Config = new Dictionary
{
{ Constants.Conventions.ConfigurationFieldAliases.AddButtonLabelKey, "contentment_configureElementType" },
{ "allowDuplicates", Constants.Values.False },
{ EnableFilterConfigurationField.EnableFilter, Constants.Values.True },
- { Constants.Conventions.ConfigurationFieldAliases.OverlayView, IOHelper.ResolveUrl(ConfigurationEditorDataEditor.DataEditorOverlayViewPath) },
+ { Constants.Conventions.ConfigurationFieldAliases.OverlayView, ioHelper.ResolveRelativeOrVirtualUrl(ConfigurationEditorDataEditor.DataEditorOverlayViewPath) },
{ Constants.Conventions.ConfigurationFieldAliases.Items, items },
{ EnableDevModeConfigurationField.EnableDevMode, Constants.Values.True },
};
@@ -57,7 +68,7 @@ private IEnumerable GetConfigurationFields(IContentType cont
{
Key = "elementType",
Name = "Element type",
- View = IOHelper.ResolveUrl(Constants.Internals.EditorsPathRoot + "readonly-node-preview.html"),
+ View = _ioHelper.ResolveRelativeOrVirtualUrl(Constants.Internals.EditorsPathRoot + "readonly-node-preview.html"),
Config = new Dictionary
{
{ "name", contentType.Name },
@@ -78,7 +89,7 @@ private IEnumerable GetConfigurationFields(IContentType cont
Key = "overlaySize",
Name = "Editor overlay size",
Description = "Select the size of the overlay editing panel. By default this is set to 'small'. However if the editor fields require a wider panel, please select 'medium' or 'large'.",
- View = IOHelper.ResolveUrl(RadioButtonListDataListEditor.DataEditorViewPath),
+ View = _ioHelper.ResolveRelativeOrVirtualUrl(RadioButtonListDataListEditor.DataEditorViewPath),
Config = new Dictionary
{
{ Constants.Conventions.ConfigurationFieldAliases.Items, new[]
diff --git a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksValueConverter.cs b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksValueConverter.cs
index bb093bb3..6f206e9d 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksValueConverter.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksValueConverter.cs
@@ -7,11 +7,19 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using Umbraco.Community.Contentment.Web.PublishedCache;
+#if NET472
using Umbraco.Core;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using Umbraco.Web.PublishedCache;
+#else
+using Umbraco.Cms.Core.Models.PublishedContent;
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Cms.Core.PublishedCache;
+using Umbraco.Cms.Core.Services;
+using Umbraco.Extensions;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
@@ -62,7 +70,7 @@ public override object ConvertIntermediateToObject(IPublishedElement owner, IPub
if (ContentTypeCacheHelper.TryGetAlias(item.ElementType, out var alias, _contentTypeService) == false)
continue;
- var contentType = _publishedSnapshotAccessor.PublishedSnapshot.Content.GetContentType(alias);
+ var contentType = _publishedSnapshotAccessor.GetRequiredPublishedSnapshot().Content.GetContentType(alias);
if (contentType == null || contentType.IsElement == false)
continue;
diff --git a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksViewHelper.cs b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksViewHelper.cs
index d330e2ac..e3aa6da6 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksViewHelper.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentBlocksViewHelper.cs
@@ -3,6 +3,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
+#if NET472
using System.IO;
using System.Web;
using System.Web.Mvc;
@@ -49,3 +50,4 @@ internal static string RenderPartial(string partialName, ViewDataDictionary view
}
}
}
+#endif
diff --git a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentTypeCacheHelper.cs b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentTypeCacheHelper.cs
index 9189a352..e999872c 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentTypeCacheHelper.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/ContentTypeCacheHelper.cs
@@ -8,10 +8,17 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
+#if NET472
using System;
using System.Collections.Concurrent;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
+#else
+using System;
+using System.Collections.Concurrent;
+using Umbraco.Cms.Core.Models;
+using Umbraco.Cms.Core.Services;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
diff --git a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/DisplayModes/BlocksDisplayMode.cs b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/DisplayModes/BlocksDisplayMode.cs
index 00f680ed..21ca4759 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/DisplayModes/BlocksDisplayMode.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/DisplayModes/BlocksDisplayMode.cs
@@ -4,13 +4,27 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System.Collections.Generic;
+#if NET472
+using Umbraco.Core.IO;
using Umbraco.Core.PropertyEditors;
using UmbIcons = Umbraco.Core.Constants.Icons;
+#else
+using Umbraco.Cms.Core.IO;
+using Umbraco.Cms.Core.PropertyEditors;
+using UmbIcons = Umbraco.Cms.Core.Constants.Icons;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
internal class BlocksDisplayMode : IContentBlocksDisplayMode
{
+ private readonly IIOHelper _ioHelper;
+
+ public BlocksDisplayMode(IIOHelper ioHelper)
+ {
+ _ioHelper = ioHelper;
+ }
+
public string Name => "Blocks";
public string Description => "Blocks will be displayed in a list similar to the Block List editor.";
@@ -36,7 +50,7 @@ internal class BlocksDisplayMode : IContentBlocksDisplayMode
public IEnumerable Fields => new[]
{
- new NotesConfigurationField($@"
+ new NotesConfigurationField(_ioHelper, $@"A note about block type previews.
Currently, the preview feature for block types has not been implemented for the {Name} display mode and has been temporarily disabled.
", true),
diff --git a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/DisplayModes/ListDisplayMode.cs b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/DisplayModes/ListDisplayMode.cs
index 4601ff37..dcf34d8a 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/DisplayModes/ListDisplayMode.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/DisplayModes/ListDisplayMode.cs
@@ -4,12 +4,25 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System.Collections.Generic;
+#if NET472
+using Umbraco.Core.IO;
using Umbraco.Core.PropertyEditors;
+#else
+using Umbraco.Cms.Core.IO;
+using Umbraco.Cms.Core.PropertyEditors;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
internal class ListDisplayMode : IContentBlocksDisplayMode
{
+ private readonly IIOHelper _ioHelper;
+
+ public ListDisplayMode(IIOHelper ioHelper)
+ {
+ _ioHelper = ioHelper;
+ }
+
public string Name => "List";
public string Description => "Blocks will be displayed in a list similar to a content picker.";
@@ -29,7 +42,7 @@ internal class ListDisplayMode : IContentBlocksDisplayMode
public IEnumerable Fields => new ConfigurationField[]
{
- new NotesConfigurationField($@"
+ new NotesConfigurationField(_ioHelper, $@"A note about block type previews.
Unfortunately, the preview feature for block types is unsupported in the {Name} display mode and will be disabled.
", true),
diff --git a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/DisplayModes/StackDisplayMode.cs b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/DisplayModes/StackDisplayMode.cs
index e1b6f495..17e386eb 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/DisplayModes/StackDisplayMode.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/DisplayModes/StackDisplayMode.cs
@@ -4,7 +4,11 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System.Collections.Generic;
+#if NET472
using Umbraco.Core.PropertyEditors;
+#else
+using Umbraco.Cms.Core.PropertyEditors;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
diff --git a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/content-blocks.overlay.js b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/content-blocks.overlay.js
index d36583e5..14f75647 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/content-blocks.overlay.js
+++ b/src/Umbraco.Community.Contentment/DataEditors/ContentBlocks/content-blocks.overlay.js
@@ -111,7 +111,10 @@ angular.module("umbraco").controller("Umbraco.Community.Contentment.Overlays.Con
icon: elementType.icon,
key: String.CreateGuid()
};
-
+
+ // TODO: [v9] [LK] Review this, get error with blueprint API request, 404.
+ // "Failed to retrieve blueprint for id 1082"
+ // e.g. /umbraco/backoffice/umbracoapi/content/GetEmpty?blueprintId=1082&parentId=1076
var getScaffold = blueprint && blueprint.id > 0
? contentResource.getBlueprintScaffold(config.currentPageId, blueprint.id)
: contentResource.getScaffold(config.currentPageId, elementType.alias);
diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataListApiController.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataListApiController.cs
index 36d4b406..c90afc04 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataListApiController.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataListApiController.cs
@@ -4,15 +4,23 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System.Collections.Generic;
+using Newtonsoft.Json.Linq;
+#if NET472
using System.Net;
using System.Net.Http;
using System.Web.Http;
-using Newtonsoft.Json.Linq;
using Umbraco.Core;
using Umbraco.Core.PropertyEditors;
using Umbraco.Web.Editors;
using Umbraco.Web.Mvc;
using Umbraco.Web.WebApi;
+#else
+using Microsoft.AspNetCore.Mvc;
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Cms.Web.BackOffice.Controllers;
+using Umbraco.Cms.Web.Common.Attributes;
+using Umbraco.Extensions;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
@@ -27,7 +35,11 @@ public DataListApiController(PropertyEditorCollection propertyEditors)
}
[HttpPost]
+#if NET472
public HttpResponseMessage GetPreview([FromBody] JObject data)
+#else
+ public ActionResult GetPreview([FromBody] JObject data)
+#endif
{
var config = data.ToObject>();
@@ -38,10 +50,18 @@ public HttpResponseMessage GetPreview([FromBody] JObject data)
var valueEditorConfig = configurationEditor.ToValueEditor(config);
var valueEditor = propertyEditor.GetValueEditor(config);
+#if NET472
return Request.CreateResponse(HttpStatusCode.OK, new { config = valueEditorConfig, view = valueEditor.View, alias });
+#else
+ return new ObjectResult(new { config = valueEditorConfig, view = valueEditor.View, alias });
+#endif
}
+#if NET472
return Request.CreateResponse(HttpStatusCode.NotFound);
+#else
+ return new NotFoundResult();
+#endif
}
}
}
diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataListConfigurationEditor.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataListConfigurationEditor.cs
index 3cc8582b..a881feee 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataListConfigurationEditor.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataListConfigurationEditor.cs
@@ -6,9 +6,17 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
+#if NET472
using Umbraco.Core;
using Umbraco.Core.IO;
using Umbraco.Core.PropertyEditors;
+using Umbraco.Core.Strings;
+#else
+using Umbraco.Cms.Core.IO;
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Cms.Core.Strings;
+using Umbraco.Extensions;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
@@ -22,22 +30,26 @@ internal sealed class DataListConfigurationEditor : ConfigurationEditor
private readonly ConfigurationEditorUtility _utility;
- public DataListConfigurationEditor(ConfigurationEditorUtility utility)
+ public DataListConfigurationEditor(
+ ConfigurationEditorUtility utility,
+ IShortStringHelper shortStringHelper,
+ IIOHelper ioHelper)
: base()
{
_utility = utility;
- var configEditorViewPath = IOHelper.ResolveUrl(ConfigurationEditorDataEditor.DataEditorViewPath);
+ var configEditorViewPath = ioHelper.ResolveRelativeOrVirtualUrl(ConfigurationEditorDataEditor.DataEditorViewPath);
var defaultConfigEditorConfig = new Dictionary
{
{ MaxItemsConfigurationField.MaxItems, 1 },
{ DisableSortingConfigurationField.DisableSorting, Constants.Values.True },
- { Constants.Conventions.ConfigurationFieldAliases.OverlayView, IOHelper.ResolveUrl(ConfigurationEditorDataEditor.DataEditorOverlayViewPath) },
+ { Constants.Conventions.ConfigurationFieldAliases.OverlayView, ioHelper.ResolveRelativeOrVirtualUrl(ConfigurationEditorDataEditor.DataEditorOverlayViewPath) },
{ EnableDevModeConfigurationField.EnableDevMode, Constants.Values.True },
};
- var dataSources = new List(utility.GetConfigurationEditorModels());
- var listEditors = new List(utility.GetConfigurationEditorModels());
+ var dataSources = new List(utility.GetConfigurationEditorModels(shortStringHelper));
+ var listEditors = new List(utility.GetConfigurationEditorModels(shortStringHelper));
+
Fields.Add(new ConfigurationField
{
@@ -76,7 +88,7 @@ public DataListConfigurationEditor(ConfigurationEditorUtility utility)
{
Key = "preview",
Name = "Preview",
- View = IOHelper.ResolveUrl(DataListDataEditor.DataEditorPreviewViewPath)
+ View = ioHelper.ResolveRelativeOrVirtualUrl(DataListDataEditor.DataEditorPreviewViewPath)
});
}
diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataListDataEditor.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataListDataEditor.cs
index 710155a4..5d866844 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataListDataEditor.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataListDataEditor.cs
@@ -5,8 +5,23 @@
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
+#if NET472
using Umbraco.Core;
+using Umbraco.Core.IO;
using Umbraco.Core.PropertyEditors;
+using Umbraco.Core.Strings;
+using UmbConstants = Umbraco.Core.Constants;
+#else
+using Umbraco.Cms.Core;
+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;
+using UmbConstants = Umbraco.Cms.Core.Constants;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
@@ -20,9 +35,37 @@ public sealed class DataListDataEditor : IDataEditor
internal const string DataEditorIcon = "icon-fa fa-list-ul";
private readonly ConfigurationEditorUtility _utility;
-
- public DataListDataEditor(ConfigurationEditorUtility utility) => _utility = utility;
-
+ private readonly IShortStringHelper _shortStringHelper;
+ private readonly IIOHelper _ioHelper;
+
+#if NET472
+ public DataListDataEditor(
+ ConfigurationEditorUtility utility,
+ IShortStringHelper shortStringHelper,
+ IIOHelper ioHelper)
+ {
+ _utility = utility;
+ _shortStringHelper = shortStringHelper;
+ _ioHelper = ioHelper;
+ }
+#else
+ private readonly ILocalizedTextService _localizedTextService;
+ private readonly IJsonSerializer _jsonSerializer;
+
+ public DataListDataEditor(
+ ILocalizedTextService localizedTextService,
+ IShortStringHelper shortStringHelper,
+ IJsonSerializer jsonSerializer,
+ ConfigurationEditorUtility utility,
+ IIOHelper ioHelper)
+ {
+ _localizedTextService = localizedTextService;
+ _shortStringHelper = shortStringHelper;
+ _jsonSerializer = jsonSerializer;
+ _utility = utility;
+ _ioHelper = ioHelper;
+ }
+#endif
public string Alias => DataEditorAlias;
public EditorType Type => EditorType.PropertyValue;
@@ -31,7 +74,7 @@ public sealed class DataListDataEditor : IDataEditor
public string Icon => DataEditorIcon;
- public string Group => Core.Constants.PropertyEditors.Groups.Lists;
+ public string Group => UmbConstants.PropertyEditors.Groups.Lists;
public bool IsDeprecated => false;
@@ -39,14 +82,18 @@ public sealed class DataListDataEditor : IDataEditor
public IPropertyIndexValueFactory PropertyIndexValueFactory => new DefaultPropertyIndexValueFactory();
- public IConfigurationEditor GetConfigurationEditor() => new DataListConfigurationEditor(_utility);
+ public IConfigurationEditor GetConfigurationEditor() => new DataListConfigurationEditor(_utility, _shortStringHelper, _ioHelper);
public IDataValueEditor GetValueEditor()
{
+#if NET472
return new DataValueEditor
+#else
+ return new DataValueEditor(_localizedTextService, _shortStringHelper, _jsonSerializer)
+#endif
{
ValueType = ValueTypes.Json,
- View = DataEditorViewPath,
+ View = _ioHelper.ResolveRelativeOrVirtualUrl(DataEditorViewPath),
};
}
@@ -73,11 +120,15 @@ public IDataValueEditor GetValueEditor(object configuration)
}
}
+#if NET472
return new DataValueEditor
+#else
+ return new DataValueEditor(_localizedTextService, _shortStringHelper, _jsonSerializer)
+#endif
{
Configuration = configuration,
ValueType = ValueTypes.Json,
- View = view ?? DataEditorViewPath,
+ View = _ioHelper.ResolveRelativeOrVirtualUrl(view ?? DataEditorViewPath),
};
}
}
diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataListValueConverter.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataListValueConverter.cs
index fd85bf25..741983ce 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataListValueConverter.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataListValueConverter.cs
@@ -8,9 +8,15 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
+#if NET472
using Umbraco.Core;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
+#else
+using Umbraco.Cms.Core.Models.PublishedContent;
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Extensions;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/CountriesDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/CountriesDataListSource.cs
index d86f8137..fabe1dad 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/CountriesDataListSource.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/CountriesDataListSource.cs
@@ -6,8 +6,13 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
+#if NET472
using Umbraco.Core;
using Umbraco.Core.PropertyEditors;
+#else
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Extensions;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/CurrenciesDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/CurrenciesDataListSource.cs
index ae773753..e6d6ec74 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/CurrenciesDataListSource.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/CurrenciesDataListSource.cs
@@ -6,8 +6,13 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
+#if NET472
using Umbraco.Core;
using Umbraco.Core.PropertyEditors;
+#else
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Extensions;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/EnumDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/EnumDataListSource.cs
index 777e9c96..d4a9364b 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/EnumDataListSource.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/EnumDataListSource.cs
@@ -11,19 +11,45 @@
using System.Runtime.Serialization;
using Newtonsoft.Json.Linq;
using Umbraco.Community.Contentment.Web.Controllers;
+#if NET472
using Umbraco.Core;
+using Umbraco.Core.IO;
using Umbraco.Core.Logging;
using Umbraco.Core.PropertyEditors;
+using Umbraco.Core.Strings;
+#else
+using Microsoft.Extensions.Logging;
+using Umbraco.Cms.Core.IO;
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Cms.Core.Strings;
+using Umbraco.Extensions;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
public sealed class EnumDataListSource : IDataListSource, IDataListSourceValueConverter
{
- private readonly ILogger _logger;
+ private readonly IIOHelper _ioHelper;
+ private readonly IShortStringHelper _shortStringHelper;
- public EnumDataListSource(ILogger logger)
+#if NET472
+ private readonly ILogger _logger;
+#else
+ private readonly ILogger _logger;
+#endif
+
+ public EnumDataListSource(
+#if NET472
+ ILogger logger,
+#else
+ ILogger logger,
+#endif
+ IShortStringHelper shortStringHelper,
+ IIOHelper ioHelper)
{
_logger = logger;
+ _shortStringHelper = shortStringHelper;
+ _ioHelper = ioHelper;
}
public string Name => ".NET Enumeration";
@@ -45,7 +71,7 @@ public EnumDataListSource(ILogger logger)
Key = "enumType",
Name = "Enumeration type",
Description = "Select the enumeration from an assembly type.",
- View = CascadingDropdownListDataEditor.DataEditorViewPath,
+ View = _ioHelper.ResolveRelativeOrVirtualUrl(CascadingDropdownListDataEditor.DataEditorViewPath),
Config = new Dictionary
{
{ CascadingDropdownListDataEditor.APIs, new[]
@@ -93,7 +119,7 @@ public IEnumerable GetItems(Dictionary config)
Description = attr?.Description ?? attr2?.Description,
Disabled = attr?.Disabled ?? false,
Icon = attr?.Icon,
- Name = attr?.Name ?? field.Name.SplitPascalCasing(),
+ Name = attr?.Name ?? field.Name.SplitPascalCasing(_shortStringHelper),
Value = attr3?.Value ?? attr?.Value ?? field.Name
});
}
@@ -114,11 +140,35 @@ public Type GetValueType(Dictionary config)
if (enumType?.Length > 1)
{
var assembly = default(Assembly);
- try { assembly = Assembly.Load(enumType[0]); } catch (Exception ex) { _logger.Error(ex); }
+ try
+ {
+ assembly = Assembly.Load(enumType[0]);
+ }
+ catch (Exception ex)
+ {
+#if NET472
+ _logger.Error(ex);
+#else
+ _logger.LogError(ex, "Unable to load target type.");
+#endif
+ }
+
if (assembly != null)
{
var type = default(Type);
- try { type = assembly.GetType(enumType[1]); } catch (Exception ex) { _logger.Error(ex); }
+ try
+ {
+ type = assembly.GetType(enumType[1]);
+ }
+ catch (Exception ex)
+ {
+#if NET472
+ _logger.Error(ex);
+#else
+ _logger.LogError(ex, "Unable to retrieve target type.");
+#endif
+ }
+
if (type != null && type.IsEnum == true)
{
return type;
@@ -149,7 +199,11 @@ public object ConvertValue(Type type, string value)
}
}
+#if NET472
_logger.Debug($"Unable to find value '{value}' in enum '{type.FullName}'.");
+#else
+ _logger.LogDebug($"Unable to find value '{value}' in enum '{type.FullName}'.");
+#endif
}
return type.GetDefaultValue();
diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/ExamineDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/ExamineDataListSource.cs
index f9b577f2..fac6e40c 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/ExamineDataListSource.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/ExamineDataListSource.cs
@@ -6,23 +6,34 @@
using System.Collections.Generic;
using System.Linq;
using Examine;
-using Examine.LuceneEngine.Providers;
using Examine.Search;
+#if NET472
using Umbraco.Core;
using Umbraco.Core.IO;
using Umbraco.Core.PropertyEditors;
-using Umbraco.Examine;
+using Umbraco.Core.Strings;
using UmbConstants = Umbraco.Core.Constants;
+using UmbracoExamineFieldNames = Umbraco.Examine.UmbracoExamineIndex;
+#else
+using Umbraco.Cms.Core.IO;
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Cms.Core.Strings;
+using Umbraco.Cms.Infrastructure.Examine;
+using Umbraco.Extensions;
+using UmbConstants = Umbraco.Cms.Core.Constants;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
public sealed class ExamineDataListSource : IDataListSource
{
private readonly IExamineManager _examineManager;
+ private readonly IShortStringHelper _shortStringHelper;
+ private readonly IIOHelper _ioHelper;
private const string _defaultNameField = "nodeName";
- private const string _defaultValueField = UmbracoExamineIndex.NodeKeyFieldName;
- private const string _defaultIconField = UmbracoExamineIndex.IconFieldName;
+ private const string _defaultValueField = UmbracoExamineFieldNames.NodeKeyFieldName;
+ private const string _defaultIconField = UmbracoExamineFieldNames.IconFieldName;
private readonly Dictionary _examineFieldConfig = new Dictionary
{
@@ -30,14 +41,14 @@ public sealed class ExamineDataListSource : IDataListSource
Constants.Conventions.ConfigurationFieldAliases.Items,
new[]
{
- LuceneIndex.CategoryFieldName,
- LuceneIndex.ItemIdFieldName,
- LuceneIndex.ItemTypeFieldName,
- UmbracoExamineIndex.IconFieldName,
- UmbracoExamineIndex.IndexPathFieldName,
- UmbracoExamineIndex.NodeKeyFieldName,
- UmbracoExamineIndex.PublishedFieldName,
- UmbracoExamineIndex.UmbracoFileFieldName,
+ UmbracoExamineFieldNames.CategoryFieldName,
+ UmbracoExamineFieldNames.ItemIdFieldName,
+ UmbracoExamineFieldNames.ItemTypeFieldName,
+ UmbracoExamineFieldNames.IconFieldName,
+ UmbracoExamineFieldNames.IndexPathFieldName,
+ UmbracoExamineFieldNames.NodeKeyFieldName,
+ UmbracoExamineFieldNames.PublishedFieldName,
+ UmbracoExamineFieldNames.UmbracoFileFieldName,
"createDate",
"creatorID",
"creatorName",
@@ -57,9 +68,11 @@ public sealed class ExamineDataListSource : IDataListSource
},
};
- public ExamineDataListSource(IExamineManager examineManager)
+ public ExamineDataListSource(IExamineManager examineManager, IShortStringHelper shortStringHelper, IIOHelper ioHelper)
{
_examineManager = examineManager;
+ _shortStringHelper = shortStringHelper;
+ _ioHelper = ioHelper;
}
public string Name => "Examine Query";
@@ -79,14 +92,18 @@ public ExamineDataListSource(IExamineManager examineManager)
Key = "examineIndex",
Name = "Examine Index",
Description = "Select the Examine index.",
- View = DropdownListDataListEditor.DataEditorViewPath,
+ View = _ioHelper.ResolveRelativeOrVirtualUrl(DropdownListDataListEditor.DataEditorViewPath),
Config = new Dictionary
{
{ DropdownListDataListEditor.AllowEmpty, Constants.Values.False },
- { Constants.Conventions.ConfigurationFieldAliases.Items, _examineManager.Indexes.OrderBy(x => x.Name).Select(x => new DataListItem { Name = x.Name.SplitPascalCasing(), Value = x.Name }) },
+ { Constants.Conventions.ConfigurationFieldAliases.Items, _examineManager.Indexes.OrderBy(x => x.Name).Select(x => new DataListItem
+ {
+ Name = x.Name.SplitPascalCasing(_shortStringHelper),
+ Value = x.Name
+ }) },
}
},
- new NotesConfigurationField(@"
+ new NotesConfigurationField(_ioHelper, @"Do you need help with Lucene query?
If you need assistance with Lucene query syntax, please refer to this resource on our.umbraco.com.
", true),
@@ -95,7 +112,7 @@ public ExamineDataListSource(IExamineManager examineManager)
Key = "luceneQuery",
Name = "Lucene query",
Description = "Enter your raw Lucene expression to query Examine with.",
- View = CodeEditorDataEditor.DataEditorViewPath,
+ View = _ioHelper.ResolveRelativeOrVirtualUrl(CodeEditorDataEditor.DataEditorViewPath),
Config = new Dictionary
{
{ CodeEditorConfigurationEditor.Mode, "text" },
@@ -108,7 +125,7 @@ public ExamineDataListSource(IExamineManager examineManager)
Key = "nameField",
Name = "Name Field",
Description = "Enter the field name to select the name from the Examine record.",
- View = IOHelper.ResolveUrl(TextInputDataEditor.DataEditorViewPath),
+ View = _ioHelper.ResolveRelativeOrVirtualUrl(TextInputDataEditor.DataEditorViewPath),
Config = _examineFieldConfig
},
new ConfigurationField
@@ -116,7 +133,7 @@ public ExamineDataListSource(IExamineManager examineManager)
Key = "valueField",
Name = "Value Field",
Description = "Enter the field name to select the value (key) from the Examine record.",
- View = IOHelper.ResolveUrl(TextInputDataEditor.DataEditorViewPath),
+ View = _ioHelper.ResolveRelativeOrVirtualUrl(TextInputDataEditor.DataEditorViewPath),
Config = _examineFieldConfig
},
new ConfigurationField
@@ -124,7 +141,7 @@ public ExamineDataListSource(IExamineManager examineManager)
Key = "iconField",
Name = "Icon Field",
Description = "(optional) Enter the field name to select the icon from the Examine record.",
- View = IOHelper.ResolveUrl(TextInputDataEditor.DataEditorViewPath),
+ View = _ioHelper.ResolveRelativeOrVirtualUrl(TextInputDataEditor.DataEditorViewPath),
Config = _examineFieldConfig
},
new ConfigurationField
@@ -132,7 +149,7 @@ public ExamineDataListSource(IExamineManager examineManager)
Key = "descriptionField",
Name = "Description Field",
Description = "(optional) Enter the field name to select the description from the Examine record.",
- View = IOHelper.ResolveUrl(TextInputDataEditor.DataEditorViewPath),
+ View = _ioHelper.ResolveRelativeOrVirtualUrl(TextInputDataEditor.DataEditorViewPath),
Config = _examineFieldConfig
},
};
@@ -161,7 +178,11 @@ public IEnumerable GetItems(Dictionary config)
var descriptionField = config.GetValueAs("descriptionField", string.Empty);
var results = index
+#if NET472
.GetSearcher()
+#else
+ .Searcher
+#endif
.CreateQuery()
.NativeQuery(luceneQuery)
// NOTE: For any `OrderBy` complaints, refer to: https://github.com/Shazwazza/Examine/issues/126
diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/JsonDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/JsonDataListSource.cs
index 7ad04880..7cae63ef 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/JsonDataListSource.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/JsonDataListSource.cs
@@ -10,20 +10,46 @@
using System.Net;
using System.Text;
using Newtonsoft.Json.Linq;
+#if NET472
using Umbraco.Core;
+using Umbraco.Core.Hosting;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
using Umbraco.Core.PropertyEditors;
+#else
+using Microsoft.Extensions.Logging;
+using Umbraco.Cms.Core.Hosting;
+using Umbraco.Cms.Core.IO;
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Extensions;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
public sealed class JsonDataListSource : IDataListSource
{
+ private readonly IHostingEnvironment _hostingEnvironment;
+ private readonly IIOHelper _ioHelper;
+
+#if NET472
private readonly ILogger _logger;
- public JsonDataListSource(ILogger logger)
+ public JsonDataListSource(
+ ILogger logger,
+ IHostingEnvironment hostingEnvironment,
+ IIOHelper ioHelper)
+#else
+ private readonly ILogger _logger;
+
+ public JsonDataListSource(
+ ILogger logger,
+ IHostingEnvironment hostingEnvironment,
+ IIOHelper ioHelper)
+#endif
{
_logger = logger;
+ _hostingEnvironment = hostingEnvironment;
+ _ioHelper = ioHelper;
}
public string Name => "JSON Data";
@@ -38,12 +64,12 @@ public JsonDataListSource(ILogger logger)
public IEnumerable Fields => new[]
{
- new NotesConfigurationField($@"
+ new NotesConfigurationField(_ioHelper, $@"Do you need help with JSONPath expressions?
This data-source uses Newtonsoft's Json.NET library, with this we are limited to extracting only the 'value' from any key/value-pairs.
If you are a developer and have ideas on how to extract the `key` (name) from the items, please do let me know on GitHub issue: #40.
+
If you are a developer and have ideas on how to extract the key (name) from the items, please do let me know on GitHub issue: #40.
", true),
new ConfigurationField
{
@@ -128,7 +154,11 @@ public IEnumerable GetItems(Dictionary config)
if (tokens.Any() == false)
{
+#if NET472
_logger.Warn($"The JSONPath '{itemsJsonPath}' did not match any items in the JSON.");
+#else
+ _logger.LogWarning($"The JSONPath '{itemsJsonPath}' did not match any items in the JSON.");
+#endif
return Enumerable.Empty();
}
@@ -159,13 +189,21 @@ public IEnumerable GetItems(Dictionary config)
// How should we log if either name or value is empty? Note that empty or missing values are totally legal according to json
if (name == null)
{
+#if NET472
_logger.Warn($"The JSONPath '{nameJsonPath}' did not match a 'name' in the item JSON.");
+#else
+ _logger.LogWarning($"The JSONPath '{nameJsonPath}' did not match a 'name' in the item JSON.");
+#endif
}
// If value is missing we'll skip this specific item and log as a warning
if (value == null)
{
+#if NET472
_logger.Warn($"The JSONPath '{valueJsonPath}' did not match a 'value' in the item XML. The item was skipped.");
+#else
+ _logger.LogWarning($"The JSONPath '{valueJsonPath}' did not match a 'value' in the item XML. The item was skipped.");
+#endif
continue;
}
@@ -182,7 +220,11 @@ public IEnumerable GetItems(Dictionary config)
}
catch (Exception ex)
{
+#if NET472
_logger.Error(ex, "Error finding items in the JSON. Please check the syntax of your JSONPath expressions.");
+#else
+ _logger.LogError(ex, "Error finding items in the JSON. Please check the syntax of your JSONPath expressions.");
+#endif
}
return Enumerable.Empty();
@@ -203,27 +245,39 @@ private JToken GetJson(string url)
}
catch (WebException ex)
{
+#if NET472
_logger.Error(ex, $"Unable to fetch remote data from URL: {url}");
+#else
+ _logger.LogError(ex, $"Unable to fetch remote data from URL: {url}");
+#endif
}
}
else
{
// assume local file
- var path = IOHelper.MapPath(url);
+ var path = _hostingEnvironment.MapPathWebRoot(url);
if (File.Exists(path) == true)
{
content = File.ReadAllText(path);
}
else
{
+#if NET472
_logger.Error(new FileNotFoundException(), $"Unable to find the local file path: {url}");
+#else
+ _logger.LogError(new FileNotFoundException(), $"Unable to find the local file path: {url}");
+#endif
return null;
}
}
if (string.IsNullOrWhiteSpace(content) == true)
{
+#if NET472
_logger.Warn($"The contents of '{url}' was empty. Unable to process JSON data.");
+#else
+ _logger.LogWarning($"The contents of '{url}' was empty. Unable to process JSON data.");
+#endif
return default;
}
@@ -237,7 +291,11 @@ private JToken GetJson(string url)
catch (Exception ex)
{
var trimmed = content.Substring(0, Math.Min(400, content.Length));
+#if NET472
_logger.Error(ex, $"Error parsing string to JSON: {trimmed}");
+#else
+ _logger.LogError(ex, $"Error parsing string to JSON: {trimmed}");
+#endif
}
return default;
diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/LanguagesDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/LanguagesDataListSource.cs
index 0fe90032..e55b93ff 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/LanguagesDataListSource.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/LanguagesDataListSource.cs
@@ -6,8 +6,13 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
+#if NET472
using Umbraco.Core;
using Umbraco.Core.PropertyEditors;
+#else
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Extensions;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/NumberRangeDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/NumberRangeDataListSource.cs
index a3ae72b6..a1b8fbfb 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/NumberRangeDataListSource.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/NumberRangeDataListSource.cs
@@ -6,15 +6,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
+#if NET472
using Umbraco.Core;
using Umbraco.Core.IO;
using Umbraco.Core.PropertyEditors;
using UmbConstants = Umbraco.Core.Constants;
+#else
+using Umbraco.Cms.Core.IO;
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Extensions;
+using UmbConstants = Umbraco.Cms.Core.Constants;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
public sealed class NumberRangeDataListSource : IDataListSource, IDataListSourceValueConverter
{
+ private readonly IIOHelper _ioHelper;
+
+ public NumberRangeDataListSource(IIOHelper ioHelper)
+ {
+ _ioHelper = ioHelper;
+ }
+
public string Name => "Number Range";
public string Description => "Generates a sequence of numbers within a specified range.";
@@ -30,7 +44,7 @@ public sealed class NumberRangeDataListSource : IDataListSource, IDataListSource
Key = "start",
Name = "Start",
Description = "The value of the first number in the sequence.",
- View = IOHelper.ResolveUrl(NumberInputDataEditor.DataEditorViewPath),
+ View = _ioHelper.ResolveRelativeOrVirtualUrl(NumberInputDataEditor.DataEditorViewPath),
Config = new Dictionary
{
{ "step", 0.1D },
@@ -42,7 +56,7 @@ public sealed class NumberRangeDataListSource : IDataListSource, IDataListSource
Key = "end",
Name = "End",
Description = "The value of the last number in the sequence.",
- View = IOHelper.ResolveUrl(NumberInputDataEditor.DataEditorViewPath),
+ View = _ioHelper.ResolveRelativeOrVirtualUrl(NumberInputDataEditor.DataEditorViewPath),
Config = new Dictionary
{
{ "step", 0.1D },
@@ -54,7 +68,7 @@ public sealed class NumberRangeDataListSource : IDataListSource, IDataListSource
Key = "step",
Name = "Step",
Description = "The number of steps between each number.",
- View = IOHelper.ResolveUrl(NumberInputDataEditor.DataEditorViewPath),
+ View = _ioHelper.ResolveRelativeOrVirtualUrl(NumberInputDataEditor.DataEditorViewPath),
Config = new Dictionary
{
{ "step", 0.1D },
@@ -66,7 +80,7 @@ public sealed class NumberRangeDataListSource : IDataListSource, IDataListSource
Key = "decimals",
Name = "Decimal places",
Description = "How many decimal places would you like?",
- View = IOHelper.ResolveUrl("~/umbraco/views/propertyeditors/slider/slider.html"),
+ View = _ioHelper.ResolveRelativeOrVirtualUrl("~/umbraco/views/propertyeditors/slider/slider.html"),
Config = new Dictionary
{
{ "initVal1", 0 },
diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/PhysicalFileSystemDataSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/PhysicalFileSystemDataSource.cs
index 25526329..f5b1b454 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/PhysicalFileSystemDataSource.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/PhysicalFileSystemDataSource.cs
@@ -5,14 +5,52 @@
using System.Collections.Generic;
using System.Linq;
+#if NET472
using Umbraco.Core;
using Umbraco.Core.IO;
using Umbraco.Core.PropertyEditors;
+using Umbraco.Core.Strings;
+using UmbConstants = Umbraco.Core.Constants;
+#else
+using Microsoft.Extensions.Logging;
+using Umbraco.Cms.Core.Hosting;
+using Umbraco.Cms.Core.IO;
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Cms.Core.Strings;
+using Umbraco.Extensions;
+using UmbConstants = Umbraco.Cms.Core.Constants;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
public sealed class PhysicalFileSystemDataSource : IDataListSource
{
+ private readonly IShortStringHelper _shortStringHelper;
+
+#if NET472
+ public PhysicalFileSystemDataSource(
+ IShortStringHelper shortStringHelper)
+ {
+ _shortStringHelper = shortStringHelper;
+ }
+#else
+ private readonly IIOHelper _ioHelper;
+ private readonly IHostingEnvironment _hostingEnvironment;
+ private readonly ILogger _logger;
+
+ public PhysicalFileSystemDataSource(
+ IIOHelper ioHelper,
+ IHostingEnvironment hostingEnvironment,
+ ILogger logger,
+ IShortStringHelper shortStringHelper)
+ {
+ _shortStringHelper = shortStringHelper;
+ _ioHelper = ioHelper;
+ _hostingEnvironment = hostingEnvironment;
+ _logger = logger;
+ }
+#endif
+
public string Name => "File System";
public string Description => "Select paths from the physical file system as the data source.";
@@ -29,7 +67,7 @@ public sealed class PhysicalFileSystemDataSource : IDataListSource
{
Key = "path",
Name = "Folder path",
- Description = "Enter the relative path of the folder. e.g. ~/css",
+ Description = "Enter the relative path of the folder. e.g. ~/css Please note, this is relative to the web root folder, e.g. wwwroot.",
View = "textstring",
},
new ConfigurationField
@@ -68,15 +106,19 @@ public IEnumerable GetItems(Dictionary config)
? filter
: "*.*";
+#if NET472
var fs = new PhysicalFileSystem(virtualRoot);
+#else
+ var fs = new PhysicalFileSystem(_ioHelper, _hostingEnvironment, _logger, _hostingEnvironment.MapPathWebRoot(virtualRoot), _hostingEnvironment.ToAbsolute(virtualRoot));
+#endif
var files = fs.GetFiles(".", fileFilter);
return files.Select(x => new DataListItem
{
- Name = friendlyName == true ? x.SplitPascalCasing().ToFriendlyName() : x,
+ Name = friendlyName == true ? x.SplitPascalCasing(_shortStringHelper).ToFriendlyName() : x,
Value = virtualRoot + x,
Description = virtualRoot + x,
- Icon = Core.Constants.Icons.DefaultIcon,
+ Icon = UmbConstants.Icons.DefaultIcon,
});
}
}
diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/SqlDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/SqlDataListSource.cs
index 3dfdd03f..4fb1a315 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/SqlDataListSource.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/SqlDataListSource.cs
@@ -4,16 +4,28 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System.Collections.Generic;
-using System.Configuration;
using System.Data.Common;
using System.Data.SqlClient;
-using System.Data.SqlServerCe;
using System.IO;
using System.Linq;
+#if NET472
+using System.Configuration;
+using System.Data.SqlServerCe;
using Umbraco.Core;
+using Umbraco.Core.Hosting;
using Umbraco.Core.IO;
using Umbraco.Core.PropertyEditors;
using UmbConstants = Umbraco.Core.Constants;
+#else
+using Microsoft.Extensions.Configuration;
+using Umbraco.Cms.Core;
+using Umbraco.Cms.Core.Configuration;
+using Umbraco.Cms.Core.Hosting;
+using Umbraco.Cms.Core.IO;
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Extensions;
+using UmbConstants = Umbraco.Cms.Core.Constants;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
@@ -21,14 +33,24 @@ public sealed class SqlDataListSource : IDataListSource
{
private readonly string _codeEditorMode;
private readonly IEnumerable _connectionStrings;
-
- public SqlDataListSource()
+ private readonly IIOHelper _ioHelper;
+#if NET472 == false
+ private readonly IConfiguration _configuration;
+#endif
+
+ public SqlDataListSource(
+ IHostingEnvironment hostingEnvironment,
+#if NET472 == false
+ IConfiguration configuration,
+#endif
+ IIOHelper ioHelper)
{
// NOTE: Umbraco doesn't ship with SqlServer mode, so we check if its been added manually, otherwise defautls to Razor.
- _codeEditorMode = File.Exists(IOHelper.MapPath("~/umbraco/lib/ace-builds/src-min-noconflict/mode-sqlserver.js"))
+ _codeEditorMode = File.Exists(hostingEnvironment.MapPathWebRoot("~/umbraco/lib/ace-builds/src-min-noconflict/mode-sqlserver.js"))
? "sqlserver"
: "razor";
+#if NET472
_connectionStrings = ConfigurationManager.ConnectionStrings
.Cast()
.Select(x => new DataListItem
@@ -36,6 +58,19 @@ public SqlDataListSource()
Name = x.Name,
Value = x.Name
});
+#else
+ _connectionStrings = configuration
+ .GetSection("ConnectionStrings")
+ .GetChildren()
+ .Select(x => new DataListItem
+ {
+ Name = x.Key,
+ Value = x.Key
+ });
+
+ _configuration = configuration;
+#endif
+ _ioHelper = ioHelper;
}
public string Name => "SQL Data";
@@ -50,7 +85,9 @@ public SqlDataListSource()
public IEnumerable Fields => new ConfigurationField[]
{
- new NotesConfigurationField(@"
+ // TODO: [LK:2021-09-20] Add a note on v9 edition to inform the user about the lack of SQLCE support + a plea for help.
+
+ new NotesConfigurationField(_ioHelper, @"Important: A note about your SQL query.
Your SQL query should be designed to return a minimum of 2 columns, (and a maximum of 5 columns). These columns will be used to populate the List Editor items.
The columns will be mapped in the following order:
@@ -68,7 +105,7 @@ public SqlDataListSource()
Key = "query",
Name = "SQL query",
Description = "Enter your SQL query.",
- View = CodeEditorDataEditor.DataEditorViewPath,
+ View = _ioHelper.ResolveRelativeOrVirtualUrl(CodeEditorDataEditor.DataEditorViewPath),
Config = new Dictionary
{
{ CodeEditorConfigurationEditor.Mode, _codeEditorMode },
@@ -81,7 +118,7 @@ public SqlDataListSource()
Key = "connectionString",
Name = "Connection string",
Description = "Select the connection string.",
- View = DropdownListDataListEditor.DataEditorViewPath,
+ View = _ioHelper.ResolveRelativeOrVirtualUrl(DropdownListDataListEditor.DataEditorViewPath),
Config = new Dictionary
{
{ DropdownListDataListEditor.AllowEmpty, Constants.Values.False },
@@ -92,7 +129,7 @@ public SqlDataListSource()
public Dictionary DefaultValues => new Dictionary
{
- { "query", $"-- This is an example query that will select all the content nodes that are at level 1.\r\nSELECT\r\n\t[text],\r\n\t[uniqueId]\r\nFROM\r\n\t[umbracoNode]\r\nWHERE\r\n\t[nodeObjectType] = '{Core.Constants.ObjectTypes.Strings.Document}'\r\n\tAND\r\n\t[level] = 1\r\nORDER BY\r\n\t[sortOrder] ASC\r\n;" },
+ { "query", $"-- This is an example query that will select all the content nodes that are at level 1.\r\nSELECT\r\n\t[text],\r\n\t[uniqueId]\r\nFROM\r\n\t[umbracoNode]\r\nWHERE\r\n\t[nodeObjectType] = '{UmbConstants.ObjectTypes.Strings.Document}'\r\n\tAND\r\n\t[level] = 1\r\nORDER BY\r\n\t[sortOrder] ASC\r\n;" },
{ "connectionString", UmbConstants.System.UmbracoConnectionName }
};
@@ -101,19 +138,25 @@ public IEnumerable GetItems(Dictionary config)
var items = new List();
var query = config.GetValueAs("query", string.Empty);
- var connectionString = config.GetValueAs("connectionString", string.Empty);
+ var connectionStringName = config.GetValueAs("connectionString", string.Empty);
- if (string.IsNullOrWhiteSpace(query) == true || string.IsNullOrWhiteSpace(connectionString) == true)
+ if (string.IsNullOrWhiteSpace(query) == true || string.IsNullOrWhiteSpace(connectionStringName) == true)
{
return items;
}
- var settings = ConfigurationManager.ConnectionStrings[connectionString];
+#if NET472
+ var settings = ConfigurationManager.ConnectionStrings[connectionStringName];
if (settings == null)
+#else
+ var connectionString = _configuration.GetConnectionString(connectionStringName);
+ if (string.IsNullOrWhiteSpace(connectionString) == true)
+#endif
{
return items;
}
+#if NET472
// NOTE: SQLCE uses a different connection/command. I'm trying to keep this as generic as possible, without resorting to using NPoco. [LK]
if (settings.ProviderName.InvariantEquals(UmbConstants.DatabaseProviders.SqlCe) == true)
{
@@ -123,6 +166,15 @@ public IEnumerable GetItems(Dictionary config)
{
items.AddRange(GetSqlItems(query, settings.ConnectionString));
}
+#else
+ // TODO: [v9] [LK:2021-05-07] Review SQLCE
+ // NOTE: SQLCE uses a different connection/command. I'm trying to keep this as generic as possible, without resorting to using NPoco. [LK]
+ // I've tried digging around Umbraco's `IUmbracoDatabase` layer, but I couldn't get my head around it.
+ // At the end of the day, if the user has SQLCE configured, it'd be nice for them to query it.
+ // But I don't want to add an assembly dependency (for SQLCE) to Contentment itself. I'd like to leverage Umbraco's code.
+
+ items.AddRange(GetSqlItems(query, connectionString));
+#endif
return items;
}
diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/TextDelimitedDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/TextDelimitedDataListSource.cs
index 083e6591..bc0debc4 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/TextDelimitedDataListSource.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/TextDelimitedDataListSource.cs
@@ -7,21 +7,53 @@
using System.Collections.Generic;
using System.IO;
using System.Net;
+#if NET472
using Umbraco.Core;
+using Umbraco.Core.Hosting;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
using Umbraco.Core.PropertyEditors;
+#else
+using Microsoft.Extensions.Logging;
+using Umbraco.Cms.Core;
+using Umbraco.Cms.Core.Hosting;
+using Umbraco.Cms.Core.IO;
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Extensions;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
public sealed class TextDelimitedDataListSource : IDataListSource
{
+ private readonly IHostingEnvironment _hostingEnvironment;
+ private readonly IIOHelper _ioHelper;
+
+#if NET472
private readonly ILogger _logger;
- public TextDelimitedDataListSource(ILogger logger)
+ public TextDelimitedDataListSource(
+ ILogger logger,
+ IHostingEnvironment hostingEnvironment,
+ IIOHelper ioHelper)
+ {
+ _logger = logger;
+ _hostingEnvironment = hostingEnvironment;
+ _ioHelper = ioHelper;
+ }
+#else
+ private readonly ILogger _logger;
+
+ public TextDelimitedDataListSource(
+ ILogger logger,
+ IHostingEnvironment hostingEnvironment,
+ IIOHelper ioHelper)
{
_logger = logger;
+ _hostingEnvironment = hostingEnvironment;
+ _ioHelper = ioHelper;
}
+#endif
public string Name => "Text Delimited Data";
@@ -35,7 +67,7 @@ public TextDelimitedDataListSource(ILogger logger)
public IEnumerable Fields => new[]
{
- new NotesConfigurationField(@"
+ new NotesConfigurationField(_ioHelper, @"A note about using this data source.
The text contents will be retrieved and split into lines. Each line will be split into fields by the delimiting character.
The fields are then assigned by index position.
@@ -66,28 +98,28 @@ public TextDelimitedDataListSource(ILogger logger)
Key = "nameIndex",
Name = "Name Index",
Description = "Enter the index position of the name field from the delimited line. The default index position is 0.",
- View = NumberInputDataEditor.DataEditorViewPath
+ View = _ioHelper.ResolveRelativeOrVirtualUrl(NumberInputDataEditor.DataEditorViewPath),
},
new ConfigurationField
{
Key = "valueIndex",
Name = "Value Index",
Description = "Enter the index position of the value (key) field from the delimited line. The default index position is 1.",
- View = NumberInputDataEditor.DataEditorViewPath
+ View = _ioHelper.ResolveRelativeOrVirtualUrl(NumberInputDataEditor.DataEditorViewPath),
},
new ConfigurationField
{
Key = "iconIndex",
Name = "Icon Index",
Description = "(optional) Enter the index position of the icon field from the delimited line. To ignore this option, set the value to -1.",
- View = NumberInputDataEditor.DataEditorViewPath
+ View = _ioHelper.ResolveRelativeOrVirtualUrl(NumberInputDataEditor.DataEditorViewPath),
},
new ConfigurationField
{
Key = "descriptionIndex",
Name = "Description Index",
Description = "(optional) Enter the index position of the description field from the delimited line. To ignore this option, set the value to -1.",
- View = NumberInputDataEditor.DataEditorViewPath
+ View = _ioHelper.ResolveRelativeOrVirtualUrl(NumberInputDataEditor.DataEditorViewPath),
}
};
@@ -186,20 +218,28 @@ private string[] GetTextLines(string url)
}
catch (WebException ex)
{
+#if NET472
_logger.Error(ex, "Unable to fetch remote data.");
+#else
+ _logger.LogError(ex, "Unable to fetch remote data.");
+#endif
}
}
else
{
// assume local file
- var path = IOHelper.MapPath(url);
+ var path = _hostingEnvironment.MapPathWebRoot(url);
if (File.Exists(path) == true)
{
return File.ReadAllLines(path);
}
else
{
+#if NET472
_logger.Warn("Unable to find the local file path.");
+#else
+ _logger.LogWarning("Unable to find the local file path.");
+#endif
}
}
diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/TimeZoneDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/TimeZoneDataListSource.cs
index 47bbd009..74a4ab61 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/TimeZoneDataListSource.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/TimeZoneDataListSource.cs
@@ -6,7 +6,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
+#if NET472
using Umbraco.Core.PropertyEditors;
+#else
+using Umbraco.Cms.Core.PropertyEditors;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoContentDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoContentDataListSource.cs
index 73fc8d21..407002b9 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoContentDataListSource.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoContentDataListSource.cs
@@ -6,13 +6,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
+#if NET472
using Umbraco.Core;
+using Umbraco.Core.IO;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using Umbraco.Core.Xml;
using Umbraco.Web;
using UmbConstants = Umbraco.Core.Constants;
+#else
+using Umbraco.Cms.Core;
+using Umbraco.Cms.Core.IO;
+using Umbraco.Cms.Core.Models.PublishedContent;
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Cms.Core.Services;
+using Umbraco.Cms.Core.Web;
+using Umbraco.Cms.Core.Xml;
+using Umbraco.Extensions;
+using UmbConstants = Umbraco.Cms.Core.Constants;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
@@ -20,12 +33,33 @@ public sealed class UmbracoContentDataListSource : IDataListSource, IDataListSou
{
private readonly IContentTypeService _contentTypeService;
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
+ private readonly IIOHelper _ioHelper;
- public UmbracoContentDataListSource(IContentTypeService contentTypeService, IUmbracoContextAccessor umbracoContextAccessor)
+#if NET472
+ public UmbracoContentDataListSource(
+ IContentTypeService contentTypeService,
+ IUmbracoContextAccessor umbracoContextAccessor,
+ IIOHelper ioHelper)
{
_contentTypeService = contentTypeService;
_umbracoContextAccessor = umbracoContextAccessor;
+ _ioHelper = ioHelper;
}
+#else
+ private readonly IRequestAccessor _requestAccessor;
+
+ public UmbracoContentDataListSource(
+ IContentTypeService contentTypeService,
+ IRequestAccessor requestAccessor,
+ IUmbracoContextAccessor umbracoContextAccessor,
+ IIOHelper ioHelper)
+ {
+ _contentTypeService = contentTypeService;
+ _requestAccessor = requestAccessor;
+ _umbracoContextAccessor = umbracoContextAccessor;
+ _ioHelper = ioHelper;
+ }
+#endif
public string Name => "Umbraco Content";
@@ -44,7 +78,7 @@ public UmbracoContentDataListSource(IContentTypeService contentTypeService, IUmb
Key = "parentNode",
Name = "Parent node",
Description = "Set a parent node to use its child nodes as the data source items.",
- View = ContentPickerDataEditor.DataEditorSourceViewPath,
+ View = _ioHelper.ResolveRelativeOrVirtualUrl(ContentPickerDataEditor.DataEditorSourceViewPath),
}
};
@@ -55,18 +89,26 @@ public IEnumerable GetItems(Dictionary config)
var preview = true;
var parentNode = config.GetValueAs("parentNode", string.Empty);
var startNode = default(IPublishedContent);
+ var umbracoContext = _umbracoContextAccessor.GetRequiredUmbracoContext();
if (parentNode.InvariantStartsWith("umb://document/") == false)
{
var nodeContextId = default(int?);
- var umbracoContext = _umbracoContextAccessor.UmbracoContext;
// NOTE: First we check for "id" (if on a content page), then "parentId" (if editing an element).
+#if NET472
if (int.TryParse(umbracoContext.HttpContext.Request.QueryString.Get("id"), out var currentId) == true)
+#else
+ if (int.TryParse(_requestAccessor.GetQueryStringValue("id"), out var currentId) == true)
+#endif
{
nodeContextId = currentId;
}
+#if NET472
else if (int.TryParse(umbracoContext.HttpContext.Request.QueryString.Get("parentId"), out var parentId) == true)
+#else
+ else if (int.TryParse(_requestAccessor.GetQueryStringValue("parentId"), out var parentId) == true)
+#endif
{
nodeContextId = parentId;
}
@@ -86,9 +128,9 @@ public IEnumerable GetItems(Dictionary config)
startNode = umbracoContext.Content.GetSingleByXPath(preview, parsed);
}
}
- else if (GuidUdi.TryParse(parentNode, out var udi) == true && udi.Guid != Guid.Empty)
+ else if (UdiParser.TryParse(parentNode, out GuidUdi udi) == true && udi.Guid != Guid.Empty)
{
- startNode = _umbracoContextAccessor.UmbracoContext.Content.GetById(preview, udi.Guid);
+ startNode = umbracoContext.Content.GetById(preview, udi.Guid);
}
if (startNode != null)
@@ -111,8 +153,8 @@ public IEnumerable GetItems(Dictionary config)
public object ConvertValue(Type type, string value)
{
- return Udi.TryParse(value, out var udi) == true
- ? _umbracoContextAccessor.UmbracoContext.Content.GetById(udi)
+ return UdiParser.TryParse(value, out GuidUdi udi) == true
+ ? _umbracoContextAccessor.GetRequiredUmbracoContext().Content.GetById(udi)
: default;
}
}
diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoContentPropertiesDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoContentPropertiesDataListSource.cs
index e0c5e907..d531a70a 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoContentPropertiesDataListSource.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoContentPropertiesDataListSource.cs
@@ -7,11 +7,20 @@
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json.Linq;
+#if NET472
using Umbraco.Core;
using Umbraco.Core.IO;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using UmbConstants = Umbraco.Core.Constants;
+#else
+using Umbraco.Cms.Core;
+using Umbraco.Cms.Core.IO;
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Cms.Core.Services;
+using Umbraco.Extensions;
+using UmbConstants = Umbraco.Cms.Core.Constants;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
@@ -19,12 +28,17 @@ public sealed class UmbracoContentPropertiesDataListSource : IDataListSource
{
private readonly IContentTypeService _contentTypeService;
private readonly Lazy _dataEditors;
+ private readonly IIOHelper _ioHelper;
private Dictionary _icons;
- public UmbracoContentPropertiesDataListSource(IContentTypeService contentTypeService, Lazy dataEditors)
+ public UmbracoContentPropertiesDataListSource(
+ IContentTypeService contentTypeService,
+ Lazy dataEditors,
+ IIOHelper ioHelper)
{
_contentTypeService = contentTypeService;
_dataEditors = dataEditors;
+ _ioHelper = ioHelper;
}
public string Name => "Umbraco Content Properties";
@@ -57,13 +71,13 @@ public IEnumerable Fields
Key = "contentType",
Name = "Content Type",
Description = "Select a Content Type to list the properties from.",
- View = ItemPickerDataListEditor.DataEditorViewPath,
+ View = _ioHelper.ResolveRelativeOrVirtualUrl(ItemPickerDataListEditor.DataEditorViewPath),
Config = new Dictionary
{
{ "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 },
}
}
@@ -81,7 +95,7 @@ public IEnumerable GetItems(Dictionary config)
array.Count > 0 &&
array[0].Value() is string str &&
string.IsNullOrWhiteSpace(str) == false &&
- GuidUdi.TryParse(str, out var udi) == true)
+ UdiParser.TryParse(str, out GuidUdi udi) == true)
{
var contentType = _contentTypeService.Get(udi.Guid);
if (contentType != null)
diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoContentTypesDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoContentTypesDataListSource.cs
index a70615dd..50182cfd 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoContentTypesDataListSource.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoContentTypesDataListSource.cs
@@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json.Linq;
+#if NET472
using Umbraco.Core;
using Umbraco.Core.IO;
using Umbraco.Core.Models.PublishedContent;
@@ -15,6 +16,16 @@
using Umbraco.Core.Xml;
using Umbraco.Web;
using UmbConstants = Umbraco.Core.Constants;
+#else
+using Umbraco.Cms.Core;
+using Umbraco.Cms.Core.IO;
+using Umbraco.Cms.Core.Models.PublishedContent;
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Cms.Core.Services;
+using Umbraco.Cms.Core.Web;
+using Umbraco.Extensions;
+using UmbConstants = Umbraco.Cms.Core.Constants;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
@@ -22,11 +33,16 @@ public sealed class UmbracoContentTypesDataListSource : IDataListSource, IDataLi
{
private readonly IContentTypeService _contentTypeService;
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
+ private readonly IIOHelper _ioHelper;
- public UmbracoContentTypesDataListSource(IContentTypeService contentTypeService, IUmbracoContextAccessor umbracoContextAccessor)
+ public UmbracoContentTypesDataListSource(
+ IContentTypeService contentTypeService,
+ IUmbracoContextAccessor umbracoContextAccessor,
+ IIOHelper ioHelper)
{
_contentTypeService = contentTypeService;
_umbracoContextAccessor = umbracoContextAccessor;
+ _ioHelper = ioHelper;
}
public string Name => "Umbraco Content Types";
@@ -45,7 +61,7 @@ public UmbracoContentTypesDataListSource(IContentTypeService contentTypeService,
{
Key = "contentTypes",
Name = "Content types",
- View = IOHelper.ResolveUrl(CheckboxListDataListEditor.DataEditorViewPath),
+ View = _ioHelper.ResolveRelativeOrVirtualUrl(CheckboxListDataListEditor.DataEditorViewPath),
Description = "Select the types to use.",
Config = new Dictionary
{
@@ -128,9 +144,9 @@ public IEnumerable GetItems(Dictionary config)
public object ConvertValue(Type type, string value)
{
- if (GuidUdi.TryParse(value, out var udi) == true && ContentTypeCacheHelper.TryGetAlias(udi.Guid, out var alias, _contentTypeService) == true)
+ if (UdiParser.TryParse(value, out GuidUdi udi) == true && ContentTypeCacheHelper.TryGetAlias(udi.Guid, out var alias, _contentTypeService) == true)
{
- return _umbracoContextAccessor.UmbracoContext.Content.GetContentType(alias);
+ return _umbracoContextAccessor.GetRequiredUmbracoContext().Content.GetContentType(alias);
}
return default;
diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoContentXPathDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoContentXPathDataListSource.cs
index e6cfa604..3573c0c2 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoContentXPathDataListSource.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoContentXPathDataListSource.cs
@@ -6,13 +6,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
+#if NET472
using Umbraco.Core;
+using Umbraco.Core.IO;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using Umbraco.Core.Xml;
using Umbraco.Web;
using UmbConstants = Umbraco.Core.Constants;
+#else
+using Umbraco.Cms.Core;
+using Umbraco.Cms.Core.IO;
+using Umbraco.Cms.Core.Models.PublishedContent;
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Cms.Core.Services;
+using Umbraco.Cms.Core.Web;
+using Umbraco.Cms.Core.Xml;
+using Umbraco.Extensions;
+using UmbConstants = Umbraco.Cms.Core.Constants;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
@@ -20,12 +33,33 @@ public sealed class UmbracoContentXPathDataListSource : IDataListSource, IDataLi
{
private readonly IContentTypeService _contentTypeService;
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
+ private readonly IIOHelper _ioHelper;
- public UmbracoContentXPathDataListSource(IContentTypeService contentTypeService, IUmbracoContextAccessor umbracoContextAccessor)
+#if NET472
+ public UmbracoContentXPathDataListSource(
+ IContentTypeService contentTypeService,
+ IUmbracoContextAccessor umbracoContextAccessor,
+ IIOHelper ioHelper)
{
_contentTypeService = contentTypeService;
_umbracoContextAccessor = umbracoContextAccessor;
+ _ioHelper = ioHelper;
}
+#else
+ private readonly IRequestAccessor _requestAccessor;
+
+ public UmbracoContentXPathDataListSource(
+ IContentTypeService contentTypeService,
+ IRequestAccessor requestAccessor,
+ IUmbracoContextAccessor umbracoContextAccessor,
+ IIOHelper ioHelper)
+ {
+ _contentTypeService = contentTypeService;
+ _requestAccessor = requestAccessor;
+ _umbracoContextAccessor = umbracoContextAccessor;
+ _ioHelper = ioHelper;
+ }
+#endif
public string Name => "Umbraco Content by XPath";
@@ -46,7 +80,7 @@ public UmbracoContentXPathDataListSource(IContentTypeService contentTypeService,
Description = "Enter the XPath expression to select the content.",
View = "textstring",
},
- new NotesConfigurationField($@"
+ new NotesConfigurationField(_ioHelper, $@"Do you need help with XPath expressions?
If you need assistance with XPath syntax in general, please refer to this resource: w3schools.com/xml.
@@ -79,14 +113,22 @@ public IEnumerable GetItems(Dictionary config)
{
var nodeContextId = default(int?);
var preview = true;
- var umbracoContext = _umbracoContextAccessor.UmbracoContext;
+ var umbracoContext = _umbracoContextAccessor.GetRequiredUmbracoContext();
// NOTE: First we check for "id" (if on a content page), then "parentId" (if editing an element).
+#if NET472
if (int.TryParse(umbracoContext.HttpContext.Request.QueryString.Get("id"), out var currentId) == true)
+#else
+ if (int.TryParse(_requestAccessor.GetQueryStringValue("id"), out var currentId) == true)
+#endif
{
nodeContextId = currentId;
}
+#if NET472
else if (int.TryParse(umbracoContext.HttpContext.Request.QueryString.Get("parentId"), out var parentId) == true)
+#else
+ else if (int.TryParse(_requestAccessor.GetQueryStringValue("parentId"), out var parentId) == true)
+#endif
{
nodeContextId = parentId;
}
@@ -117,8 +159,8 @@ public IEnumerable GetItems(Dictionary config)
public object ConvertValue(Type type, string value)
{
- return Udi.TryParse(value, out var udi) == true
- ? _umbracoContextAccessor.UmbracoContext.Content.GetById(udi)
+ return UdiParser.TryParse(value, out var udi) == true
+ ? _umbracoContextAccessor.GetRequiredUmbracoContext().Content.GetById(udi)
: default;
}
}
diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoDictionaryDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoDictionaryDataListSource.cs
index c4d66ff7..20a78db3 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoDictionaryDataListSource.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoDictionaryDataListSource.cs
@@ -7,19 +7,31 @@
using System.Globalization;
using System.Linq;
using Newtonsoft.Json.Linq;
+#if NET472
using Umbraco.Core;
+using Umbraco.Core.IO;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
+#else
+using Umbraco.Cms.Core.IO;
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Cms.Core.Services;
+using Umbraco.Extensions;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
public sealed class UmbracoDictionaryDataListSource : IDataListSource
{
private readonly ILocalizationService _localizationService;
+ private readonly IIOHelper _ioHelper;
- public UmbracoDictionaryDataListSource(ILocalizationService localizationService)
+ public UmbracoDictionaryDataListSource(
+ ILocalizationService localizationService,
+ IIOHelper ioHelper)
{
_localizationService = localizationService;
+ _ioHelper = ioHelper;
}
public string Name => "Umbraco Dictionary Items";
@@ -37,7 +49,7 @@ public UmbracoDictionaryDataListSource(ILocalizationService localizationService)
Key = "item",
Name = "Dictionary item",
Description = "Select a parent dictionary item to display the child items.",
- View = DictionaryPickerDataEditor.DataEditorViewPath,
+ View = _ioHelper.ResolveRelativeOrVirtualUrl(DictionaryPickerDataEditor.DataEditorViewPath),
Config = new Dictionary
{
{ MaxItemsConfigurationField.MaxItems, 1 }
diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoEntityDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoEntityDataListSource.cs
index 665a67dd..8d169861 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoEntityDataListSource.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoEntityDataListSource.cs
@@ -6,12 +6,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
+#if NET472
using Umbraco.Core;
+using Umbraco.Core.IO;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Entities;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
+using Umbraco.Core.Strings;
using UmbConstants = Umbraco.Core.Constants;
+#else
+using Umbraco.Cms.Core;
+using Umbraco.Cms.Core.IO;
+using Umbraco.Cms.Core.Models;
+using Umbraco.Cms.Core.Models.Entities;
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Cms.Core.Services;
+using Umbraco.Cms.Core.Strings;
+using Umbraco.Extensions;
+using UmbConstants = Umbraco.Cms.Core.Constants;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
@@ -41,11 +55,18 @@ public sealed class UmbracoEntityDataListSource : IDataListSource, IDataListSour
{ nameof(UmbracoObjectTypes.MemberType), UmbConstants.Icons.MemberType },
};
- private readonly IEntityService _entityService;
+ private readonly IIOHelper _ioHelper;
+ private readonly Lazy _entityService;
+ private readonly IShortStringHelper _shortStringHelper;
- public UmbracoEntityDataListSource(IEntityService entityService)
+ public UmbracoEntityDataListSource(
+ Lazy entityService,
+ IShortStringHelper shortStringHelper,
+ IIOHelper ioHelper)
{
_entityService = entityService;
+ _shortStringHelper = shortStringHelper;
+ _ioHelper = ioHelper;
}
public string Name => "Umbraco Entities";
@@ -58,7 +79,7 @@ public UmbracoEntityDataListSource(IEntityService entityService)
public IEnumerable Fields => new ConfigurationField[]
{
- new NotesConfigurationField(@"
+ new NotesConfigurationField(_ioHelper, @"A note about supported Umbraco entity types.
Umbraco's EntityService API (currently) has limited support for querying entity types by GUID or UDI.
Supported entity types are available in the list below.
@@ -68,11 +89,16 @@ public UmbracoEntityDataListSource(IEntityService entityService)
Key = "entityType",
Name = "Entity type",
Description = "Select the Umbraco entity type to use.",
- View = DropdownListDataListEditor.DataEditorViewPath,
+ View = _ioHelper.ResolveRelativeOrVirtualUrl(DropdownListDataListEditor.DataEditorViewPath),
Config = new Dictionary()
{
{ "allowEmpty", Constants.Values.False },
- { "items", SupportedEntityTypes.Keys.Select(x => new DataListItem { Name = x.SplitPascalCasing(), Value = x }) },
+ { "items", SupportedEntityTypes.Keys.Select(x => new DataListItem
+ {
+ Name = x.SplitPascalCasing(_shortStringHelper),
+ Value = x
+ })
+ },
}
}
};
@@ -88,13 +114,14 @@ public IEnumerable GetItems(Dictionary config)
var icon = EntityTypeIcons.GetValueAs(entityType, UmbConstants.Icons.DefaultIcon);
return _entityService
+ .Value
.GetAll(objectType)
.OrderBy(x => x.Name)
.Select(x => new DataListItem
{
Icon = icon,
Name = x.Name,
- Value = Udi.Create(UmbConstants.UdiEntityType.FromUmbracoObjectType(objectType), x.Key).ToString(),
+ Value = Udi.Create(objectType.GetUdiType(), x.Key).ToString(),
});
}
@@ -105,8 +132,8 @@ public IEnumerable GetItems(Dictionary config)
public object ConvertValue(Type type, string value)
{
- return GuidUdi.TryParse(value, out var udi) == true && udi.Guid.Equals(Guid.Empty) == false
- ? _entityService.Get(udi.Guid)
+ return UdiParser.TryParse(value, out GuidUdi udi) == true && udi.Guid.Equals(Guid.Empty) == false
+ ? _entityService.Value.Get(udi.Guid)
: default;
}
}
diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoImageCropDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoImageCropDataListSource.cs
index 06d91155..1d2f69da 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoImageCropDataListSource.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoImageCropDataListSource.cs
@@ -5,21 +5,36 @@
using System.Collections.Generic;
using System.Linq;
+#if NET472
using Umbraco.Core;
+using Umbraco.Core.IO;
using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using UmbConstants = Umbraco.Core.Constants;
+#else
+using Umbraco.Cms.Core;
+using Umbraco.Cms.Core.IO;
+using Umbraco.Cms.Core.Models;
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Cms.Core.Services;
+using Umbraco.Extensions;
+using UmbConstants = Umbraco.Cms.Core.Constants;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
public sealed class UmbracoImageCropDataListSource : IDataListSource
{
private readonly IDataTypeService _dataTypeService;
+ private readonly IIOHelper _ioHelper;
- public UmbracoImageCropDataListSource(IDataTypeService dataTypeService)
+ public UmbracoImageCropDataListSource(
+ IDataTypeService dataTypeService,
+ IIOHelper ioHelper)
{
_dataTypeService = dataTypeService;
+ _ioHelper = ioHelper;
}
public string Name => "Umbraco Image Crops";
@@ -50,7 +65,7 @@ public IEnumerable Fields
Key = "imageCropper",
Name = "Image Cropper",
Description = "Select a Data Type that uses the Image Cropper.",
- View = RadioButtonListDataListEditor.DataEditorViewPath,
+ View = _ioHelper.ResolveRelativeOrVirtualUrl(RadioButtonListDataListEditor.DataEditorViewPath),
Config = new Dictionary
{
{ Constants.Conventions.ConfigurationFieldAliases.Items, items },
@@ -71,7 +86,7 @@ public IEnumerable GetItems(Dictionary config)
if (config.TryGetValue("imageCropper", out var obj) == true &&
obj is string str &&
string.IsNullOrWhiteSpace(str) == false &&
- GuidUdi.TryParse(str, out var udi) == true)
+ UdiParser.TryParse(str, out GuidUdi udi) == true)
{
return _dataTypeService
.GetDataType(udi.Guid)?
diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoLanguagesDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoLanguagesDataListSource.cs
index e5c7d5fe..21afe54d 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoLanguagesDataListSource.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoLanguagesDataListSource.cs
@@ -5,9 +5,15 @@
using System.Collections.Generic;
using System.Linq;
+#if NET472
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using UmbConstants = Umbraco.Core.Constants;
+#else
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Cms.Core.Services;
+using UmbConstants = Umbraco.Cms.Core.Constants;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoMemberGroupDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoMemberGroupDataListSource.cs
index 5be1f843..84cf4d53 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoMemberGroupDataListSource.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoMemberGroupDataListSource.cs
@@ -6,10 +6,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
+#if NET472
using Umbraco.Core;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using UmbConstants = Umbraco.Core.Constants;
+#else
+using Umbraco.Cms.Core;
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Cms.Core.Services;
+using UmbConstants = Umbraco.Cms.Core.Constants;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoMembersDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoMembersDataListSource.cs
index 120dd237..125d207a 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoMembersDataListSource.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoMembersDataListSource.cs
@@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json.Linq;
+#if NET472
using Umbraco.Core;
using Umbraco.Core.IO;
using Umbraco.Core.Models;
@@ -15,6 +16,17 @@
using Umbraco.Core.Services;
using Umbraco.Web.PublishedCache;
using UmbConstants = Umbraco.Core.Constants;
+#else
+using Umbraco.Cms.Core;
+using Umbraco.Cms.Core.IO;
+using Umbraco.Cms.Core.Models;
+using Umbraco.Cms.Core.Models.PublishedContent;
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Cms.Core.PublishedCache;
+using Umbraco.Cms.Core.Services;
+using Umbraco.Extensions;
+using UmbConstants = Umbraco.Cms.Core.Constants;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
@@ -23,12 +35,18 @@ public sealed class UmbracoMembersDataListSource : IDataListSource, IDataListSou
private readonly IMemberTypeService _memberTypeService;
private readonly IMemberService _memberService;
private readonly IPublishedSnapshotAccessor _publishedSnapshotAccessor;
+ private readonly IIOHelper _ioHelper;
- public UmbracoMembersDataListSource(IMemberTypeService memberTypeService, IMemberService memberService, IPublishedSnapshotAccessor publishedSnapshotAccessor)
+ public UmbracoMembersDataListSource(
+ IMemberTypeService memberTypeService,
+ IMemberService memberService,
+ IPublishedSnapshotAccessor publishedSnapshotAccessor,
+ IIOHelper ioHelper)
{
_memberTypeService = memberTypeService;
_memberService = memberService;
_publishedSnapshotAccessor = publishedSnapshotAccessor;
+ _ioHelper = ioHelper;
}
public string Name => "Umbraco Members";
@@ -56,7 +74,7 @@ public IEnumerable Fields
return new[]
{
- new NotesConfigurationField($@"
+ new NotesConfigurationField(_ioHelper, $@"Important note about Umbraco Members.
This data source is ideal for smaller number of members, e.g. under 50. Upwards of that, you will notice an unpleasant editor experience and rapidly diminished performance.
Remember...
@@ -70,14 +88,14 @@ public IEnumerable Fields
Key = "memberType",
Name = "Member Type",
Description = "Select a member type to filter the members by. If left empty, all members will be used.",
- View = ItemPickerDataListEditor.DataEditorViewPath,
+ View = _ioHelper.ResolveRelativeOrVirtualUrl(ItemPickerDataListEditor.DataEditorViewPath),
Config = new Dictionary
{
{ "addButtonLabelKey", "defaultdialogs_selectMemberType" },
{ "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 },
}
}
@@ -107,7 +125,7 @@ DataListItem mapMember(IMember member)
array.Count > 0 &&
array[0].Value() is string str &&
string.IsNullOrWhiteSpace(str) == false &&
- GuidUdi.TryParse(str, out var udi) == true)
+ UdiParser.TryParse(str, out GuidUdi udi) == true)
{
var memberType = _memberTypeService.Get(udi.Guid);
if (memberType != null)
@@ -123,9 +141,20 @@ DataListItem mapMember(IMember member)
public object ConvertValue(Type type, string value)
{
- return GuidUdi.TryParse(value, out var udi) == true && udi.Guid.Equals(Guid.Empty) == false
- ? _publishedSnapshotAccessor.PublishedSnapshot.Members.GetByProviderKey(udi.Guid)
- : default;
+ if (UdiParser.TryParse(value, out GuidUdi udi) == true && udi.Guid.Equals(Guid.Empty) == false)
+ {
+#if NET472
+ return _publishedSnapshotAccessor.GetRequiredPublishedSnapshot()?.Members.GetByProviderKey(udi.Guid);
+#else
+ var member = _memberService.GetByKey(udi.Guid);
+ if (member != null)
+ {
+ return _publishedSnapshotAccessor.GetRequiredPublishedSnapshot()?.Members.Get(_memberService.GetByKey(udi.Guid));
+ }
+#endif
+ }
+
+ return default(IPublishedContent);
}
}
}
diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoTagsDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoTagsDataListSource.cs
index 2f048af5..a2d22337 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoTagsDataListSource.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoTagsDataListSource.cs
@@ -6,9 +6,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
+#if NET472
using Umbraco.Core;
using Umbraco.Core.PropertyEditors;
using Umbraco.Web;
+#else
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Cms.Core.PublishedCache;
+using Umbraco.Extensions;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
@@ -51,7 +57,11 @@ public IEnumerable GetItems(Dictionary config)
{
var tagGroup = config.GetValueAs("tagGroup", defaultValue: string.Empty);
- return _tagQuery.Value
+ // TODO: [LK:2021-09-20] Error with Tags data source on v9.
+ // FIXME: Cannot resolve scoped service 'Umbraco.Cms.Core.PublishedCache.ITagQuery' from root provider.
+
+ return _tagQuery
+ .Value
.GetAllTags(tagGroup)
.OrderBy(x => x.Text)
.Select(x => new DataListItem
diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoUserGroupDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoUserGroupDataListSource.cs
index 221c6a43..9ca7c857 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoUserGroupDataListSource.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoUserGroupDataListSource.cs
@@ -6,10 +6,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
+#if NET472
using Umbraco.Core.Models.Membership;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using UmbConstants = Umbraco.Core.Constants;
+#else
+using Umbraco.Cms.Core.Models.Membership;
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Cms.Core.Services;
+using UmbConstants = Umbraco.Cms.Core.Constants;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoUsersDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoUsersDataListSource.cs
index f2200e56..c9fe153f 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoUsersDataListSource.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UmbracoUsersDataListSource.cs
@@ -7,21 +7,32 @@
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json.Linq;
+#if NET472
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;
+#else
+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;
+#endif
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;
}
@@ -55,13 +66,13 @@ public IEnumerable Fields
Key = "userGroup",
Name = "User Group",
Description = "Select a user group to filter the users by. If left empty, all users will be used.",
- View = ItemPickerDataListEditor.DataEditorViewPath,
+ View = _ioHelper.ResolveRelativeOrVirtualUrl(ItemPickerDataListEditor.DataEditorViewPath),
Config = new Dictionary
{
{ "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 },
}
}
diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UserDefinedDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UserDefinedDataListSource.cs
index 5ffaee35..c03390e3 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UserDefinedDataListSource.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/UserDefinedDataListSource.cs
@@ -6,18 +6,34 @@
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json.Linq;
+#if NET472
using Umbraco.Core;
+using Umbraco.Core.IO;
using Umbraco.Core.PropertyEditors;
+using UmbConstants = Umbraco.Core.Constants;
+#else
+using Umbraco.Cms.Core.IO;
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Extensions;
+using UmbConstants = Umbraco.Cms.Core.Constants;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
public sealed class UserDefinedDataListSource : IDataListSource
{
+ private readonly IIOHelper _ioHelper;
+
+ public UserDefinedDataListSource(IIOHelper ioHelper)
+ {
+ _ioHelper = ioHelper;
+ }
+
public string Name => "User-defined List";
public string Description => "Manually configure the items for the data source.";
- public string Icon => Core.Constants.Icons.DataType;
+ public string Icon => UmbConstants.Icons.DataType;
public string Group => Constants.Conventions.DataSourceGroups.Data;
@@ -28,18 +44,17 @@ public sealed class UserDefinedDataListSource : IDataListSource
Key = "items",
Name = "Options",
Description = "Configure the option items for the data list.
Please try to avoid using duplicate values, as this may cause adverse issues with list editors.",
- View = DataListDataEditor.DataEditorListEditorViewPath,
+ View = _ioHelper.ResolveRelativeOrVirtualUrl(DataListDataEditor.DataEditorListEditorViewPath),
Config = new Dictionary()
{
{ "confirmRemoval", Constants.Values.True },
{ EnableDevModeConfigurationField.EnableDevMode, Constants.Values.True },
{ MaxItemsConfigurationField.MaxItems, 0 },
- { NotesConfigurationField.Notes, @"
-
- Advanced: Paste in the raw JSON?
-
If you have copied the raw JSON from the Data List preview panel, .
-
The JSON format must be an array of the Data List item structure. For example...
- [
+ { NotesConfigurationField.Notes, @"
+Advanced: Paste in the raw JSON?
+
If you have copied the raw JSON from the Data List preview panel, .
+
The JSON format must be an array of the Data List item structure. For example...
+[
{
""name"": ""Ready"",
""value"": ""value1"",
@@ -57,7 +72,7 @@ public sealed class UserDefinedDataListSource : IDataListSource
""description"": ""Three to get ready. Now go, cat, go.""
}
]
- " },
+" },
},
}
};
diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/XmlDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/XmlDataListSource.cs
index c5b3eecb..2e78d4cb 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/XmlDataListSource.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/XmlDataListSource.cs
@@ -7,23 +7,56 @@
using System.Collections.Generic;
using System.Linq;
using System.Net;
+using System.Net.Http;
using System.Xml;
using System.Xml.XPath;
+#if NET472
using Umbraco.Core;
+using Umbraco.Core.Hosting;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
using Umbraco.Core.PropertyEditors;
+#else
+using Microsoft.Extensions.Logging;
+using Umbraco.Cms.Core;
+using Umbraco.Cms.Core.Hosting;
+using Umbraco.Cms.Core.IO;
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Extensions;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
public sealed class XmlDataListSource : IDataListSource
{
+ private readonly IHostingEnvironment _hostingEnvironment;
+ private readonly IIOHelper _ioHelper;
+
+#if NET472
private readonly ILogger _logger;
- public XmlDataListSource(ILogger logger)
+ public XmlDataListSource(
+ ILogger logger,
+ IHostingEnvironment hostingEnvironment,
+ IIOHelper ioHelper)
+ {
+ _logger = logger;
+ _hostingEnvironment = hostingEnvironment;
+ _ioHelper = ioHelper;
+ }
+#else
+ private readonly ILogger _logger;
+
+ public XmlDataListSource(
+ ILogger logger,
+ IHostingEnvironment hostingEnvironment,
+ IIOHelper ioHelper)
{
_logger = logger;
+ _hostingEnvironment = hostingEnvironment;
+ _ioHelper = ioHelper;
}
+#endif
public string Name => "XML Data";
@@ -44,7 +77,7 @@ public XmlDataListSource(ILogger logger)
Description = "Enter the URL of the XML data source. This can be either a remote URL, or local relative file path.",
View = "textstring"
},
- new NotesConfigurationField(@"
+ new NotesConfigurationField(_ioHelper, @"Do you need help with XPath expressions?
If you need assistance with XPath syntax, please refer to this resource: w3schools.com/xml.
@@ -109,7 +142,7 @@ public IEnumerable GetItems(Dictionary config)
}
var path = url.InvariantStartsWith("http") == false
- ? IOHelper.MapPath(url)
+ ? _hostingEnvironment.MapPathWebRoot(url)
: url;
var doc = default(XPathDocument);
@@ -118,13 +151,29 @@ public IEnumerable GetItems(Dictionary config)
{
doc = new XPathDocument(path);
}
+ catch (HttpRequestException ex)
+ {
+#if NET472
+ _logger.Error(ex, $"Unable to retrieve data from '{path}'.");
+#else
+ _logger.LogError(ex, $"Unable to retrieve data from '{path}'.");
+#endif
+ }
catch (WebException ex)
{
+#if NET472
_logger.Error(ex, $"Unable to retrieve data from '{path}'.");
+#else
+ _logger.LogError(ex, $"Unable to retrieve data from '{path}'.");
+#endif
}
catch (XmlException ex)
{
+#if NET472
_logger.Error(ex, "Unable to load XML data.");
+#else
+ _logger.LogError(ex, $"Unable to load XML data from '{path}'.");
+#endif
}
if (doc == null)
@@ -158,7 +207,11 @@ public IEnumerable GetItems(Dictionary config)
if (nodes.Count == 0)
{
+#if NET472
_logger.Warn($"The XPath '{itemsXPath}' did not match any items in the XML: {nav.OuterXml.Substring(0, Math.Min(300, nav.OuterXml.Length))}");
+#else
+ _logger.LogWarning($"The XPath '{itemsXPath}' did not match any items in the XML: {nav.OuterXml.Substring(0, Math.Min(300, nav.OuterXml.Length))}");
+#endif
return Enumerable.Empty();
}
@@ -198,12 +251,20 @@ public IEnumerable GetItems(Dictionary config)
if (name == null)
{
+#if NET472
_logger.Warn($"The XPath '{nameXPath}' did not match a 'name' in the item XML: {outerXml}");
+#else
+ _logger.LogWarning($"The XPath '{nameXPath}' did not match a 'name' in the item XML: {outerXml}");
+#endif
}
if (value == null)
{
+#if NET472
_logger.Warn($"The XPath '{valueXPath}' did not match a 'value' in the item XML: {outerXml}");
+#else
+ _logger.LogWarning($"The XPath '{valueXPath}' did not match a 'value' in the item XML: {outerXml}");
+#endif
}
}
}
diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/XmlSitemapChangeFrequencyDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/XmlSitemapChangeFrequencyDataListSource.cs
index 00633050..6c5cc68f 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/XmlSitemapChangeFrequencyDataListSource.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/XmlSitemapChangeFrequencyDataListSource.cs
@@ -5,8 +5,13 @@
using System.Collections.Generic;
using System.Linq;
+#if NET472
using Umbraco.Core;
using Umbraco.Core.PropertyEditors;
+#else
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Extensions;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/XmlSitemapPriorityDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/XmlSitemapPriorityDataListSource.cs
index 246b5fd4..1e32d5ba 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/XmlSitemapPriorityDataListSource.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/XmlSitemapPriorityDataListSource.cs
@@ -4,7 +4,11 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System.Collections.Generic;
+#if NET472
using Umbraco.Core.PropertyEditors;
+#else
+using Umbraco.Cms.Core.PropertyEditors;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
diff --git a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/uCssClassNameDataListSource.cs b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/uCssClassNameDataListSource.cs
index 609e93d9..45ed6bd3 100644
--- a/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/uCssClassNameDataListSource.cs
+++ b/src/Umbraco.Community.Contentment/DataEditors/DataList/DataSources/uCssClassNameDataListSource.cs
@@ -7,14 +7,34 @@
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
+#if NET472
using Umbraco.Core;
+using Umbraco.Core.Hosting;
using Umbraco.Core.IO;
using Umbraco.Core.PropertyEditors;
+#else
+using Umbraco.Cms.Core;
+using Umbraco.Cms.Core.Hosting;
+using Umbraco.Cms.Core.IO;
+using Umbraco.Cms.Core.PropertyEditors;
+using Umbraco.Extensions;
+#endif
namespace Umbraco.Community.Contentment.DataEditors
{
public class uCssClassNameDataListSource : IDataListSource
{
+ private readonly IHostingEnvironment _hostingEnvironment;
+ private readonly IIOHelper _ioHelper;
+
+ public uCssClassNameDataListSource(
+ IHostingEnvironment hostingEnvironment,
+ IIOHelper ioHelper)
+ {
+ _hostingEnvironment = hostingEnvironment;
+ _ioHelper = ioHelper;
+ }
+
public string Name => "uCssClassName";
public string Description => "A homage to @marcemarc's bingo-famous uCssClassNameDropdown package!";
@@ -25,7 +45,7 @@ public class uCssClassNameDataListSource : IDataListSource
public IEnumerable Fields => new[]
{
- new NotesConfigurationField(@"
+ new NotesConfigurationField(_ioHelper, @"uCssClassName? What sort of a name is that?