From cc082e191c18cee27dcd825a5789267624355225 Mon Sep 17 00:00:00 2001 From: Kenn Jacobsen Date: Thu, 15 Feb 2024 12:36:23 +0100 Subject: [PATCH] Clean up datatype configurations for V14 (#15718) * Clean up datatype configurations for V14 * Fix merge * Remove ParameterEditorCollection + revert accidental changes to core project file --- .../Configuration/Grid/GridConfig.cs | 43 -- .../Configuration/Grid/GridEditorsConfig.cs | 148 ----- .../Configuration/Grid/IGridConfig.cs | 6 - .../Configuration/Grid/IGridEditorConfig.cs | 18 - .../Configuration/Grid/IGridEditorsConfig.cs | 6 - src/Umbraco.Core/Constants-PropertyEditors.cs | 5 - .../ContentApps/ListViewContentAppFactory.cs | 2 - .../DependencyInjection/UmbracoBuilder.cs | 5 - .../CompositeLegacyPackageManifest.cs | 7 - .../Manifest/ILegacyPackageManifest.cs | 6 - .../Manifest/LegacyPackageManifest.cs | 9 - .../ContentEditing/ContentPropertyDisplay.cs | 10 - .../Models/ContentEditing/DataTypeBasic.cs | 4 - .../DataTypeConfigurationFieldDisplay.cs | 24 - .../ContentEditing/PropertyEditorBasic.cs | 6 - .../ContentEditing/PropertyTypeBasic.cs | 4 - src/Umbraco.Core/Models/IDataValueEditor.cs | 10 - .../Mapping/ContentPropertyDisplayMapper.cs | 15 +- .../Models/Mapping/DataTypeMapDefinition.cs | 21 +- .../Models/Mapping/MacroMapDefinition.cs | 86 --- .../Mapping/MemberTabsAndPropertiesMapper.cs | 14 - .../Models/Mapping/PropertyTypeGroupMapper.cs | 2 - .../PropertyEditors/BlockGridConfiguration.cs | 125 +--- .../PropertyEditors/BlockListConfiguration.cs | 51 +- .../ColorPickerConfiguration.cs | 18 +- .../ConfigurationEditorOfTConfiguration.cs | 51 +- .../PropertyEditors/ConfigurationField.cs | 42 -- .../ConfigurationFieldAttribute.cs | 104 +--- .../ContentPickerConfiguration.cs | 12 +- .../ContentPickerConfigurationEditor.cs | 23 +- .../ContentPickerPropertyEditor.cs | 28 +- .../PropertyEditors/DataEditor.cs | 36 +- .../PropertyEditors/DataEditorAttribute.cs | 111 +--- .../PropertyEditors/DataValueEditor.cs | 33 - .../PropertyEditors/DateTimeConfiguration.cs | 22 - .../DateTimeConfigurationEditor.cs | 47 -- .../DecimalConfigurationEditor.cs | 11 +- .../PropertyEditors/DecimalPropertyEditor.cs | 7 +- .../DropDownFlexibleConfiguration.cs | 6 +- .../PropertyEditors/EditorType.cs | 23 - .../EmailAddressConfiguration.cs | 11 - .../EmailAddressConfigurationEditor.cs | 27 - .../EyeDropperColorPickerConfiguration.cs | 13 - ...yeDropperColorPickerConfigurationEditor.cs | 14 - .../EyeDropperColorPickerPropertyEditor.cs | 41 +- .../FileExtensionConfigItem.cs | 5 - .../FileUploadConfiguration.cs | 2 +- .../FileUploadConfigurationEditor.cs | 12 +- .../PropertyEditors/GridEditor.cs | 74 --- .../PropertyEditors/IDataEditor.cs | 25 - ...INestedContentPropertyIndexValueFactory.cs | 5 - .../IntegerConfigurationEditor.cs | 9 - .../PropertyEditors/IntegerPropertyEditor.cs | 16 +- .../PropertyEditors/LabelConfiguration.cs | 2 +- .../LabelConfigurationEditor.cs | 12 +- .../PropertyEditors/LabelPropertyEditor.cs | 27 +- .../PropertyEditors/ListViewConfiguration.cs | 139 +---- .../ListViewConfigurationEditor.cs | 12 +- .../PropertyEditors/MarkdownConfiguration.cs | 16 - .../MarkdownConfigurationEditor.cs | 18 - .../PropertyEditors/MarkdownPropertyEditor.cs | 35 +- .../MediaPicker3Configuration.cs | 34 +- .../MediaPicker3ConfigurationEditor.cs | 23 +- .../MediaPickerConfiguration.cs | 27 - .../MediaPickerConfigurationEditor.cs | 47 -- .../MemberGroupPickerPropertyEditor.cs | 11 +- .../MemberPickerConfiguration.cs | 7 - .../MemberPickerPropertyEditor.cs | 13 +- .../PropertyEditors/MissingPropertyEditor.cs | 8 +- .../MultiNodePickerConfiguration.cs | 18 +- .../MultiNodePickerConfigurationEditor.cs | 37 +- .../MultiUrlPickerConfiguration.cs | 20 +- .../MultiUrlPickerConfigurationEditor.cs | 12 +- .../NestedContentConfiguration.cs | 44 -- .../NestedContentConfigurationEditor.cs | 28 - .../ParameterEditorCollection.cs | 24 - .../ContentTypeParameterEditor.cs | 25 - .../MultipleContentPickerParameterEditor.cs | 53 -- .../MultipleContentTypeParameterEditor.cs | 19 - .../MultipleMediaPickerParameterEditor.cs | 51 -- ...ultiplePickerParamateterValueEditorBase.cs | 57 -- .../MultiplePropertyGroupParameterEditor.cs | 22 - .../MultiplePropertyTypeParameterEditor.cs | 22 - .../PropertyGroupParameterEditor.cs | 22 - .../PropertyTypeParameterEditor.cs | 22 - .../PlainDateTimePropertyEditor.cs | 4 - .../PlainDecimalPropertyEditor.cs | 4 - .../PlainIntegerPropertyEditor.cs | 4 - .../PlainJsonPropertyEditor.cs | 4 - .../PlainStringPropertyEditor.cs | 4 - .../PlainTimePropertyEditor.cs | 8 +- .../PropertyEditorCollection.cs | 4 +- .../PropertyEditors/RichTextConfiguration.cs | 55 +- .../RichTextConfigurationEditor.cs | 12 +- .../PropertyEditors/SliderConfiguration.cs | 15 +- .../SliderConfigurationEditor.cs | 13 +- .../PropertyEditors/TagConfiguration.cs | 8 +- .../PropertyEditors/TagConfigurationEditor.cs | 26 +- .../PropertyEditors/TextAreaConfiguration.cs | 5 +- .../TextAreaConfigurationEditor.cs | 12 +- .../PropertyEditors/TextboxConfiguration.cs | 2 +- .../TextboxConfigurationEditor.cs | 12 +- .../PropertyEditors/TrueFalseConfiguration.cs | 19 - .../TrueFalseConfigurationEditor.cs | 27 - .../UserPickerConfiguration.cs | 9 - .../UserPickerPropertyEditor.cs | 13 +- .../MediaPickerValueConverter.cs | 152 ----- .../PropertyEditors/ValueListConfiguration.cs | 9 +- src/Umbraco.Core/Services/DataTypeService.cs | 38 +- .../Services/IEditorConfigurationParser.cs | 12 - .../UmbracoBuilder.CoreServices.cs | 4 - .../UmbracoBuilder.MappingProfiles.cs | 1 - .../UmbracoBuilder.Services.cs | 2 - .../GridCellValueConnectorExtensions.cs | 52 -- .../Deploy/IGridCellValueConnector.cs | 52 -- .../Deploy/IGridCellValueConnector2.cs | 42 -- .../Manifest/DataEditorConverter.cs | 27 +- .../Manifest/LegacyManifestParser.cs | 18 - .../Migrations/Install/DatabaseDataCreator.cs | 26 - .../Models/GridValue.cs | 88 --- .../BlockGridPropertyEditor.cs | 22 +- .../BlockListConfigurationEditor.cs | 4 +- .../BlockListPropertyEditor.cs | 29 +- .../CheckBoxListPropertyEditor.cs | 32 +- .../ColorPickerConfigurationEditor.cs | 62 +- .../ColorPickerPropertyEditor.cs | 31 +- .../PropertyEditors/DateTimePropertyEditor.cs | 27 +- .../DropDownFlexibleConfigurationEditor.cs | 12 +- .../DropDownFlexiblePropertyEditor.cs | 36 +- .../EmailAddressPropertyEditor.cs | 19 +- .../FileUploadPropertyEditor.cs | 36 +- .../PropertyEditors/GridConfiguration.cs | 31 - .../GridConfigurationEditor.cs | 74 --- .../PropertyEditors/GridPropertyEditor.cs | 337 ---------- .../GridPropertyIndexValueFactory.cs | 97 --- .../ImageCropperConfiguration.cs | 7 +- .../ImageCropperConfigurationEditor.cs | 5 +- .../ImageCropperPropertyEditor.cs | 41 +- .../PropertyEditors/ListViewPropertyEditor.cs | 26 +- .../MediaPicker3PropertyEditor.cs | 33 +- .../MediaPickerPropertyEditor.cs | 96 --- .../MultiNodeTreePickerPropertyEditor.cs | 28 +- .../MultiUrlPickerPropertyEditor.cs | 26 +- .../MultipleTextStringConfigurationEditor.cs | 15 +- .../MultipleTextStringPropertyEditor.cs | 14 +- .../NestedContentPropertyEditor.cs | 575 ------------------ .../NestedContentPropertyHandler.cs | 83 --- .../NestedContentPropertyIndexValueFactory.cs | 57 -- .../RadioButtonsPropertyEditor.cs | 32 +- .../PropertyEditors/RichTextPropertyEditor.cs | 113 +--- .../PropertyEditors/SliderPropertyEditor.cs | 27 +- .../PropertyEditors/TagsPropertyEditor.cs | 20 +- .../PropertyEditors/TextAreaPropertyEditor.cs | 25 +- .../PropertyEditors/TextboxPropertyEditor.cs | 25 +- .../TrueFalsePropertyEditor.cs | 38 +- .../ValueConverters/GridValueConverter.cs | 117 ---- .../NestedContentManyValueConverter.cs | 132 ---- .../NestedContentSingleValueConverter.cs | 116 ---- .../NestedContentValueConverterBase.cs | 72 --- .../ValueListConfigurationEditor.cs | 22 +- .../ValueListUniqueValueValidator.cs | 51 +- .../Services/ContentListViewServiceBase.cs | 2 +- .../Services/EditorConfigurationParser.cs | 71 --- .../Templates/HtmlMacroParameterParser.cs | 171 ------ .../Templates/IHtmlMacroParameterParser.cs | 25 - .../Controllers/BackOfficeController.cs | 10 - .../Controllers/BackOfficeServerVariables.cs | 5 - .../Controllers/ContentTypeController.cs | 1 - .../Controllers/DataTypeController.cs | 6 +- .../Controllers/MacrosController.cs | 418 ------------- .../Trees/DataTypeTreeController.cs | 2 +- .../UmbracoTestDataController.cs | 5 - .../Builders/ContentBuilder.cs | 1 - .../Builders/ContentTypeBuilder.cs | 8 - .../Builders/DataEditorBuilder.cs | 1 - .../Builders/DataValueEditorBuilder.cs | 4 - .../TestHelpers/MockedValueEditors.cs | 4 +- ...reNotAmbiguousActionNameControllerTests.cs | 4 - .../Services/ContentServiceTests.cs | 3 - .../UmbracoExamine/IndexTest.cs | 86 --- .../Packaging/PackageDataInstallationTests.cs | 4 +- .../DataTypeDefinitionRepositoryTest.cs | 18 +- .../Services/DataTypeContainerServiceTests.cs | 4 +- .../Services/DataTypeServiceTests.cs | 4 +- .../Services/EntityXmlSerializerTests.cs | 4 +- .../Cache/ValueEditorCacheTests.cs | 6 - .../Umbraco.Core/Composing/TypeLoaderTests.cs | 2 +- .../MediaPickerValueConverterTests.cs | 103 ---- .../NestedContentValueConverterTests.cs | 153 ----- .../OutputExpansionStrategyTestBase.cs | 7 +- .../Manifest/LegacyManifestParserTests.cs | 291 --------- .../Umbraco.Core/Models/VariationTests.cs | 6 +- .../PropertyEditors/ColorListValidatorTest.cs | 50 +- .../DataValueEditorReuseTests.cs | 12 +- ...ataValueReferenceFactoryCollectionTests.cs | 32 +- .../DecimalValueEditorTests.cs | 5 +- .../EnsureUniqueValuesValidatorTest.cs | 81 +-- .../MultiNodeTreePickerTests.cs | 3 +- .../MultiValuePropertyEditorTests.cs | 37 +- .../MultipleTextStringValueEditorTests.cs | 2 +- .../NestedContentPropertyComponentTests.cs | 430 ------------- .../NumericValueEditorTests.cs | 3 +- .../PropertyEditorValueTypeConverterTests.cs | 2 +- .../PropertyEditors/SliderValueEditorTests.cs | 3 +- .../TrueFalsePropertyValueEditorTests.cs | 5 +- .../Published/NestedContentTests.cs | 302 --------- .../PropertyValidationServiceTests.cs | 5 +- .../Builders/DataTypeBuilderTests.cs | 3 - .../Umbraco.Tests.UnitTests.csproj | 36 ++ .../Controllers/MemberControllerUnitTests.cs | 5 +- .../ContentModelSerializationTests.cs | 3 - 211 files changed, 414 insertions(+), 7824 deletions(-) delete mode 100644 src/Umbraco.Core/Configuration/Grid/GridConfig.cs delete mode 100644 src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs delete mode 100644 src/Umbraco.Core/Configuration/Grid/IGridConfig.cs delete mode 100644 src/Umbraco.Core/Configuration/Grid/IGridEditorConfig.cs delete mode 100644 src/Umbraco.Core/Configuration/Grid/IGridEditorsConfig.cs delete mode 100644 src/Umbraco.Core/Models/Mapping/MacroMapDefinition.cs delete mode 100644 src/Umbraco.Core/PropertyEditors/DateTimeConfiguration.cs delete mode 100644 src/Umbraco.Core/PropertyEditors/DateTimeConfigurationEditor.cs delete mode 100644 src/Umbraco.Core/PropertyEditors/EditorType.cs delete mode 100644 src/Umbraco.Core/PropertyEditors/EmailAddressConfiguration.cs delete mode 100644 src/Umbraco.Core/PropertyEditors/EmailAddressConfigurationEditor.cs delete mode 100644 src/Umbraco.Core/PropertyEditors/EyeDropperColorPickerConfiguration.cs delete mode 100644 src/Umbraco.Core/PropertyEditors/EyeDropperColorPickerConfigurationEditor.cs delete mode 100644 src/Umbraco.Core/PropertyEditors/GridEditor.cs delete mode 100644 src/Umbraco.Core/PropertyEditors/INestedContentPropertyIndexValueFactory.cs delete mode 100644 src/Umbraco.Core/PropertyEditors/MarkdownConfiguration.cs delete mode 100644 src/Umbraco.Core/PropertyEditors/MarkdownConfigurationEditor.cs delete mode 100644 src/Umbraco.Core/PropertyEditors/MediaPickerConfiguration.cs delete mode 100644 src/Umbraco.Core/PropertyEditors/MediaPickerConfigurationEditor.cs delete mode 100644 src/Umbraco.Core/PropertyEditors/MemberPickerConfiguration.cs delete mode 100644 src/Umbraco.Core/PropertyEditors/NestedContentConfiguration.cs delete mode 100644 src/Umbraco.Core/PropertyEditors/NestedContentConfigurationEditor.cs delete mode 100644 src/Umbraco.Core/PropertyEditors/ParameterEditorCollection.cs delete mode 100644 src/Umbraco.Core/PropertyEditors/ParameterEditors/ContentTypeParameterEditor.cs delete mode 100644 src/Umbraco.Core/PropertyEditors/ParameterEditors/MultipleContentPickerParameterEditor.cs delete mode 100644 src/Umbraco.Core/PropertyEditors/ParameterEditors/MultipleContentTypeParameterEditor.cs delete mode 100644 src/Umbraco.Core/PropertyEditors/ParameterEditors/MultipleMediaPickerParameterEditor.cs delete mode 100644 src/Umbraco.Core/PropertyEditors/ParameterEditors/MultiplePickerParamateterValueEditorBase.cs delete mode 100644 src/Umbraco.Core/PropertyEditors/ParameterEditors/MultiplePropertyGroupParameterEditor.cs delete mode 100644 src/Umbraco.Core/PropertyEditors/ParameterEditors/MultiplePropertyTypeParameterEditor.cs delete mode 100644 src/Umbraco.Core/PropertyEditors/ParameterEditors/PropertyGroupParameterEditor.cs delete mode 100644 src/Umbraco.Core/PropertyEditors/ParameterEditors/PropertyTypeParameterEditor.cs delete mode 100644 src/Umbraco.Core/PropertyEditors/TrueFalseConfiguration.cs delete mode 100644 src/Umbraco.Core/PropertyEditors/TrueFalseConfigurationEditor.cs delete mode 100644 src/Umbraco.Core/PropertyEditors/UserPickerConfiguration.cs delete mode 100644 src/Umbraco.Core/PropertyEditors/ValueConverters/MediaPickerValueConverter.cs delete mode 100644 src/Umbraco.Core/Services/IEditorConfigurationParser.cs delete mode 100644 src/Umbraco.Infrastructure/Deploy/GridCellValueConnectorExtensions.cs delete mode 100644 src/Umbraco.Infrastructure/Deploy/IGridCellValueConnector.cs delete mode 100644 src/Umbraco.Infrastructure/Deploy/IGridCellValueConnector2.cs delete mode 100644 src/Umbraco.Infrastructure/Models/GridValue.cs delete mode 100644 src/Umbraco.Infrastructure/PropertyEditors/GridConfiguration.cs delete mode 100644 src/Umbraco.Infrastructure/PropertyEditors/GridConfigurationEditor.cs delete mode 100644 src/Umbraco.Infrastructure/PropertyEditors/GridPropertyEditor.cs delete mode 100644 src/Umbraco.Infrastructure/PropertyEditors/GridPropertyIndexValueFactory.cs delete mode 100644 src/Umbraco.Infrastructure/PropertyEditors/MediaPickerPropertyEditor.cs delete mode 100644 src/Umbraco.Infrastructure/PropertyEditors/NestedContentPropertyEditor.cs delete mode 100644 src/Umbraco.Infrastructure/PropertyEditors/NestedContentPropertyHandler.cs delete mode 100644 src/Umbraco.Infrastructure/PropertyEditors/NestedContentPropertyIndexValueFactory.cs delete mode 100644 src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/GridValueConverter.cs delete mode 100644 src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/NestedContentManyValueConverter.cs delete mode 100644 src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/NestedContentSingleValueConverter.cs delete mode 100644 src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/NestedContentValueConverterBase.cs delete mode 100644 src/Umbraco.Infrastructure/Services/EditorConfigurationParser.cs delete mode 100644 src/Umbraco.Infrastructure/Templates/HtmlMacroParameterParser.cs delete mode 100644 src/Umbraco.Infrastructure/Templates/IHtmlMacroParameterParser.cs delete mode 100644 src/Umbraco.Web.BackOffice/Controllers/MacrosController.cs delete mode 100644 tests/Umbraco.Tests.UnitTests/Umbraco.Core/DeliveryApi/MediaPickerValueConverterTests.cs delete mode 100644 tests/Umbraco.Tests.UnitTests/Umbraco.Core/DeliveryApi/NestedContentValueConverterTests.cs delete mode 100644 tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/NestedContentPropertyComponentTests.cs delete mode 100644 tests/Umbraco.Tests.UnitTests/Umbraco.Core/Published/NestedContentTests.cs diff --git a/src/Umbraco.Core/Configuration/Grid/GridConfig.cs b/src/Umbraco.Core/Configuration/Grid/GridConfig.cs deleted file mode 100644 index 67137ab487..0000000000 --- a/src/Umbraco.Core/Configuration/Grid/GridConfig.cs +++ /dev/null @@ -1,43 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Umbraco.Cms.Core.Cache; -using Umbraco.Cms.Core.Hosting; -using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Manifest; -using Umbraco.Cms.Core.Serialization; -using Umbraco.Cms.Web.Common.DependencyInjection; - -namespace Umbraco.Cms.Core.Configuration.Grid; - -[Obsolete("The grid is obsolete, will be removed in V13")] -public class GridConfig : IGridConfig -{ - public GridConfig( - AppCaches appCaches, - ILegacyManifestParser legacyManifestParser, - IJsonSerializer jsonSerializer, - IHostingEnvironment hostingEnvironment, - ILoggerFactory loggerFactory, - IGridEditorsConfigFileProviderFactory gridEditorsConfigFileProviderFactory) - => EditorsConfig = - new GridEditorsConfig(appCaches, hostingEnvironment, legacyManifestParser, jsonSerializer, loggerFactory.CreateLogger(), gridEditorsConfigFileProviderFactory); - - [Obsolete("Use other ctor - Will be removed in Umbraco 13")] - public GridConfig( - AppCaches appCaches, - ILegacyManifestParser legacyManifestParser, - IJsonSerializer jsonSerializer, - IHostingEnvironment hostingEnvironment, - ILoggerFactory loggerFactory) - : this( - appCaches, - legacyManifestParser, - jsonSerializer, - hostingEnvironment, - loggerFactory, - StaticServiceProvider.Instance.GetRequiredService()) - { - } - - public IGridEditorsConfig EditorsConfig { get; } -} diff --git a/src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs b/src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs deleted file mode 100644 index 64d471faf9..0000000000 --- a/src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs +++ /dev/null @@ -1,148 +0,0 @@ -using System.Text; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.FileProviders; -using Microsoft.Extensions.Logging; -using Umbraco.Cms.Core.Cache; -using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Manifest; -using Umbraco.Cms.Core.PropertyEditors; -using Umbraco.Cms.Core.Serialization; -using Umbraco.Cms.Web.Common.DependencyInjection; -using Umbraco.Extensions; -using IHostingEnvironment = Umbraco.Cms.Core.Hosting.IHostingEnvironment; - -namespace Umbraco.Cms.Core.Configuration.Grid; - -internal class GridEditorsConfig : IGridEditorsConfig -{ - private readonly AppCaches _appCaches; - private readonly IHostingEnvironment _hostingEnvironment; - - private readonly IJsonSerializer _jsonSerializer; - private readonly ILogger _logger; - private readonly IGridEditorsConfigFileProviderFactory _gridEditorsConfigFileProviderFactory; - private readonly ILegacyManifestParser _legacyManifestParser; - - public GridEditorsConfig( - AppCaches appCaches, - IHostingEnvironment hostingEnvironment, - ILegacyManifestParser legacyManifestParser, - IJsonSerializer jsonSerializer, - ILogger logger, - IGridEditorsConfigFileProviderFactory gridEditorsConfigFileProviderFactory) - { - _appCaches = appCaches; - _hostingEnvironment = hostingEnvironment; - _legacyManifestParser = legacyManifestParser; - _jsonSerializer = jsonSerializer; - _logger = logger; - _gridEditorsConfigFileProviderFactory = gridEditorsConfigFileProviderFactory; - } - - [Obsolete("Use other ctor - Will be removed in Umbraco 13")] - public GridEditorsConfig( - AppCaches appCaches, - IHostingEnvironment hostingEnvironment, - ILegacyManifestParser legacyManifestParser, - IJsonSerializer jsonSerializer, - ILogger logger) - : this( - appCaches, - hostingEnvironment, - legacyManifestParser, - jsonSerializer, - logger, - StaticServiceProvider.Instance.GetRequiredService()) - { - } - - public IEnumerable Editors - { - get - { - List GetResult() - { - IFileInfo? gridConfig = null; - var editors = new List(); - var configPath = Constants.SystemDirectories.Config.TrimStart(Constants.CharArrays.Tilde); - - // Get physical file if it exists - var configPhysicalDirPath = _hostingEnvironment.MapPathContentRoot(configPath); - - if (Directory.Exists(configPhysicalDirPath) == true) - { - var physicalFileProvider = new PhysicalFileProvider(configPhysicalDirPath); - gridConfig = GetConfigFile(physicalFileProvider, string.Empty); - } - - // If there is no physical file, check in RCLs - if (gridConfig is null) - { - IFileProvider? compositeFileProvider = _gridEditorsConfigFileProviderFactory.Create(); - - if (compositeFileProvider is null) - { - throw new ArgumentNullException(nameof(compositeFileProvider)); - } - - gridConfig = GetConfigFile(compositeFileProvider, configPath); - } - - if (gridConfig is not null) - { - using Stream stream = gridConfig.CreateReadStream(); - using var reader = new StreamReader(stream, Encoding.UTF8); - var sourceString = reader.ReadToEnd(); - - try - { - editors.AddRange(_jsonSerializer.Deserialize>(sourceString)!); - } - catch (Exception ex) - { - _logger.LogError( - ex, - "Could not parse the contents of grid.editors.config.js into a JSON array '{Json}", - sourceString); - } - } - - // Read default from embedded file - else - { - IFileProvider configFileProvider = new EmbeddedFileProvider(GetType().Assembly, "Umbraco.Cms.Core.EmbeddedResources.Grid"); - IFileInfo embeddedConfig = configFileProvider.GetFileInfo("grid.editors.config.js"); - - using Stream stream = embeddedConfig.CreateReadStream(); - using var reader = new StreamReader(stream, Encoding.UTF8); - var sourceString = reader.ReadToEnd(); - editors.AddRange(_jsonSerializer.Deserialize>(sourceString)!); - } - - // Add manifest editors, skip duplicates - foreach (GridEditor gridEditor in _legacyManifestParser.CombinedManifest.GridEditors) - { - if (editors.Contains(gridEditor) == false) - { - editors.Add(gridEditor); - } - } - - return editors; - } - - // cache the result if debugging is disabled - List? result = _hostingEnvironment.IsDebugMode - ? GetResult() - : _appCaches.RuntimeCache.GetCacheItem(typeof(GridEditorsConfig) + ".Editors", GetResult, TimeSpan.FromMinutes(10)); - - return result!; - } - } - - private static IFileInfo? GetConfigFile(IFileProvider fileProvider, string path) - { - IFileInfo fileInfo = fileProvider.GetFileInfo($"{path}/grid.editors.config.js"); - return fileInfo.Exists ? fileInfo : null; - } -} diff --git a/src/Umbraco.Core/Configuration/Grid/IGridConfig.cs b/src/Umbraco.Core/Configuration/Grid/IGridConfig.cs deleted file mode 100644 index 4dd11ee1fc..0000000000 --- a/src/Umbraco.Core/Configuration/Grid/IGridConfig.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Umbraco.Cms.Core.Configuration.Grid; - -public interface IGridConfig -{ - IGridEditorsConfig EditorsConfig { get; } -} diff --git a/src/Umbraco.Core/Configuration/Grid/IGridEditorConfig.cs b/src/Umbraco.Core/Configuration/Grid/IGridEditorConfig.cs deleted file mode 100644 index 5103e7a328..0000000000 --- a/src/Umbraco.Core/Configuration/Grid/IGridEditorConfig.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace Umbraco.Cms.Core.Configuration.Grid; - -public interface IGridEditorConfig -{ - string? Name { get; } - - string? NameTemplate { get; } - - string Alias { get; } - - string? View { get; } - - string? Render { get; } - - string? Icon { get; } - - IDictionary Config { get; } -} diff --git a/src/Umbraco.Core/Configuration/Grid/IGridEditorsConfig.cs b/src/Umbraco.Core/Configuration/Grid/IGridEditorsConfig.cs deleted file mode 100644 index e0d8c8f8d4..0000000000 --- a/src/Umbraco.Core/Configuration/Grid/IGridEditorsConfig.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Umbraco.Cms.Core.Configuration.Grid; - -public interface IGridEditorsConfig -{ - IEnumerable Editors { get; } -} diff --git a/src/Umbraco.Core/Constants-PropertyEditors.cs b/src/Umbraco.Core/Constants-PropertyEditors.cs index 7e982840ec..9466a51b88 100644 --- a/src/Umbraco.Core/Constants-PropertyEditors.cs +++ b/src/Umbraco.Core/Constants-PropertyEditors.cs @@ -100,11 +100,6 @@ public static partial class Constants /// public const string ListView = "Umbraco.ListView"; - /// - /// Media Picker. - /// - public const string MediaPicker = "Umbraco.MediaPicker"; - /// /// Media Picker v.3. /// diff --git a/src/Umbraco.Core/ContentApps/ListViewContentAppFactory.cs b/src/Umbraco.Core/ContentApps/ListViewContentAppFactory.cs index 0e7119b858..1d427347d8 100644 --- a/src/Umbraco.Core/ContentApps/ListViewContentAppFactory.cs +++ b/src/Umbraco.Core/ContentApps/ListViewContentAppFactory.cs @@ -120,8 +120,6 @@ public class ListViewContentAppFactory : IContentAppFactory Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}containerView", Label = string.Empty, Value = null, - View = editor.GetValueEditor().View, - HideLabel = true, Config = listViewConfig, }, }; diff --git a/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs index 0140fb612e..9d2b52bc76 100644 --- a/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs +++ b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs @@ -10,7 +10,6 @@ using Microsoft.Extensions.Options; using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Composing; using Umbraco.Cms.Core.Configuration; -using Umbraco.Cms.Core.Configuration.Grid; using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.Diagnostics; using Umbraco.Cms.Core.Dictionary; @@ -201,9 +200,6 @@ namespace Umbraco.Cms.Core.DependencyInjection Services.AddUnique(); Services.AddUnique(); - // Grid config is not a real config file as we know them - Services.AddUnique(); - Services.AddUnique(); Services.AddUnique(); @@ -245,7 +241,6 @@ namespace Umbraco.Cms.Core.DependencyInjection Services.AddSingleton(); Services.AddSingleton(); - Services.AddSingleton(); // register a server registrar, by default it's the db registrar Services.AddUnique(f => diff --git a/src/Umbraco.Core/Manifest/CompositeLegacyPackageManifest.cs b/src/Umbraco.Core/Manifest/CompositeLegacyPackageManifest.cs index d0512a1753..2692b0b953 100644 --- a/src/Umbraco.Core/Manifest/CompositeLegacyPackageManifest.cs +++ b/src/Umbraco.Core/Manifest/CompositeLegacyPackageManifest.cs @@ -10,7 +10,6 @@ public class CompositeLegacyPackageManifest public CompositeLegacyPackageManifest( IReadOnlyList propertyEditors, IReadOnlyList parameterEditors, - IReadOnlyList gridEditors, IReadOnlyList contentApps, IReadOnlyList dashboards, IReadOnlyList sections, @@ -19,7 +18,6 @@ public class CompositeLegacyPackageManifest { PropertyEditors = propertyEditors ?? throw new ArgumentNullException(nameof(propertyEditors)); ParameterEditors = parameterEditors ?? throw new ArgumentNullException(nameof(parameterEditors)); - GridEditors = gridEditors ?? throw new ArgumentNullException(nameof(gridEditors)); ContentApps = contentApps ?? throw new ArgumentNullException(nameof(contentApps)); Dashboards = dashboards ?? throw new ArgumentNullException(nameof(dashboards)); Sections = sections ?? throw new ArgumentNullException(nameof(sections)); @@ -37,11 +35,6 @@ public class CompositeLegacyPackageManifest /// public IReadOnlyList ParameterEditors { get; } - /// - /// Gets or sets the grid editors listed in the manifest. - /// - public IReadOnlyList GridEditors { get; } - /// /// Gets or sets the content apps listed in the manifest. /// diff --git a/src/Umbraco.Core/Manifest/ILegacyPackageManifest.cs b/src/Umbraco.Core/Manifest/ILegacyPackageManifest.cs index 21e1903e18..073290d405 100644 --- a/src/Umbraco.Core/Manifest/ILegacyPackageManifest.cs +++ b/src/Umbraco.Core/Manifest/ILegacyPackageManifest.cs @@ -40,12 +40,6 @@ public interface ILegacyPackageManifest [DataMember(Name = "parameterEditors")] IDataEditor[] ParameterEditors { get; set; } - /// - /// Gets or sets the grid editors listed in the manifest. - /// - [DataMember(Name = "gridEditors")] - GridEditor[] GridEditors { get; set; } - /// /// Gets or sets the content apps listed in the manifest. /// diff --git a/src/Umbraco.Core/Manifest/LegacyPackageManifest.cs b/src/Umbraco.Core/Manifest/LegacyPackageManifest.cs index 116c9d88fe..ca3028316b 100644 --- a/src/Umbraco.Core/Manifest/LegacyPackageManifest.cs +++ b/src/Umbraco.Core/Manifest/LegacyPackageManifest.cs @@ -145,15 +145,6 @@ public class LegacyPackageManifest [DataMember(Name = "parameterEditors")] public IDataEditor[] ParameterEditors { get; set; } = Array.Empty(); - /// - /// Gets or sets the grid editors listed in the manifest. - /// - /// - /// The grid editors. - /// - [DataMember(Name = "gridEditors")] - public GridEditor[] GridEditors { get; set; } = Array.Empty(); - /// /// Gets or sets the content apps listed in the manifest. /// diff --git a/src/Umbraco.Core/Models/ContentEditing/ContentPropertyDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/ContentPropertyDisplay.cs index 26e35270fa..6b7e7a20ac 100644 --- a/src/Umbraco.Core/Models/ContentEditing/ContentPropertyDisplay.cs +++ b/src/Umbraco.Core/Models/ContentEditing/ContentPropertyDisplay.cs @@ -25,19 +25,9 @@ public class ContentPropertyDisplay : ContentPropertyBasic [DataMember(Name = "description")] public string? Description { get; set; } - [DataMember(Name = "view", IsRequired = true)] - [Required(AllowEmptyStrings = false)] - public string? View { get; set; } - [DataMember(Name = "config")] public IDictionary? Config { get; set; } - [DataMember(Name = "hideLabel")] - public bool HideLabel { get; set; } - - [DataMember(Name = "labelOnTop")] - public bool? LabelOnTop { get; set; } - [DataMember(Name = "validation")] public PropertyTypeValidation Validation { get; set; } diff --git a/src/Umbraco.Core/Models/ContentEditing/DataTypeBasic.cs b/src/Umbraco.Core/Models/ContentEditing/DataTypeBasic.cs index 7bb0d427ea..c141ffd7f1 100644 --- a/src/Umbraco.Core/Models/ContentEditing/DataTypeBasic.cs +++ b/src/Umbraco.Core/Models/ContentEditing/DataTypeBasic.cs @@ -16,10 +16,6 @@ public class DataTypeBasic : EntityBasic [ReadOnly(true)] public bool IsSystemDataType { get; set; } - [DataMember(Name = "group")] - [ReadOnly(true)] - public string? Group { get; set; } - [DataMember(Name = "hasPrevalues")] [ReadOnly(true)] public bool HasPrevalues { get; set; } diff --git a/src/Umbraco.Core/Models/ContentEditing/DataTypeConfigurationFieldDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/DataTypeConfigurationFieldDisplay.cs index a324bb4bce..edef88f2e7 100644 --- a/src/Umbraco.Core/Models/ContentEditing/DataTypeConfigurationFieldDisplay.cs +++ b/src/Umbraco.Core/Models/ContentEditing/DataTypeConfigurationFieldDisplay.cs @@ -8,30 +8,6 @@ namespace Umbraco.Cms.Core.Models.ContentEditing; [DataContract(Name = "preValue", Namespace = "")] public class DataTypeConfigurationFieldDisplay : DataTypeConfigurationFieldSave { - /// - /// The name to display for this pre-value field - /// - [DataMember(Name = "label", IsRequired = true)] - public string? Name { get; set; } - - /// - /// The description to display for this pre-value field - /// - [DataMember(Name = "description")] - public string? Description { get; set; } - - /// - /// Specifies whether to hide the label for the pre-value - /// - [DataMember(Name = "hideLabel")] - public bool HideLabel { get; set; } - - /// - /// The view to render for the field - /// - [DataMember(Name = "view", IsRequired = true)] - public string? View { get; set; } - /// /// This allows for custom configuration to be injected into the pre-value editor /// diff --git a/src/Umbraco.Core/Models/ContentEditing/PropertyEditorBasic.cs b/src/Umbraco.Core/Models/ContentEditing/PropertyEditorBasic.cs index 498537cf1e..3c132c0a84 100644 --- a/src/Umbraco.Core/Models/ContentEditing/PropertyEditorBasic.cs +++ b/src/Umbraco.Core/Models/ContentEditing/PropertyEditorBasic.cs @@ -10,10 +10,4 @@ public class PropertyEditorBasic { [DataMember(Name = "alias")] public string? Alias { get; set; } - - [DataMember(Name = "name")] - public string? Name { get; set; } - - [DataMember(Name = "icon")] - public string? Icon { get; set; } } diff --git a/src/Umbraco.Core/Models/ContentEditing/PropertyTypeBasic.cs b/src/Umbraco.Core/Models/ContentEditing/PropertyTypeBasic.cs index 4574e62cde..92eaf0007e 100644 --- a/src/Umbraco.Core/Models/ContentEditing/PropertyTypeBasic.cs +++ b/src/Umbraco.Core/Models/ContentEditing/PropertyTypeBasic.cs @@ -53,10 +53,6 @@ public class PropertyTypeBasic [ReadOnly(true)] public string? DataTypeName { get; set; } - [DataMember(Name = "dataTypeIcon")] - [ReadOnly(true)] - public string? DataTypeIcon { get; set; } - // SD: Is this really needed ? [DataMember(Name = "groupId")] public int GroupId { get; set; } diff --git a/src/Umbraco.Core/Models/IDataValueEditor.cs b/src/Umbraco.Core/Models/IDataValueEditor.cs index 3e749b6d20..d733488be8 100644 --- a/src/Umbraco.Core/Models/IDataValueEditor.cs +++ b/src/Umbraco.Core/Models/IDataValueEditor.cs @@ -11,11 +11,6 @@ namespace Umbraco.Cms.Core.Models; /// This is the base interface for parameter and property value editors. public interface IDataValueEditor { - /// - /// Gets the editor view. - /// - string? View { get; } - /// /// Gets the type of the value. /// @@ -27,11 +22,6 @@ public interface IDataValueEditor /// bool IsReadOnly { get; } - /// - /// Gets a value indicating whether to display the associated label. - /// - bool HideLabel { get; } - /// /// Gets a value indicating whether the IDataValueEditor supports readonly mode /// diff --git a/src/Umbraco.Core/Models/Mapping/ContentPropertyDisplayMapper.cs b/src/Umbraco.Core/Models/Mapping/ContentPropertyDisplayMapper.cs index a090caa848..0a227c4533 100644 --- a/src/Umbraco.Core/Models/Mapping/ContentPropertyDisplayMapper.cs +++ b/src/Umbraco.Core/Models/Mapping/ContentPropertyDisplayMapper.cs @@ -44,15 +44,10 @@ internal class ContentPropertyDisplayMapper : ContentPropertyBasicMapper properties = _propertyEditors .Where(x => !x.IsDeprecated || _contentSettings.ShowDeprecatedPropertyEditors || source.EditorAlias == x.Alias) - .OrderBy(x => x.Name); + .OrderBy(x => x.Alias); return context.MapEnumerable(properties).WhereNotNull(); } diff --git a/src/Umbraco.Core/Models/Mapping/MacroMapDefinition.cs b/src/Umbraco.Core/Models/Mapping/MacroMapDefinition.cs deleted file mode 100644 index 62256a9bf0..0000000000 --- a/src/Umbraco.Core/Models/Mapping/MacroMapDefinition.cs +++ /dev/null @@ -1,86 +0,0 @@ -using Microsoft.Extensions.Logging; -using Umbraco.Cms.Core.Mapping; -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Cms.Core.PropertyEditors; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.Models.Mapping; - -public class MacroMapDefinition : IMapDefinition -{ - private readonly ILogger _logger; - private readonly ParameterEditorCollection _parameterEditors; - - public MacroMapDefinition(ParameterEditorCollection parameterEditors, ILogger logger) - { - _parameterEditors = parameterEditors; - _logger = logger; - } - - public void DefineMaps(IUmbracoMapper mapper) - { - mapper.Define((source, context) => new EntityBasic(), Map); - mapper.Define((source, context) => new MacroDisplay(), Map); - mapper.Define>((source, context) => - context.MapEnumerable(source.Properties.Values).WhereNotNull()); - mapper.Define((source, context) => new MacroParameter(), Map); - } - - // Umbraco.Code.MapAll -Trashed -AdditionalData - private static void Map(IMacro source, EntityBasic target, MapperContext context) - { - target.Alias = source.Alias; - target.Icon = Constants.Icons.Macro; - target.Id = source.Id; - target.Key = source.Key; - target.Name = source.Name; - target.ParentId = -1; - target.Path = "-1," + source.Id; - target.Udi = Udi.Create(Constants.UdiEntityType.Macro, source.Key); - } - - private void Map(IMacro source, MacroDisplay target, MapperContext context) - { - target.Alias = source.Alias; - target.Icon = Constants.Icons.Macro; - target.Id = source.Id; - target.Key = source.Key; - target.Name = source.Name; - target.ParentId = -1; - target.Path = "-1," + source.Id; - target.Udi = Udi.Create(Constants.UdiEntityType.Macro, source.Key); - target.CacheByPage = source.CacheByPage; - target.CacheByUser = source.CacheByMember; - target.CachePeriod = source.CacheDuration; - target.UseInEditor = source.UseInEditor; - target.RenderInEditor = !source.DontRender; - target.View = source.MacroSource; - } - - // Umbraco.Code.MapAll -Value - private void Map(IMacroProperty source, MacroParameter target, MapperContext context) - { - target.Alias = source.Alias; - target.Name = source.Name; - target.SortOrder = source.SortOrder; - - // map the view and the config - // we need to show the deprecated ones for backwards compatibility - IDataEditor? paramEditor = _parameterEditors[source.EditorAlias]; // TODO: include/filter deprecated?! - if (paramEditor == null) - { - // we'll just map this to a text box - paramEditor = _parameterEditors[Constants.PropertyEditors.Aliases.TextBox]; - _logger.LogWarning( - "Could not resolve a parameter editor with alias {PropertyEditorAlias}, a textbox will be rendered in it's place", - source.EditorAlias); - } - - target.View = paramEditor?.GetValueEditor().View; - - // sets the parameter configuration to be the default configuration editor's configuration, - // ie configurationEditor.DefaultConfigurationObject, prepared for the value editor - IConfigurationEditor? configurationEditor = paramEditor?.GetConfigurationEditor(); - target.Configuration = configurationEditor?.FromConfigurationEditor(configurationEditor.DefaultConfiguration); - } -} diff --git a/src/Umbraco.Core/Models/Mapping/MemberTabsAndPropertiesMapper.cs b/src/Umbraco.Core/Models/Mapping/MemberTabsAndPropertiesMapper.cs index 3c20babecc..f1b94e3142 100644 --- a/src/Umbraco.Core/Models/Mapping/MemberTabsAndPropertiesMapper.cs +++ b/src/Umbraco.Core/Models/Mapping/MemberTabsAndPropertiesMapper.cs @@ -151,8 +151,6 @@ public class MemberTabsAndPropertiesMapper : TabsAndPropertiesMapper prop.IsSensitive = true; // mark this property as readonly so that it does not post any data prop.Readonly = true; - // replace this editor with a sensitive value - prop.View = "sensitivevalue"; // clear the value prop.Value = null; } @@ -180,7 +178,6 @@ public class MemberTabsAndPropertiesMapper : TabsAndPropertiesMapper Value = member.Username }; - prop.View = "textbox"; prop.Validation.Mandatory = true; return prop; } @@ -224,7 +221,6 @@ public class MemberTabsAndPropertiesMapper : TabsAndPropertiesMapper Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}email", Label = _localizedTextService.Localize("general","email"), Value = member.Email, - View = "email", Validation = { Mandatory = true } }, new() @@ -236,7 +232,6 @@ public class MemberTabsAndPropertiesMapper : TabsAndPropertiesMapper // TODO: why ignoreCase, what are we doing here?! { "newPassword", member.GetAdditionalDataValueIgnoreCase("NewPassword", null) } }, - View = "changepassword", Config = GetPasswordConfig(member) // Initialize the dictionary with the configuration from the default membership provider }, new() @@ -244,7 +239,6 @@ public class MemberTabsAndPropertiesMapper : TabsAndPropertiesMapper Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}membergroup", Label = _localizedTextService.Localize("content","membergroup"), Value = GetMemberGroupValue(member.Username), - View = "membergroups", Config = new Dictionary { { "IsRequired", true } @@ -257,7 +251,6 @@ public class MemberTabsAndPropertiesMapper : TabsAndPropertiesMapper Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}failedPasswordAttempts", Label = _localizedTextService.Localize("user", "failedPasswordAttempts"), Value = member.FailedPasswordAttempts, - View = "readonlyvalue", IsSensitive = true, }, @@ -266,7 +259,6 @@ public class MemberTabsAndPropertiesMapper : TabsAndPropertiesMapper Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}approved", Label = _localizedTextService.Localize("user", "stateApproved"), Value = member.IsApproved, - View = "boolean", IsSensitive = true, Readonly = false, }, @@ -276,7 +268,6 @@ public class MemberTabsAndPropertiesMapper : TabsAndPropertiesMapper Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}lockedOut", Label = _localizedTextService.Localize("user", "stateLockedOut"), Value = member.IsLockedOut, - View = "boolean", IsSensitive = true, Readonly = !member.IsLockedOut, // IMember.IsLockedOut can't be set to true, so make it readonly when that's the case (you can only unlock) }, @@ -287,7 +278,6 @@ public class MemberTabsAndPropertiesMapper : TabsAndPropertiesMapper Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}twoFactorEnabled", Label = _localizedTextService.Localize("member", "2fa"), Value = isTwoFactorEnabled, - View = "boolean", IsSensitive = true, Readonly = !isTwoFactorEnabled, // The value can't be set to true, so make it readonly when that's the case (you can only disable) }, @@ -297,7 +287,6 @@ public class MemberTabsAndPropertiesMapper : TabsAndPropertiesMapper Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}lastLockoutDate", Label = _localizedTextService.Localize("user", "lastLockoutDate"), Value = member.LastLockoutDate?.ToString(), - View = "readonlyvalue", IsSensitive = true, }, @@ -306,7 +295,6 @@ public class MemberTabsAndPropertiesMapper : TabsAndPropertiesMapper Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}lastLoginDate", Label = _localizedTextService.Localize("user", "lastLogin"), Value = member.LastLoginDate?.ToString(), - View = "readonlyvalue", IsSensitive = true, }, @@ -315,7 +303,6 @@ public class MemberTabsAndPropertiesMapper : TabsAndPropertiesMapper Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}lastPasswordChangeDate", Label = _localizedTextService.Localize("user", "lastPasswordChangeDate"), Value = member.LastPasswordChangeDate?.ToString(), - View = "readonlyvalue", IsSensitive = true, }, }; @@ -328,7 +315,6 @@ public class MemberTabsAndPropertiesMapper : TabsAndPropertiesMapper if (property.IsSensitive) { property.Value = null; - property.View = "sensitivevalue"; property.Readonly = true; } } diff --git a/src/Umbraco.Core/Models/Mapping/PropertyTypeGroupMapper.cs b/src/Umbraco.Core/Models/Mapping/PropertyTypeGroupMapper.cs index 6db5c56f94..8d64518860 100644 --- a/src/Umbraco.Core/Models/Mapping/PropertyTypeGroupMapper.cs +++ b/src/Umbraco.Core/Models/Mapping/PropertyTypeGroupMapper.cs @@ -272,7 +272,6 @@ public class PropertyTypeGroupMapper PatternMessage = p.ValidationRegExpMessage, }, Label = p.Name, - View = propertyEditor?.GetValueEditor().View, Config = config, // Value = "", @@ -281,7 +280,6 @@ public class PropertyTypeGroupMapper DataTypeId = p.DataTypeId, DataTypeKey = p.DataTypeKey, DataTypeName = dataType?.Name, - DataTypeIcon = propertyEditor?.Icon, SortOrder = p.SortOrder, ContentTypeId = contentType.Id, ContentTypeName = contentType.Name, diff --git a/src/Umbraco.Core/PropertyEditors/BlockGridConfiguration.cs b/src/Umbraco.Core/PropertyEditors/BlockGridConfiguration.cs index 1fab493825..d628537ab3 100644 --- a/src/Umbraco.Core/PropertyEditors/BlockGridConfiguration.cs +++ b/src/Umbraco.Core/PropertyEditors/BlockGridConfiguration.cs @@ -1,8 +1,6 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using System.Runtime.Serialization; - namespace Umbraco.Cms.Core.PropertyEditors; /// @@ -10,160 +8,45 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// public class BlockGridConfiguration { - [ConfigurationField("blocks", "Blocks", "views/propertyeditors/blockgrid/prevalue/blockgrid.blockconfiguration.html", Description = "Define Blocks based on Element Types. Use Groups to help organise their selection. Example Groups: 'Layout' and 'Content'")] - public BlockGridBlockConfiguration[] Blocks { get; set; } = Array.Empty(); + [ConfigurationField("blocks")] + public BlockGridBlockConfiguration[] Blocks { get; set; } = Array.Empty(); - [ConfigurationField("blockGroups", "Block Groups", "views/propertyeditors/blockgrid/prevalue/blockgrid.groupconfiguration.html", HideLabel = true)] - public BlockGridGroupConfiguration[] BlockGroups { get; set; } = Array.Empty(); - - [ConfigurationField("validationLimit", "Amount", "numberrange", Description = "Set the required range for the allowed number of blocks")] + [ConfigurationField("validationLimit")] public NumberRange ValidationLimit { get; set; } = new NumberRange(); - [ConfigurationField("useLiveEditing", "Live editing mode", "boolean", Description = "Live update content when editing in overlay")] - public bool UseLiveEditing { get; set; } - - [ConfigurationField("maxPropertyWidth", "Editor width", "textstring", Description = "Optional css overwrite. (example: 1200px or 100%)")] - public string? MaxPropertyWidth { get; set; } - - [ConfigurationField("gridColumns", "Grid Columns", "number", Description = "Set the number of columns for the layout. (defaults to 12)")] + [ConfigurationField("gridColumns")] public int? GridColumns { get; set; } - [ConfigurationField("layoutStylesheet", "Layout Stylesheet", "views/propertyeditors/blockgrid/prevalue/blockgrid.stylesheetpicker.html", Description = "Override default stylesheet for backoffice layout.")] - public string? LayoutStylesheet { get; set; } - - [ConfigurationField("createLabel", "Create Button Label", "textstring", Description = "Override the label text for adding a new block, Example 'Add Widget'")] - public string? CreateLabel { get; set; } - - [DataContract] public class BlockGridBlockConfiguration : IBlockConfiguration { - [DataMember(Name ="columnSpanOptions")] - public BlockGridColumnSpanOption[] ColumnSpanOptions { get; set; } = Array.Empty(); - - [DataMember(Name ="rowMinSpan")] - public int? RowMinSpan { get; set; } - - [DataMember(Name ="rowMaxSpan")] - public int? RowMaxSpan { get; set; } - - [DataMember(Name ="allowAtRoot")] - public bool AllowAtRoot { get; set; } = true; - - [DataMember(Name ="allowInAreas")] - public bool AllowInAreas { get; set; } = true; - - [DataMember(Name ="areaGridColumns")] public int? AreaGridColumns { get; set; } - [DataMember(Name = "areas")] public BlockGridAreaConfiguration[] Areas { get; set; } = Array.Empty(); - [DataMember(Name ="backgroundColor")] - public string? BackgroundColor { get; set; } - - [DataMember(Name ="iconColor")] - public string? IconColor { get; set; } - - [DataMember(Name ="thumbnail")] - public string? Thumbnail { get; set; } - - [DataMember(Name ="contentElementTypeKey")] public Guid ContentElementTypeKey { get; set; } - [DataMember(Name ="settingsElementTypeKey")] public Guid? SettingsElementTypeKey { get; set; } - - [DataMember(Name ="view")] - public string? View { get; set; } - - [DataMember(Name ="stylesheet")] - public string? Stylesheet { get; set; } - - [DataMember(Name ="label")] - public string? Label { get; set; } - - [DataMember(Name ="editorSize")] - public string? EditorSize { get; set; } - - [DataMember(Name ="inlineEditing")] - public bool InlineEditing { get; set; } - - [DataMember(Name ="forceHideContentEditorInOverlay")] - public bool ForceHideContentEditorInOverlay { get; set; } - - [DataMember(Name ="groupKey")] - public string? GroupKey { get; set; } } - [DataContract] - public class BlockGridColumnSpanOption - { - [DataMember(Name ="columnSpan")] - public int? ColumnSpan { get; set; } - } - - [DataContract] - public class BlockGridGroupConfiguration - { - - [DataMember(Name ="key")] - public Guid Key { get; set; } - - [DataMember(Name ="name")] - public string? Name { get; set; } - } - - [DataContract] public class NumberRange { - [DataMember(Name ="min")] public int? Min { get; set; } - [DataMember(Name ="max")] public int? Max { get; set; } } - [DataContract] public class BlockGridAreaConfiguration { - [DataMember(Name ="key")] public Guid Key { get; set; } - [DataMember(Name ="alias")] public string? Alias { get; set; } - [DataMember(Name ="createLabel")] - public string? CreateLabel { get; set; } - - [DataMember(Name ="columnSpan")] public int? ColumnSpan { get; set; } - [DataMember(Name ="rowSpan")] public int? RowSpan { get; set; } - [DataMember(Name ="minAllowed")] public int? MinAllowed { get; set; } - [DataMember(Name ="maxAllowed")] - public int? MaxAllowed { get; set; } - - [DataMember(Name ="specifiedAllowance")] - public BlockGridAreaConfigurationSpecifiedAllowance[] SpecifiedAllowance { get; set; } = Array.Empty(); - } - - [DataContract] - public class BlockGridAreaConfigurationSpecifiedAllowance - { - [DataMember(Name ="elementTypeKey")] - public Guid? ElementTypeKey { get; set; } - - [DataMember(Name ="groupKey")] - public Guid? GroupKey { get; set; } - - [DataMember(Name ="minAllowed")] - public int? MinAllowed { get; set; } - - [DataMember(Name ="maxAllowed")] public int? MaxAllowed { get; set; } } } diff --git a/src/Umbraco.Core/PropertyEditors/BlockListConfiguration.cs b/src/Umbraco.Core/PropertyEditors/BlockListConfiguration.cs index 1184f2524f..f398d75eac 100644 --- a/src/Umbraco.Core/PropertyEditors/BlockListConfiguration.cs +++ b/src/Umbraco.Core/PropertyEditors/BlockListConfiguration.cs @@ -1,8 +1,6 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using System.Runtime.Serialization; - namespace Umbraco.Cms.Core.PropertyEditors; /// @@ -10,69 +8,26 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// public class BlockListConfiguration { - [ConfigurationField("blocks", "Available Blocks", "views/propertyeditors/blocklist/prevalue/blocklist.blockconfiguration.html", Description = "Define the available blocks.")] + [ConfigurationField("blocks")] public BlockConfiguration[] Blocks { get; set; } = null!; - [ConfigurationField("validationLimit", "Amount", "numberrange", Description = "Set a required range of blocks")] + [ConfigurationField("validationLimit")] public NumberRange ValidationLimit { get; set; } = new(); - [ConfigurationField("useSingleBlockMode", "Single block mode", "boolean", - Description = @"When in Single block mode, the output will be BlockListItem<>, instead of BlockListModel. - -**NOTE:** -Single block mode requires a maximum of one available block, and an amount set to minimum 1 and maximum 1 blocks.")] + [ConfigurationField("useSingleBlockMode")] public bool UseSingleBlockMode { get; set; } - [ConfigurationField("useLiveEditing", "Live editing mode", "boolean", Description = "Live editing in editor overlays for live updated custom views or labels using custom expression.")] - public bool UseLiveEditing { get; set; } - - [ConfigurationField("useInlineEditingAsDefault", "Inline editing mode", "boolean", Description = "Use the inline editor as the default block view.")] - public bool UseInlineEditingAsDefault { get; set; } - - [ConfigurationField("maxPropertyWidth", "Property editor width", "textstring", Description = "Optional CSS override, example: 800px or 100%")] - public string? MaxPropertyWidth { get; set; } - - [DataContract] public class BlockConfiguration : IBlockConfiguration { - [DataMember(Name = "backgroundColor")] - public string? BackgroundColor { get; set; } - - [DataMember(Name = "iconColor")] - public string? IconColor { get; set; } - - [DataMember(Name = "thumbnail")] - public string? Thumbnail { get; set; } - - [DataMember(Name = "contentElementTypeKey")] public Guid ContentElementTypeKey { get; set; } - [DataMember(Name = "settingsElementTypeKey")] public Guid? SettingsElementTypeKey { get; set; } - - [DataMember(Name = "view")] - public string? View { get; set; } - - [DataMember(Name = "stylesheet")] - public string? Stylesheet { get; set; } - - [DataMember(Name = "label")] - public string? Label { get; set; } - - [DataMember(Name = "editorSize")] - public string? EditorSize { get; set; } - - [DataMember(Name = "forceHideContentEditorInOverlay")] - public bool ForceHideContentEditorInOverlay { get; set; } } - [DataContract] public class NumberRange { - [DataMember(Name = "min")] public int? Min { get; set; } - [DataMember(Name = "max")] public int? Max { get; set; } } } diff --git a/src/Umbraco.Core/PropertyEditors/ColorPickerConfiguration.cs b/src/Umbraco.Core/PropertyEditors/ColorPickerConfiguration.cs index 02fc30d68b..e2c2279248 100644 --- a/src/Umbraco.Core/PropertyEditors/ColorPickerConfiguration.cs +++ b/src/Umbraco.Core/PropertyEditors/ColorPickerConfiguration.cs @@ -3,12 +3,18 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// /// Represents the configuration for the color picker value editor. /// -public class ColorPickerConfiguration : ValueListConfiguration +public class ColorPickerConfiguration { - [ConfigurationField( - "useLabel", - "Include labels?", - "boolean", - Description = "Stores colors as a Json object containing both the color hex string and label, rather than just the hex string.")] + [ConfigurationField("useLabel")] public bool UseLabel { get; set; } + + [ConfigurationField("items")] + public List Items { get; set; } = new(); + + public class ColorPickerItem + { + public required string Value { get; set; } + + public required string Label { get; set; } + } } diff --git a/src/Umbraco.Core/PropertyEditors/ConfigurationEditorOfTConfiguration.cs b/src/Umbraco.Core/PropertyEditors/ConfigurationEditorOfTConfiguration.cs index 2a216098f9..fa135e2ead 100644 --- a/src/Umbraco.Core/PropertyEditors/ConfigurationEditorOfTConfiguration.cs +++ b/src/Umbraco.Core/PropertyEditors/ConfigurationEditorOfTConfiguration.cs @@ -2,13 +2,9 @@ // See LICENSE for more details. using System.Reflection; -using Microsoft.Extensions.DependencyInjection; using Umbraco.Cms.Core.Composing; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.Serialization; -using Umbraco.Cms.Core.Services; -using Umbraco.Extensions; namespace Umbraco.Cms.Core.PropertyEditors; @@ -18,21 +14,13 @@ namespace Umbraco.Cms.Core.PropertyEditors; public abstract class ConfigurationEditor : ConfigurationEditor where TConfiguration : new() { - private readonly IEditorConfigurationParser _editorConfigurationParser; - - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] - protected ConfigurationEditor(IIOHelper ioHelper) - : this(ioHelper, StaticServiceProvider.Instance.GetRequiredService()) - { - } - /// /// Initializes a new instance of the class. /// - protected ConfigurationEditor(IIOHelper ioHelper, IEditorConfigurationParser editorConfigurationParser) - : base(DiscoverFields(ioHelper)) => - _editorConfigurationParser = editorConfigurationParser; + protected ConfigurationEditor(IIOHelper ioHelper) + : base(DiscoverFields(ioHelper)) + { + } /// public override object ToConfigurationObject( @@ -82,8 +70,6 @@ public abstract class ConfigurationEditor : ConfigurationEditor ConfigurationField field; - var attributeView = ioHelper.ResolveRelativeOrVirtualUrl(attribute.View); - // if the field does not have its own type, use the base type if (attribute.Type == null) { @@ -91,13 +77,8 @@ public abstract class ConfigurationEditor : ConfigurationEditor { // if the key is empty then use the property name Key = string.IsNullOrWhiteSpace(attribute.Key) ? property.Name : attribute.Key, - Name = attribute.Name, PropertyName = property.Name, PropertyType = property.PropertyType, - Description = attribute.Description, - HideLabel = attribute.HideLabel, - SortOrder = attribute.SortOrder, - View = attributeView, }; fields.Add(field); @@ -122,8 +103,6 @@ public abstract class ConfigurationEditor : ConfigurationEditor field.PropertyName = property.Name; field.PropertyType = property.PropertyType; - field.SortOrder = attribute.SortOrder; - if (!string.IsNullOrWhiteSpace(attribute.Key)) { field.Key = attribute.Key; @@ -134,28 +113,8 @@ public abstract class ConfigurationEditor : ConfigurationEditor { field.Key = property.Name; } - - if (!string.IsNullOrWhiteSpace(attribute.Name)) - { - field.Name = attribute.Name; - } - - if (!string.IsNullOrWhiteSpace(attribute.View)) - { - field.View = attributeView; - } - - if (!string.IsNullOrWhiteSpace(attribute.Description)) - { - field.Description = attribute.Description; - } - - if (attribute.HideLabelSettable.HasValue) - { - field.HideLabel = attribute.HideLabel; - } } - return fields.OrderBy(x => x.SortOrder).ToList(); + return fields; } } diff --git a/src/Umbraco.Core/PropertyEditors/ConfigurationField.cs b/src/Umbraco.Core/PropertyEditors/ConfigurationField.cs index def2135bbd..690b5584e3 100644 --- a/src/Umbraco.Core/PropertyEditors/ConfigurationField.cs +++ b/src/Umbraco.Core/PropertyEditors/ConfigurationField.cs @@ -1,5 +1,4 @@ using System.Runtime.Serialization; -using Umbraco.Cms.Core.Models.ContentEditing; using Umbraco.Extensions; namespace Umbraco.Cms.Core.PropertyEditors; @@ -43,12 +42,7 @@ public class ConfigurationField return; } - Name = attribute.Name; - Description = attribute.Description; - HideLabel = attribute.HideLabel; Key = attribute.Key; - View = attribute.View; - SortOrder = attribute.SortOrder; } /// @@ -57,12 +51,6 @@ public class ConfigurationField [DataMember(Name = "key", IsRequired = true)] public string Key { get; set; } = null!; - /// - /// Gets or sets the name of the field. - /// - [DataMember(Name = "label", IsRequired = true)] - public string? Name { get; set; } - /// /// Gets or sets the property name of the field. /// @@ -73,36 +61,6 @@ public class ConfigurationField /// public Type? PropertyType { get; set; } - /// - /// Gets or sets the description of the field. - /// - [DataMember(Name = "description")] - public string? Description { get; set; } - - /// - /// Gets or sets the sort order of the field. - /// - [DataMember(Name = "sortOrder")] - public int SortOrder { get; set; } - - /// - /// Gets or sets a value indicating whether to hide the label of the field. - /// - [DataMember(Name = "hideLabel")] - public bool HideLabel { get; set; } - - /// - /// Gets or sets the view to used in the editor. - /// - /// - /// - /// Can be the full virtual path, or the relative path to the Umbraco folder, - /// or a simple view name which will map to ~/Views/PreValueEditors/{view}.html. - /// - /// - [DataMember(Name = "view", IsRequired = true)] - public string? View { get; set; } - /// /// Gets the validators of the field. /// diff --git a/src/Umbraco.Core/PropertyEditors/ConfigurationFieldAttribute.cs b/src/Umbraco.Core/PropertyEditors/ConfigurationFieldAttribute.cs index 9eec779c2c..6a0092a84e 100644 --- a/src/Umbraco.Core/PropertyEditors/ConfigurationFieldAttribute.cs +++ b/src/Umbraco.Core/PropertyEditors/ConfigurationFieldAttribute.cs @@ -22,9 +22,7 @@ public class ConfigurationFieldAttribute : Attribute /// Initializes a new instance of the class. /// /// The unique identifier of the field. - /// The friendly name of the field. - /// The view to use to render the field editor. - public ConfigurationFieldAttribute(string key, string name, string view) + public ConfigurationFieldAttribute(string key) { if (key == null) { @@ -36,73 +34,7 @@ public class ConfigurationFieldAttribute : Attribute throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(key)); } - if (name == null) - { - throw new ArgumentNullException(nameof(name)); - } - - if (string.IsNullOrWhiteSpace(name)) - { - throw new ArgumentException( - "Value can't be empty or consist only of white-space characters.", - nameof(name)); - } - - if (view == null) - { - throw new ArgumentNullException(nameof(view)); - } - - if (string.IsNullOrWhiteSpace(view)) - { - throw new ArgumentException( - "Value can't be empty or consist only of white-space characters.", - nameof(view)); - } - Key = key; - Name = name; - View = view; - } - - /// - /// Initializes a new instance of the class. - /// - /// The friendly name of the field. - /// The view to use to render the field editor. - /// - /// When no key is specified, the will derive a key - /// from the name of the property marked with this attribute. - /// - public ConfigurationFieldAttribute(string name, string view) - { - if (name == null) - { - throw new ArgumentNullException(nameof(name)); - } - - if (string.IsNullOrWhiteSpace(name)) - { - throw new ArgumentException( - "Value can't be empty or consist only of white-space characters.", - nameof(name)); - } - - if (view == null) - { - throw new ArgumentNullException(nameof(view)); - } - - if (string.IsNullOrWhiteSpace(view)) - { - throw new ArgumentException( - "Value can't be empty or consist only of white-space characters.", - nameof(view)); - } - - Name = name; - View = view; - Key = string.Empty; } /// @@ -114,40 +46,6 @@ public class ConfigurationFieldAttribute : Attribute /// public string Key { get; } - /// - /// Gets the friendly name of the field. - /// - public string? Name { get; } - - /// - /// Gets the view to use to render the field editor. - /// - public string? View { get; } - - /// - /// Gets or sets the sort order to use to render the field editor. - /// - public int SortOrder { get; set; } - - /// - /// Gets or sets the description of the field. - /// - public string? Description { get; set; } - - /// - /// Gets or sets a value indicating whether the field editor should be displayed without its label. - /// - public bool HideLabel - { - get => HideLabelSettable.ValueOrDefault(false); - set => HideLabelSettable.Set(value); - } - - /// - /// Gets the settable underlying . - /// - public Settable HideLabelSettable { get; } = new(); - /// /// Gets or sets the type of the field. /// diff --git a/src/Umbraco.Core/PropertyEditors/ContentPickerConfiguration.cs b/src/Umbraco.Core/PropertyEditors/ContentPickerConfiguration.cs index 8cbaecdbdb..fbef443da1 100644 --- a/src/Umbraco.Core/PropertyEditors/ContentPickerConfiguration.cs +++ b/src/Umbraco.Core/PropertyEditors/ContentPickerConfiguration.cs @@ -2,16 +2,6 @@ namespace Umbraco.Cms.Core.PropertyEditors; public class ContentPickerConfiguration : IIgnoreUserStartNodesConfig { - [ConfigurationField("showOpenButton", "Show open button", "boolean", Description = "Opens the node in a dialog")] - public bool ShowOpenButton { get; set; } - - [ConfigurationField("startNodeId", "Start node", "treepicker")] // + config in configuration editor ctor - public Udi? StartNodeId { get; set; } - - [ConfigurationField( - Constants.DataTypes.ReservedPreValueKeys.IgnoreUserStartNodes, - "Ignore User Start Nodes", - "boolean", - Description = "Selecting this option allows a user to choose nodes that they normally don't have access to.")] + [ConfigurationField(Constants.DataTypes.ReservedPreValueKeys.IgnoreUserStartNodes)] public bool IgnoreUserStartNodes { get; set; } } diff --git a/src/Umbraco.Core/PropertyEditors/ContentPickerConfigurationEditor.cs b/src/Umbraco.Core/PropertyEditors/ContentPickerConfigurationEditor.cs index 9d3e7eedf6..be8a755dfc 100644 --- a/src/Umbraco.Core/PropertyEditors/ContentPickerConfigurationEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/ContentPickerConfigurationEditor.cs @@ -2,32 +2,13 @@ // See LICENSE for more details. using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Services; namespace Umbraco.Cms.Core.PropertyEditors; internal class ContentPickerConfigurationEditor : ConfigurationEditor { - public ContentPickerConfigurationEditor(IIOHelper ioHelper, IEditorConfigurationParser editorConfigurationParser) - : base(ioHelper, editorConfigurationParser) => - - // configure fields - // this is not part of ContentPickerConfiguration, - // but is required to configure the UI editor (when editing the configuration) - Field(nameof(ContentPickerConfiguration.StartNodeId)) - .Config = new Dictionary { { "idType", "udi" } }; - - public override IDictionary ToValueEditor(IDictionary configuration) + public ContentPickerConfigurationEditor(IIOHelper ioHelper) + : base(ioHelper) { - // get the configuration fields - IDictionary config = base.ToValueEditor(configuration); - - // add extra fields - // not part of ContentPickerConfiguration but used to configure the UI editor - config["showEditButton"] = false; - config["showPathOnHover"] = false; - config["idType"] = "udi"; - - return config; } } diff --git a/src/Umbraco.Core/PropertyEditors/ContentPickerPropertyEditor.cs b/src/Umbraco.Core/PropertyEditors/ContentPickerPropertyEditor.cs index d6ec338495..61b38ad543 100644 --- a/src/Umbraco.Core/PropertyEditors/ContentPickerPropertyEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/ContentPickerPropertyEditor.cs @@ -1,13 +1,10 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models.Editors; using Umbraco.Cms.Core.Serialization; -using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Strings; namespace Umbraco.Cms.Core.PropertyEditors; @@ -17,39 +14,21 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// [DataEditor( Constants.PropertyEditors.Aliases.ContentPicker, - EditorType.PropertyValue | EditorType.MacroParameter, - "Content Picker", - "contentpicker", ValueType = ValueTypes.String, - Group = Constants.PropertyEditors.Groups.Pickers, ValueEditorIsReusable = true)] public class ContentPickerPropertyEditor : DataEditor { - private readonly IEditorConfigurationParser _editorConfigurationParser; private readonly IIOHelper _ioHelper; - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] - public ContentPickerPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IIOHelper ioHelper) - : this(dataValueEditorFactory, ioHelper, StaticServiceProvider.Instance.GetRequiredService()) - { - } - - public ContentPickerPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IIOHelper ioHelper, - IEditorConfigurationParser editorConfigurationParser) + public ContentPickerPropertyEditor(IDataValueEditorFactory dataValueEditorFactory, IIOHelper ioHelper) : base(dataValueEditorFactory) { _ioHelper = ioHelper; - _editorConfigurationParser = editorConfigurationParser; SupportsReadOnly = true; } protected override IConfigurationEditor CreateConfigurationEditor() => - new ContentPickerConfigurationEditor(_ioHelper, _editorConfigurationParser); + new ContentPickerConfigurationEditor(_ioHelper); protected override IDataValueEditor CreateValueEditor() => DataValueEditorFactory.Create(Attribute!); @@ -57,12 +36,11 @@ public class ContentPickerPropertyEditor : DataEditor internal class ContentPickerPropertyValueEditor : DataValueEditor, IDataValueReference { public ContentPickerPropertyValueEditor( - ILocalizedTextService localizedTextService, IShortStringHelper shortStringHelper, IJsonSerializer jsonSerializer, IIOHelper ioHelper, DataEditorAttribute attribute) - : base(localizedTextService, shortStringHelper, jsonSerializer, ioHelper, attribute) + : base(shortStringHelper, jsonSerializer, ioHelper, attribute) { } diff --git a/src/Umbraco.Core/PropertyEditors/DataEditor.cs b/src/Umbraco.Core/PropertyEditors/DataEditor.cs index c1d0495464..f04e24c51b 100644 --- a/src/Umbraco.Core/PropertyEditors/DataEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/DataEditor.cs @@ -27,28 +27,20 @@ public class DataEditor : IDataEditor /// /// Initializes a new instance of the class. /// - public DataEditor(IDataValueEditorFactory dataValueEditorFactory, EditorType type = EditorType.PropertyValue) + public DataEditor(IDataValueEditorFactory dataValueEditorFactory) { // defaults DataValueEditorFactory = dataValueEditorFactory; - Type = type; - Icon = Constants.Icons.PropertyEditor; - Group = Constants.PropertyEditors.Groups.Common; // assign properties based on the attribute, if it is found Attribute = GetType().GetCustomAttribute(false); if (Attribute == null) { Alias = string.Empty; - Name = string.Empty; return; } Alias = Attribute.Alias; - Type = Attribute.Type; - Name = Attribute.Name; - Icon = Attribute.Icon; - Group = Attribute.Group; IsDeprecated = Attribute.IsDeprecated; _canReuseValueEditor = Attribute.ValueEditorIsReusable; @@ -83,22 +75,6 @@ public class DataEditor : IDataEditor [DataMember(Name = "supportsReadOnly", IsRequired = true)] public bool SupportsReadOnly { get; set; } - /// - [IgnoreDataMember] - public EditorType Type { get; } - - /// - [DataMember(Name = "name", IsRequired = true)] - public string Name { get; internal set; } - - /// - [DataMember(Name = "icon")] - public string Icon { get; internal set; } - - /// - [DataMember(Name = "group")] - public string Group { get; internal set; } - /// [IgnoreDataMember] public bool IsDeprecated { get; } @@ -107,11 +83,7 @@ public class DataEditor : IDataEditor [DataMember(Name = "defaultConfig")] public IDictionary DefaultConfiguration { - // for property value editors, get the ConfigurationEditor.DefaultConfiguration - // else fallback to a default, empty dictionary - get => _defaultConfiguration ?? ((Type & EditorType.PropertyValue) > 0 - ? GetConfigurationEditor().DefaultConfiguration - : _defaultConfiguration = new Dictionary()); + get => _defaultConfiguration ?? GetConfigurationEditor().DefaultConfiguration; set => _defaultConfiguration = value; } @@ -208,7 +180,7 @@ public class DataEditor : IDataEditor var editor = new ConfigurationEditor(); // pass the default configuration if this is not a property value editor - if ((Type & EditorType.PropertyValue) == 0 && _defaultConfiguration is not null) + if (_defaultConfiguration is not null) { editor.DefaultConfiguration = _defaultConfiguration; } @@ -219,5 +191,5 @@ public class DataEditor : IDataEditor /// /// Provides a summary of the PropertyEditor for use with the . /// - protected virtual string DebuggerDisplay() => $"Name: {Name}, Alias: {Alias}"; + protected virtual string DebuggerDisplay() => $"Alias: {Alias}"; } diff --git a/src/Umbraco.Core/PropertyEditors/DataEditorAttribute.cs b/src/Umbraco.Core/PropertyEditors/DataEditorAttribute.cs index d9164d07ab..e4abced318 100644 --- a/src/Umbraco.Core/PropertyEditors/DataEditorAttribute.cs +++ b/src/Umbraco.Core/PropertyEditors/DataEditorAttribute.cs @@ -6,58 +6,13 @@ namespace Umbraco.Cms.Core.PropertyEditors; [AttributeUsage(AttributeTargets.Class)] public sealed class DataEditorAttribute : Attribute { - /// - /// Gets a special value indicating that the view should be null. - /// - public const string - NullView = "EXPLICITELY-SET-VIEW-TO-NULL-2B5B0B73D3DD47B28DDB84E02C349DFB"; // just a random string - private string _valueType = ValueTypes.String; /// /// Initializes a new instance of the class for a property editor. /// /// The unique identifier of the editor. - /// The friendly name of the editor. - public DataEditorAttribute(string alias, string name) - : this(alias, EditorType.PropertyValue, name, NullView) - { - } - - /// - /// Initializes a new instance of the class for a property editor. - /// - /// The unique identifier of the editor. - /// The friendly name of the editor. - /// The view to use to render the editor. - public DataEditorAttribute(string alias, string name, string view) - : this(alias, EditorType.PropertyValue, name, view) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The unique identifier of the editor. - /// The type of the editor. - /// The friendly name of the editor. - public DataEditorAttribute(string alias, EditorType type, string name) - : this(alias, type, name, NullView) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The unique identifier of the editor. - /// The type of the editor. - /// The friendly name of the editor. - /// The view to use to render the editor. - /// - /// Set to to explicitly set the view to null. - /// Otherwise, cannot be null nor empty. - /// - public DataEditorAttribute(string alias, EditorType type, string name, string view) + public DataEditorAttribute(string alias) { if (alias == null) { @@ -71,39 +26,7 @@ public sealed class DataEditorAttribute : Attribute nameof(alias)); } - if ((type & ~(EditorType.PropertyValue | EditorType.MacroParameter)) > 0) - { - throw new ArgumentOutOfRangeException(nameof(type), type, $"Not a valid {typeof(EditorType)} value."); - } - - if (name == null) - { - throw new ArgumentNullException(nameof(name)); - } - - if (string.IsNullOrWhiteSpace(name)) - { - throw new ArgumentException( - "Value can't be empty or consist only of white-space characters.", - nameof(name)); - } - - if (view == null) - { - throw new ArgumentNullException(nameof(view)); - } - - if (string.IsNullOrWhiteSpace(view)) - { - throw new ArgumentException( - "Value can't be empty or consist only of white-space characters.", - nameof(view)); - } - - Type = type; Alias = alias; - Name = name; - View = view == NullView ? null : view; } /// @@ -111,21 +34,6 @@ public sealed class DataEditorAttribute : Attribute /// public string Alias { get; } - /// - /// Gets the type of the editor. - /// - public EditorType Type { get; } - - /// - /// Gets the friendly name of the editor. - /// - public string Name { get; } - - /// - /// Gets the view to use to render the editor. - /// - public string? View { get; } - /// /// Gets or sets the type of the edited value. /// @@ -156,23 +64,6 @@ public sealed class DataEditorAttribute : Attribute } } - /// - /// Gets or sets a value indicating whether the editor should be displayed without its label. - /// - public bool HideLabel { get; set; } - - /// - /// Gets or sets an optional icon. - /// - /// The icon can be used for example when presenting datatypes based upon the editor. - public string Icon { get; set; } = Constants.Icons.PropertyEditor; - - /// - /// Gets or sets an optional group. - /// - /// The group can be used for example to group the editors by category. - public string Group { get; set; } = Constants.PropertyEditors.Groups.Common; - /// /// Gets or sets a value indicating whether the value editor is deprecated. /// diff --git a/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs b/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs index d2c29a938a..a32af502ab 100644 --- a/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs @@ -71,20 +71,7 @@ public class DataValueEditor : IDataValueEditor _shortStringHelper = shortStringHelper; _jsonSerializer = jsonSerializer; - var view = attribute.View; - if (string.IsNullOrWhiteSpace(view)) - { - throw new ArgumentException("The attribute does not specify a view.", nameof(attribute)); - } - - if (view.StartsWith("~/")) - { - view = ioHelper.ResolveRelativeOrVirtualUrl(view); - } - - View = view; ValueType = attribute.ValueType; - HideLabel = attribute.HideLabel; } /// @@ -105,19 +92,6 @@ public class DataValueEditor : IDataValueEditor /// public virtual IValueFormatValidator FormatValidator => new RegexValidator(); - /// - /// Gets or sets the editor view. - /// - /// - /// - /// The view can be three things: (1) the full virtual path, or (2) the relative path to the current Umbraco - /// folder, or (3) a view name which maps to views/propertyeditors/{view}/{view}.html. - /// - /// - [Required] - [DataMember(Name = "view")] - public string? View { get; set; } - /// /// The value type which reflects how it is validated and stored in the database /// @@ -178,13 +152,6 @@ public class DataValueEditor : IDataValueEditor return results ?? Enumerable.Empty(); } - - /// - /// If this is true than the editor will be displayed full width without a label - /// - [DataMember(Name = "hideLabel")] - public bool HideLabel { get; set; } - /// /// Set this to true if the property editor is for display purposes only /// diff --git a/src/Umbraco.Core/PropertyEditors/DateTimeConfiguration.cs b/src/Umbraco.Core/PropertyEditors/DateTimeConfiguration.cs deleted file mode 100644 index 27c1445160..0000000000 --- a/src/Umbraco.Core/PropertyEditors/DateTimeConfiguration.cs +++ /dev/null @@ -1,22 +0,0 @@ -namespace Umbraco.Cms.Core.PropertyEditors; - -/// -/// Represents the configuration for the datetime value editor. -/// -public class DateTimeConfiguration -{ - public DateTimeConfiguration() => - - // different default values - Format = "YYYY-MM-DD HH:mm:ss"; - - [ConfigurationField("format", "Date format", "textstring", Description = "If left empty then the format is YYYY-MM-DD. (see momentjs.com for supported formats)")] - public string Format { get; set; } - - [ConfigurationField( - "offsetTime", - "Offset time", - "boolean", - Description = "When enabled the time displayed will be offset with the server's timezone, this is useful for scenarios like scheduled publishing when an editor is in a different timezone than the hosted server")] - public bool OffsetTime { get; set; } -} diff --git a/src/Umbraco.Core/PropertyEditors/DateTimeConfigurationEditor.cs b/src/Umbraco.Core/PropertyEditors/DateTimeConfigurationEditor.cs deleted file mode 100644 index 6370cf5677..0000000000 --- a/src/Umbraco.Core/PropertyEditors/DateTimeConfigurationEditor.cs +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; -using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Services; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.PropertyEditors; - -/// -/// Represents the configuration editor for the datetime value editor. -/// -public class DateTimeConfigurationEditor : ConfigurationEditor -{ - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] - public DateTimeConfigurationEditor(IIOHelper ioHelper) - : this( - ioHelper, - StaticServiceProvider.Instance.GetRequiredService()) - { - } - - public DateTimeConfigurationEditor(IIOHelper ioHelper, IEditorConfigurationParser editorConfigurationParser) - : base( - ioHelper, editorConfigurationParser) - { - } - - public override IDictionary ToValueEditor(IDictionary configuration) - { - IDictionary config = base.ToValueEditor(configuration); - - // FIXME: all this belongs clientside, this needs to go - var pickTime = true; - if (config.TryGetValue("format", out object? formatValue) && formatValue is string format) - { - pickTime = format.ContainsAny(new[] { "H", "m", "s" }); - } - - config["pickTime"] = pickTime; - - return config; - } -} diff --git a/src/Umbraco.Core/PropertyEditors/DecimalConfigurationEditor.cs b/src/Umbraco.Core/PropertyEditors/DecimalConfigurationEditor.cs index 1b4a094ca2..ada98feea4 100644 --- a/src/Umbraco.Core/PropertyEditors/DecimalConfigurationEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/DecimalConfigurationEditor.cs @@ -11,26 +11,17 @@ public class DecimalConfigurationEditor : ConfigurationEditor { Fields.Add(new ConfigurationField(new DecimalValidator()) { - Description = "Enter the minimum amount of number to be entered", - Key = "min", - View = "decimal", - Name = "Minimum", + Key = "min" }); Fields.Add(new ConfigurationField(new DecimalValidator()) { - Description = "Enter the intervals amount between each step of number to be entered", Key = "step", - View = "decimal", - Name = "Step Size", }); Fields.Add(new ConfigurationField(new DecimalValidator()) { - Description = "Enter the maximum amount of number to be entered", Key = "max", - View = "decimal", - Name = "Maximum", }); } } diff --git a/src/Umbraco.Core/PropertyEditors/DecimalPropertyEditor.cs b/src/Umbraco.Core/PropertyEditors/DecimalPropertyEditor.cs index 675978e875..1ecae6b0bd 100644 --- a/src/Umbraco.Core/PropertyEditors/DecimalPropertyEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/DecimalPropertyEditor.cs @@ -4,7 +4,6 @@ using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models.Editors; using Umbraco.Cms.Core.PropertyEditors.Validators; using Umbraco.Cms.Core.Serialization; -using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Strings; namespace Umbraco.Cms.Core.PropertyEditors; @@ -14,9 +13,6 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// [DataEditor( Constants.PropertyEditors.Aliases.Decimal, - EditorType.PropertyValue | EditorType.MacroParameter, - "Decimal", - "decimal", ValueType = ValueTypes.Decimal, ValueEditorIsReusable = true)] public class DecimalPropertyEditor : DataEditor @@ -39,12 +35,11 @@ public class DecimalPropertyEditor : DataEditor internal class DecimalPropertyValueEditor : DataValueEditor { public DecimalPropertyValueEditor( - ILocalizedTextService localizedTextService, IShortStringHelper shortStringHelper, IJsonSerializer jsonSerializer, IIOHelper ioHelper, DataEditorAttribute attribute) - : base(localizedTextService, shortStringHelper, jsonSerializer, ioHelper, attribute) => + : base(shortStringHelper, jsonSerializer, ioHelper, attribute) => Validators.Add(new DecimalValidator()); public override object? ToEditor(IProperty property, string? culture = null, string? segment = null) diff --git a/src/Umbraco.Core/PropertyEditors/DropDownFlexibleConfiguration.cs b/src/Umbraco.Core/PropertyEditors/DropDownFlexibleConfiguration.cs index c0132d574d..fb0db0d9d9 100644 --- a/src/Umbraco.Core/PropertyEditors/DropDownFlexibleConfiguration.cs +++ b/src/Umbraco.Core/PropertyEditors/DropDownFlexibleConfiguration.cs @@ -2,10 +2,6 @@ namespace Umbraco.Cms.Core.PropertyEditors; public class DropDownFlexibleConfiguration : ValueListConfiguration { - [ConfigurationField( - "multiple", - "Enable multiple choice", - "boolean", - Description = "When checked, the dropdown will be a select multiple / combo box style dropdown.")] + [ConfigurationField("multiple")] public bool Multiple { get; set; } } diff --git a/src/Umbraco.Core/PropertyEditors/EditorType.cs b/src/Umbraco.Core/PropertyEditors/EditorType.cs deleted file mode 100644 index 15469e1e51..0000000000 --- a/src/Umbraco.Core/PropertyEditors/EditorType.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace Umbraco.Cms.Core.PropertyEditors; - -/// -/// Represents the type of an editor. -/// -[Flags] -public enum EditorType -{ - /// - /// Nothing. - /// - Nothing = 0, - - /// - /// Property value editor. - /// - PropertyValue = 1, - - /// - /// Macro parameter editor. - /// - MacroParameter = 2, -} diff --git a/src/Umbraco.Core/PropertyEditors/EmailAddressConfiguration.cs b/src/Umbraco.Core/PropertyEditors/EmailAddressConfiguration.cs deleted file mode 100644 index cf3452c114..0000000000 --- a/src/Umbraco.Core/PropertyEditors/EmailAddressConfiguration.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Umbraco.Cms.Core.PropertyEditors; - -/// -/// Represents the configuration for the email address value editor. -/// -public class EmailAddressConfiguration -{ - [ConfigurationField("IsRequired", "Required?", "hidden", Description = "Deprecated; Make this required by selecting mandatory when adding to the document type")] - [Obsolete("No longer used, use `Mandatory` for the property instead. Will be removed in the next major version")] - public bool IsRequired { get; set; } -} diff --git a/src/Umbraco.Core/PropertyEditors/EmailAddressConfigurationEditor.cs b/src/Umbraco.Core/PropertyEditors/EmailAddressConfigurationEditor.cs deleted file mode 100644 index 2ecc8deedc..0000000000 --- a/src/Umbraco.Core/PropertyEditors/EmailAddressConfigurationEditor.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; -using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Services; - -namespace Umbraco.Cms.Core.PropertyEditors; - -/// -/// Represents the configuration editor for the email address value editor. -/// -public class EmailAddressConfigurationEditor : ConfigurationEditor -{ - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] - public EmailAddressConfigurationEditor(IIOHelper ioHelper) - : this(ioHelper, StaticServiceProvider.Instance.GetRequiredService()) - { - } - - public EmailAddressConfigurationEditor(IIOHelper ioHelper, IEditorConfigurationParser editorConfigurationParser) - : base(ioHelper, editorConfigurationParser) - { - } -} diff --git a/src/Umbraco.Core/PropertyEditors/EyeDropperColorPickerConfiguration.cs b/src/Umbraco.Core/PropertyEditors/EyeDropperColorPickerConfiguration.cs deleted file mode 100644 index e9c8255a19..0000000000 --- a/src/Umbraco.Core/PropertyEditors/EyeDropperColorPickerConfiguration.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace Umbraco.Cms.Core.PropertyEditors; - -/// -/// Represents the configuration for the Eye Dropper picker value editor. -/// -public class EyeDropperColorPickerConfiguration -{ - [ConfigurationField("showAlpha", "Show alpha", "boolean", Description = "Allow alpha transparency selection.")] - public bool ShowAlpha { get; set; } - - [ConfigurationField("showPalette", "Show palette", "boolean", Description = "Show a palette next to the color picker.")] - public bool ShowPalette { get; set; } -} diff --git a/src/Umbraco.Core/PropertyEditors/EyeDropperColorPickerConfigurationEditor.cs b/src/Umbraco.Core/PropertyEditors/EyeDropperColorPickerConfigurationEditor.cs deleted file mode 100644 index 4a15e1ef3b..0000000000 --- a/src/Umbraco.Core/PropertyEditors/EyeDropperColorPickerConfigurationEditor.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Services; - -namespace Umbraco.Cms.Core.PropertyEditors; - -internal class EyeDropperColorPickerConfigurationEditor : ConfigurationEditor -{ - public EyeDropperColorPickerConfigurationEditor( - IIOHelper ioHelper, - IEditorConfigurationParser editorConfigurationParser) - : base(ioHelper, editorConfigurationParser) - { - } -} diff --git a/src/Umbraco.Core/PropertyEditors/EyeDropperColorPickerPropertyEditor.cs b/src/Umbraco.Core/PropertyEditors/EyeDropperColorPickerPropertyEditor.cs index e4e41561cc..f37bb48be6 100644 --- a/src/Umbraco.Core/PropertyEditors/EyeDropperColorPickerPropertyEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/EyeDropperColorPickerPropertyEditor.cs @@ -1,46 +1,11 @@ -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; -using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Services; - namespace Umbraco.Cms.Core.PropertyEditors; [DataEditor( Constants.PropertyEditors.Aliases.ColorPickerEyeDropper, - EditorType.PropertyValue | EditorType.MacroParameter, - "Eye Dropper Color Picker", - "eyedropper", - Icon = "icon-colorpicker", - Group = Constants.PropertyEditors.Groups.Pickers, ValueEditorIsReusable = true)] public class EyeDropperColorPickerPropertyEditor : DataEditor { - private readonly IEditorConfigurationParser _editorConfigurationParser; - private readonly IIOHelper _ioHelper; - - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] - public EyeDropperColorPickerPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IIOHelper ioHelper, - EditorType type = EditorType.PropertyValue) - : this(dataValueEditorFactory, ioHelper, StaticServiceProvider.Instance.GetRequiredService(), type) - { - } - - public EyeDropperColorPickerPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IIOHelper ioHelper, - IEditorConfigurationParser editorConfigurationParser, - EditorType type = EditorType.PropertyValue) - : base(dataValueEditorFactory, type) - { - _ioHelper = ioHelper; - _editorConfigurationParser = editorConfigurationParser; - SupportsReadOnly = true; - } - - /// - protected override IConfigurationEditor CreateConfigurationEditor() => - new EyeDropperColorPickerConfigurationEditor(_ioHelper, _editorConfigurationParser); + public EyeDropperColorPickerPropertyEditor(IDataValueEditorFactory dataValueEditorFactory) + : base(dataValueEditorFactory) + => SupportsReadOnly = true; } diff --git a/src/Umbraco.Core/PropertyEditors/FileExtensionConfigItem.cs b/src/Umbraco.Core/PropertyEditors/FileExtensionConfigItem.cs index 4444466c03..a96f3cfe9d 100644 --- a/src/Umbraco.Core/PropertyEditors/FileExtensionConfigItem.cs +++ b/src/Umbraco.Core/PropertyEditors/FileExtensionConfigItem.cs @@ -1,13 +1,8 @@ -using System.Runtime.Serialization; - namespace Umbraco.Cms.Core.PropertyEditors; -[DataContract] public class FileExtensionConfigItem : IFileExtensionConfigItem { - [DataMember(Name = "id")] public int Id { get; set; } - [DataMember(Name = "value")] public string? Value { get; set; } } diff --git a/src/Umbraco.Core/PropertyEditors/FileUploadConfiguration.cs b/src/Umbraco.Core/PropertyEditors/FileUploadConfiguration.cs index 289f649b00..b1531c6548 100644 --- a/src/Umbraco.Core/PropertyEditors/FileUploadConfiguration.cs +++ b/src/Umbraco.Core/PropertyEditors/FileUploadConfiguration.cs @@ -5,6 +5,6 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// public class FileUploadConfiguration : IFileExtensionsConfig { - [ConfigurationField("fileExtensions", "Accepted file extensions", "multivalues")] + [ConfigurationField("fileExtensions")] public List FileExtensions { get; set; } = new(); } diff --git a/src/Umbraco.Core/PropertyEditors/FileUploadConfigurationEditor.cs b/src/Umbraco.Core/PropertyEditors/FileUploadConfigurationEditor.cs index f0cb1ccf3b..31fa723b3f 100644 --- a/src/Umbraco.Core/PropertyEditors/FileUploadConfigurationEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/FileUploadConfigurationEditor.cs @@ -1,7 +1,4 @@ -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Services; namespace Umbraco.Cms.Core.PropertyEditors; @@ -10,15 +7,8 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// public class FileUploadConfigurationEditor : ConfigurationEditor { - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] public FileUploadConfigurationEditor(IIOHelper ioHelper) - : this(ioHelper, StaticServiceProvider.Instance.GetRequiredService()) - { - } - - public FileUploadConfigurationEditor(IIOHelper ioHelper, IEditorConfigurationParser editorConfigurationParser) - : base(ioHelper, editorConfigurationParser) + : base(ioHelper) { } } diff --git a/src/Umbraco.Core/PropertyEditors/GridEditor.cs b/src/Umbraco.Core/PropertyEditors/GridEditor.cs deleted file mode 100644 index 2ce26bdb79..0000000000 --- a/src/Umbraco.Core/PropertyEditors/GridEditor.cs +++ /dev/null @@ -1,74 +0,0 @@ -using System.Runtime.Serialization; -using Umbraco.Cms.Core.Configuration.Grid; - -namespace Umbraco.Cms.Core.PropertyEditors; - -[DataContract] -[Obsolete("The grid is obsolete, will be removed in V13")] -public class GridEditor : IGridEditorConfig -{ - public GridEditor() - { - Config = new Dictionary(); - Alias = string.Empty; - } - - [DataMember(Name = "name", IsRequired = true)] - public string? Name { get; set; } - - [DataMember(Name = "nameTemplate")] - public string? NameTemplate { get; set; } - - [DataMember(Name = "alias", IsRequired = true)] - public string Alias { get; set; } - - [DataMember(Name = "view", IsRequired = true)] - public string? View { get; set; } - - [DataMember(Name = "render")] - public string? Render { get; set; } - - [DataMember(Name = "icon", IsRequired = true)] - public string? Icon { get; set; } - - [DataMember(Name = "config")] - public IDictionary Config { get; set; } - - /// - /// Determines whether the specified is equal to the current - /// . - /// - /// - /// true if the specified object is equal to the current object; otherwise, false. - /// - /// The object to compare with the current object. - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - - if (obj.GetType() != GetType()) - { - return false; - } - - return Equals((GridEditor)obj); - } - - protected bool Equals(GridEditor other) => string.Equals(Alias, other.Alias); - - /// - /// Serves as a hash function for a particular type. - /// - /// - /// A hash code for the current . - /// - public override int GetHashCode() => Alias.GetHashCode(); -} diff --git a/src/Umbraco.Core/PropertyEditors/IDataEditor.cs b/src/Umbraco.Core/PropertyEditors/IDataEditor.cs index b8d9af2f1a..6db8049d23 100644 --- a/src/Umbraco.Core/PropertyEditors/IDataEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/IDataEditor.cs @@ -16,31 +16,6 @@ public interface IDataEditor : IDiscoverable bool SupportsReadOnly => false; - /// - /// Gets the type of the editor. - /// - /// An editor can be a property value editor, or a parameter editor. - EditorType Type { get; } - - /// - /// Gets the name of the editor. - /// - string Name { get; } - - /// - /// Gets the icon of the editor. - /// - /// Can be used to display editors when presenting them. - // FIXME: remove this when we are rid of the old backoffice - the server should not know about data editor icons - string Icon { get; } - - /// - /// Gets the group of the editor. - /// - /// Can be used to organize editors when presenting them. - // FIXME: remove this when we are rid of the old backoffice - the server should not know about data editor groups - string Group { get; } - /// /// Gets a value indicating whether the editor is deprecated. /// diff --git a/src/Umbraco.Core/PropertyEditors/INestedContentPropertyIndexValueFactory.cs b/src/Umbraco.Core/PropertyEditors/INestedContentPropertyIndexValueFactory.cs deleted file mode 100644 index eb87a390d2..0000000000 --- a/src/Umbraco.Core/PropertyEditors/INestedContentPropertyIndexValueFactory.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace Umbraco.Cms.Core.PropertyEditors; - -public interface INestedContentPropertyIndexValueFactory : IPropertyIndexValueFactory -{ -} diff --git a/src/Umbraco.Core/PropertyEditors/IntegerConfigurationEditor.cs b/src/Umbraco.Core/PropertyEditors/IntegerConfigurationEditor.cs index e5d01900c6..eda8ae17fe 100644 --- a/src/Umbraco.Core/PropertyEditors/IntegerConfigurationEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/IntegerConfigurationEditor.cs @@ -11,26 +11,17 @@ public class IntegerConfigurationEditor : ConfigurationEditor { Fields.Add(new ConfigurationField(new IntegerValidator()) { - Description = "Enter the minimum amount of number to be entered", Key = "min", - View = "number", - Name = "Minimum", }); Fields.Add(new ConfigurationField(new IntegerValidator()) { - Description = "Enter the intervals amount between each step of number to be entered", Key = "step", - View = "number", - Name = "Step Size", }); Fields.Add(new ConfigurationField(new IntegerValidator()) { - Description = "Enter the maximum amount of number to be entered", Key = "max", - View = "number", - Name = "Maximum", }); } } diff --git a/src/Umbraco.Core/PropertyEditors/IntegerPropertyEditor.cs b/src/Umbraco.Core/PropertyEditors/IntegerPropertyEditor.cs index 66dda875a9..216a82f348 100644 --- a/src/Umbraco.Core/PropertyEditors/IntegerPropertyEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/IntegerPropertyEditor.cs @@ -4,7 +4,6 @@ using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models.Editors; using Umbraco.Cms.Core.PropertyEditors.Validators; using Umbraco.Cms.Core.Serialization; -using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Strings; namespace Umbraco.Cms.Core.PropertyEditors; @@ -14,17 +13,13 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// [DataEditor( Constants.PropertyEditors.Aliases.Integer, - EditorType.PropertyValue | EditorType.MacroParameter, - "Numeric", - "integer", ValueType = ValueTypes.Integer, ValueEditorIsReusable = true)] public class IntegerPropertyEditor : DataEditor { - public IntegerPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory) - : base(dataValueEditorFactory) => - SupportsReadOnly = true; + public IntegerPropertyEditor(IDataValueEditorFactory dataValueEditorFactory) + : base(dataValueEditorFactory) + => SupportsReadOnly = true; /// protected override IDataValueEditor CreateValueEditor() @@ -36,13 +31,12 @@ public class IntegerPropertyEditor : DataEditor internal class IntegerPropertyValueEditor : DataValueEditor { public IntegerPropertyValueEditor( - ILocalizedTextService localizedTextService, IShortStringHelper shortStringHelper, IJsonSerializer jsonSerializer, IIOHelper ioHelper, DataEditorAttribute attribute) - : base(localizedTextService, shortStringHelper, jsonSerializer, ioHelper, attribute) => - Validators.Add(new IntegerValidator()); + : base(shortStringHelper, jsonSerializer, ioHelper, attribute) + => Validators.Add(new IntegerValidator()); public override object? ToEditor(IProperty property, string? culture = null, string? segment = null) => TryParsePropertyValue(property.GetValue(culture, segment)); diff --git a/src/Umbraco.Core/PropertyEditors/LabelConfiguration.cs b/src/Umbraco.Core/PropertyEditors/LabelConfiguration.cs index f023b86a78..aac67111f3 100644 --- a/src/Umbraco.Core/PropertyEditors/LabelConfiguration.cs +++ b/src/Umbraco.Core/PropertyEditors/LabelConfiguration.cs @@ -5,6 +5,6 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// public class LabelConfiguration : IConfigureValueType { - [ConfigurationField(Constants.PropertyEditors.ConfigurationKeys.DataValueType, "Value type", "valuetype")] + [ConfigurationField(Constants.PropertyEditors.ConfigurationKeys.DataValueType)] public string ValueType { get; set; } = ValueTypes.String; } diff --git a/src/Umbraco.Core/PropertyEditors/LabelConfigurationEditor.cs b/src/Umbraco.Core/PropertyEditors/LabelConfigurationEditor.cs index b5a046b86e..3eda5e89b8 100644 --- a/src/Umbraco.Core/PropertyEditors/LabelConfigurationEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/LabelConfigurationEditor.cs @@ -1,10 +1,7 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Services; namespace Umbraco.Cms.Core.PropertyEditors; @@ -13,15 +10,8 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// public class LabelConfigurationEditor : ConfigurationEditor { - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes and IEditorConfigurationParser instead")] public LabelConfigurationEditor(IIOHelper ioHelper) - : this(ioHelper, StaticServiceProvider.Instance.GetRequiredService()) - { - } - - public LabelConfigurationEditor(IIOHelper ioHelper, IEditorConfigurationParser editorConfigurationParser) - : base(ioHelper, editorConfigurationParser) + : base(ioHelper) { } diff --git a/src/Umbraco.Core/PropertyEditors/LabelPropertyEditor.cs b/src/Umbraco.Core/PropertyEditors/LabelPropertyEditor.cs index 9ccd0d99af..646f20efe6 100644 --- a/src/Umbraco.Core/PropertyEditors/LabelPropertyEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/LabelPropertyEditor.cs @@ -1,12 +1,9 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Serialization; -using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Strings; namespace Umbraco.Cms.Core.PropertyEditors; @@ -16,35 +13,18 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// [DataEditor( Constants.PropertyEditors.Aliases.Label, - "Label", - "readonlyvalue", - Icon = "icon-readonly", ValueEditorIsReusable = true)] public class LabelPropertyEditor : DataEditor { - private readonly IEditorConfigurationParser _editorConfigurationParser; private readonly IIOHelper _ioHelper; - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] - public LabelPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IIOHelper ioHelper) - : this(dataValueEditorFactory, ioHelper, StaticServiceProvider.Instance.GetRequiredService()) - { - } - /// /// Initializes a new instance of the class. /// - public LabelPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IIOHelper ioHelper, - IEditorConfigurationParser editorConfigurationParser) + public LabelPropertyEditor(IDataValueEditorFactory dataValueEditorFactory, IIOHelper ioHelper) : base(dataValueEditorFactory) { _ioHelper = ioHelper; - _editorConfigurationParser = editorConfigurationParser; SupportsReadOnly = true; } @@ -54,18 +34,17 @@ public class LabelPropertyEditor : DataEditor /// protected override IConfigurationEditor CreateConfigurationEditor() => - new LabelConfigurationEditor(_ioHelper, _editorConfigurationParser); + new LabelConfigurationEditor(_ioHelper); // provides the property value editor internal class LabelPropertyValueEditor : DataValueEditor { public LabelPropertyValueEditor( - ILocalizedTextService localizedTextService, IShortStringHelper shortStringHelper, IJsonSerializer jsonSerializer, IIOHelper ioHelper, DataEditorAttribute attribute) - : base(localizedTextService, shortStringHelper, jsonSerializer, ioHelper, attribute) + : base(shortStringHelper, jsonSerializer, ioHelper, attribute) { } diff --git a/src/Umbraco.Core/PropertyEditors/ListViewConfiguration.cs b/src/Umbraco.Core/PropertyEditors/ListViewConfiguration.cs index 6b44d4ba56..feecea4156 100644 --- a/src/Umbraco.Core/PropertyEditors/ListViewConfiguration.cs +++ b/src/Umbraco.Core/PropertyEditors/ListViewConfiguration.cs @@ -1,5 +1,3 @@ -using System.Runtime.Serialization; - namespace Umbraco.Cms.Core.PropertyEditors; /// @@ -7,147 +5,22 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// public class ListViewConfiguration { - public ListViewConfiguration() - { + public ListViewConfiguration() => // initialize defaults - PageSize = 10; - OrderBy = "SortOrder"; - OrderDirection = "asc"; - - BulkActionPermissions = new BulkActionPermissionSettings - { - AllowBulkPublish = true, - AllowBulkUnpublish = true, - AllowBulkCopy = true, - AllowBulkMove = true, - AllowBulkDelete = true, - }; - - Layouts = new[] - { - new Layout - { - Name = "List", - Icon = "icon-list", - IsSystem = 1, - Selected = true, - Path = "views/propertyeditors/listview/layouts/list/list.html", - }, - new Layout - { - Name = "Grid", - Icon = "icon-thumbnails-small", - IsSystem = 1, - Selected = true, - Path = "views/propertyeditors/listview/layouts/grid/grid.html", - }, - }; - IncludeProperties = new[] { - new Property { Alias = "sortOrder", Header = "Sort order", IsSystem = 1 }, - new Property { Alias = "updateDate", Header = "Last edited", IsSystem = 1 }, - new Property { Alias = "owner", Header = "Created by", IsSystem = 1 }, + new Property { Alias = "sortOrder", IsSystem = true }, + new Property { Alias = "updateDate", IsSystem = true }, + new Property { Alias = "owner", IsSystem = true }, }; - } - [ConfigurationField("pageSize", "Page Size", "number", Description = "Number of items per page")] - public int PageSize { get; set; } - - [ConfigurationField("orderDirection", "Order Direction", "views/propertyeditors/listview/orderDirection.prevalues.html")] - public string OrderDirection { get; set; } - - [ConfigurationField( - "includeProperties", - "Columns Displayed", - "views/propertyeditors/listview/includeproperties.prevalues.html", - Description = "The properties that will be displayed for each column")] + [ConfigurationField("includeProperties")] public Property[] IncludeProperties { get; set; } - [ConfigurationField("orderBy", "Order By", "views/propertyeditors/listview/sortby.prevalues.html", Description = "The default sort order for the list")] - public string OrderBy { get; set; } - - [ConfigurationField("layouts", "Layouts", "views/propertyeditors/listview/layouts.prevalues.html")] - public Layout[] Layouts { get; set; } - - [ConfigurationField( - "bulkActionPermissions", - "Bulk Action Permissions", - "views/propertyeditors/listview/bulkActionPermissions.prevalues.html", - Description = "The bulk actions that are allowed from the list view")] - public BulkActionPermissionSettings BulkActionPermissions { get; set; } = new(); // TODO: managing defaults? - - [ConfigurationField("icon", "Content app icon", "views/propertyeditors/listview/icon.prevalues.html", Description = "The icon of the listview content app")] - public string? Icon { get; set; } - - [ConfigurationField("tabName", "Content app name", "textstring", Description = "The name of the listview content app (default if empty: 'Child Items')")] - public string? TabName { get; set; } - - [ConfigurationField( - "showContentFirst", - "Show Content App First", - "boolean", - Description = "Enable this to show the content app by default instead of the list view app")] - public bool ShowContentFirst { get; set; } - - [ConfigurationField( - "useInfiniteEditor", - "Edit in Infinite Editor", - "boolean", - Description = "Enable this to use infinite editing to edit the content of the list view")] - public bool UseInfiniteEditor { get; set; } - - [DataContract] public class Property { - [DataMember(Name = "alias")] public string? Alias { get; set; } - [DataMember(Name = "header")] - public string? Header { get; set; } - - [DataMember(Name = "nameTemplate")] - public string? Template { get; set; } - - [DataMember(Name = "isSystem")] - public int IsSystem { get; set; } // TODO: bool - } - - [DataContract] - public class Layout - { - [DataMember(Name = "name")] - public string? Name { get; set; } - - [DataMember(Name = "path")] - public string? Path { get; set; } - - [DataMember(Name = "icon")] - public string? Icon { get; set; } - - [DataMember(Name = "isSystem")] - public int IsSystem { get; set; } // TODO: bool - - [DataMember(Name = "selected")] - public bool Selected { get; set; } - } - - [DataContract] - public class BulkActionPermissionSettings - { - [DataMember(Name = "allowBulkPublish")] - public bool AllowBulkPublish { get; set; } = true; - - [DataMember(Name = "allowBulkUnpublish")] - public bool AllowBulkUnpublish { get; set; } = true; - - [DataMember(Name = "allowBulkCopy")] - public bool AllowBulkCopy { get; set; } = true; - - [DataMember(Name = "allowBulkMove")] - public bool AllowBulkMove { get; set; } = true; - - [DataMember(Name = "allowBulkDelete")] - public bool AllowBulkDelete { get; set; } = true; + public bool IsSystem { get; set; } } } diff --git a/src/Umbraco.Core/PropertyEditors/ListViewConfigurationEditor.cs b/src/Umbraco.Core/PropertyEditors/ListViewConfigurationEditor.cs index 4eab700e87..b739d3adf3 100644 --- a/src/Umbraco.Core/PropertyEditors/ListViewConfigurationEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/ListViewConfigurationEditor.cs @@ -1,10 +1,7 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Services; namespace Umbraco.Cms.Core.PropertyEditors; @@ -13,15 +10,8 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// public class ListViewConfigurationEditor : ConfigurationEditor { - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] public ListViewConfigurationEditor(IIOHelper ioHelper) - : this(ioHelper, StaticServiceProvider.Instance.GetRequiredService()) - { - } - - public ListViewConfigurationEditor(IIOHelper ioHelper, IEditorConfigurationParser editorConfigurationParser) - : base(ioHelper, editorConfigurationParser) + : base(ioHelper) { } } diff --git a/src/Umbraco.Core/PropertyEditors/MarkdownConfiguration.cs b/src/Umbraco.Core/PropertyEditors/MarkdownConfiguration.cs deleted file mode 100644 index b11ef08f30..0000000000 --- a/src/Umbraco.Core/PropertyEditors/MarkdownConfiguration.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace Umbraco.Cms.Core.PropertyEditors; - -/// -/// Represents the configuration for the markdown value editor. -/// -public class MarkdownConfiguration -{ - [ConfigurationField("preview", "Preview", "boolean", Description = "Display a live preview")] - public bool DisplayLivePreview { get; set; } - - [ConfigurationField("defaultValue", "Default value", "textarea", Description = "If value is blank, the editor will show this")] - public string? DefaultValue { get; set; } - - [ConfigurationField("overlaySize", "Overlay Size", "overlaysize", Description = "Select the width of the overlay (link picker).")] - public string? OverlaySize { get; set; } -} diff --git a/src/Umbraco.Core/PropertyEditors/MarkdownConfigurationEditor.cs b/src/Umbraco.Core/PropertyEditors/MarkdownConfigurationEditor.cs deleted file mode 100644 index 032bafd12b..0000000000 --- a/src/Umbraco.Core/PropertyEditors/MarkdownConfigurationEditor.cs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Services; - -namespace Umbraco.Cms.Core.PropertyEditors; - -/// -/// Represents the configuration editorfor the markdown value editor. -/// -internal class MarkdownConfigurationEditor : ConfigurationEditor -{ - public MarkdownConfigurationEditor(IIOHelper ioHelper, IEditorConfigurationParser editorConfigurationParser) - : base(ioHelper, editorConfigurationParser) - { - } -} diff --git a/src/Umbraco.Core/PropertyEditors/MarkdownPropertyEditor.cs b/src/Umbraco.Core/PropertyEditors/MarkdownPropertyEditor.cs index 531262f0b2..39693f3c34 100644 --- a/src/Umbraco.Core/PropertyEditors/MarkdownPropertyEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/MarkdownPropertyEditor.cs @@ -1,11 +1,7 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; -using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.Models; -using Umbraco.Cms.Core.Services; namespace Umbraco.Cms.Core.PropertyEditors; @@ -14,43 +10,16 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// [DataEditor( Constants.PropertyEditors.Aliases.MarkdownEditor, - "Markdown editor", - "markdowneditor", ValueType = ValueTypes.Text, - Group = Constants.PropertyEditors.Groups.RichContent, - Icon = "icon-code", ValueEditorIsReusable = true)] public class MarkdownPropertyEditor : DataEditor { - private readonly IEditorConfigurationParser _editorConfigurationParser; - private readonly IIOHelper _ioHelper; - - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] - public MarkdownPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IIOHelper ioHelper) - : this(dataValueEditorFactory, ioHelper, StaticServiceProvider.Instance.GetRequiredService()) - { - } - /// /// Initializes a new instance of the class. /// - public MarkdownPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IIOHelper ioHelper, - IEditorConfigurationParser editorConfigurationParser) + public MarkdownPropertyEditor(IDataValueEditorFactory dataValueEditorFactory) : base(dataValueEditorFactory) - { - _ioHelper = ioHelper; - _editorConfigurationParser = editorConfigurationParser; - SupportsReadOnly = true; - } - - /// - protected override IConfigurationEditor CreateConfigurationEditor() => - new MarkdownConfigurationEditor(_ioHelper, _editorConfigurationParser); + => SupportsReadOnly = true; /// /// Create a custom value editor diff --git a/src/Umbraco.Core/PropertyEditors/MediaPicker3Configuration.cs b/src/Umbraco.Core/PropertyEditors/MediaPicker3Configuration.cs index 11ed4d1afd..ec8f7c3378 100644 --- a/src/Umbraco.Core/PropertyEditors/MediaPicker3Configuration.cs +++ b/src/Umbraco.Core/PropertyEditors/MediaPicker3Configuration.cs @@ -1,5 +1,3 @@ -using System.Runtime.Serialization; - namespace Umbraco.Cms.Core.PropertyEditors; /// @@ -7,58 +5,40 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// public class MediaPicker3Configuration : IIgnoreUserStartNodesConfig { - [ConfigurationField("filter", "Accepted types", "treesourcetypepicker", Description = "Limit to specific types")] + [ConfigurationField("filter")] public string? Filter { get; set; } - [ConfigurationField("multiple", "Pick multiple items", "boolean", Description = "Outputs a IEnumerable")] + [ConfigurationField("multiple")] public bool Multiple { get; set; } - [ConfigurationField("validationLimit", "Amount", "numberrange", Description = "Set a required range of medias")] + [ConfigurationField("validationLimit")] public NumberRange ValidationLimit { get; set; } = new(); - [ConfigurationField("startNodeId", "Start node", "mediapicker")] + [ConfigurationField("startNodeId")] public Udi? StartNodeId { get; set; } - [ConfigurationField("enableLocalFocalPoint", "Enable Focal Point", "boolean")] + [ConfigurationField("enableLocalFocalPoint")] public bool EnableLocalFocalPoint { get; set; } - [ConfigurationField( - "crops", - "Image Crops", - "views/propertyeditors/mediapicker3/prevalue/mediapicker3.crops.html", - Description = "Local crops, stored on document")] + [ConfigurationField("crops")] public CropConfiguration[]? Crops { get; set; } - [ConfigurationField( - Constants.DataTypes.ReservedPreValueKeys.IgnoreUserStartNodes, - "Ignore User Start Nodes", - "boolean", - Description = "Selecting this option allows a user to choose nodes that they normally don't have access to.")] + [ConfigurationField(Constants.DataTypes.ReservedPreValueKeys.IgnoreUserStartNodes)] public bool IgnoreUserStartNodes { get; set; } - [DataContract] public class NumberRange { - [DataMember(Name = "min")] public int? Min { get; set; } - [DataMember(Name = "max")] public int? Max { get; set; } } - [DataContract] public class CropConfiguration { - [DataMember(Name = "alias")] public string? Alias { get; set; } - [DataMember(Name = "label")] - public string? Label { get; set; } - - [DataMember(Name = "width")] public int Width { get; set; } - [DataMember(Name = "height")] public int Height { get; set; } } } diff --git a/src/Umbraco.Core/PropertyEditors/MediaPicker3ConfigurationEditor.cs b/src/Umbraco.Core/PropertyEditors/MediaPicker3ConfigurationEditor.cs index 59574906da..223d9767e6 100644 --- a/src/Umbraco.Core/PropertyEditors/MediaPicker3ConfigurationEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/MediaPicker3ConfigurationEditor.cs @@ -1,7 +1,4 @@ -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Services; namespace Umbraco.Cms.Core.PropertyEditors; @@ -10,27 +7,11 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// public class MediaPicker3ConfigurationEditor : ConfigurationEditor { - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] - public MediaPicker3ConfigurationEditor(IIOHelper ioHelper) - : this(ioHelper, StaticServiceProvider.Instance.GetRequiredService()) - { - } - /// /// Initializes a new instance of the class. /// - public MediaPicker3ConfigurationEditor(IIOHelper ioHelper, IEditorConfigurationParser editorConfigurationParser) - : base(ioHelper, editorConfigurationParser) + public MediaPicker3ConfigurationEditor(IIOHelper ioHelper) + : base(ioHelper) { - // FIXME: all this belongs clientside, this needs to go - // configure fields - // this is not part of ContentPickerConfiguration, - // but is required to configure the UI editor (when editing the configuration) - Field(nameof(MediaPicker3Configuration.StartNodeId)) - .Config = new Dictionary { { "idType", "udi" } }; - - Field(nameof(MediaPicker3Configuration.Filter)) - .Config = new Dictionary { { "itemType", "media" } }; } } diff --git a/src/Umbraco.Core/PropertyEditors/MediaPickerConfiguration.cs b/src/Umbraco.Core/PropertyEditors/MediaPickerConfiguration.cs deleted file mode 100644 index 92a206065b..0000000000 --- a/src/Umbraco.Core/PropertyEditors/MediaPickerConfiguration.cs +++ /dev/null @@ -1,27 +0,0 @@ -namespace Umbraco.Cms.Core.PropertyEditors; - -/// -/// Represents the configuration for the media picker value editor. -/// -[Obsolete("Please use the MediaPicker3 instead, will be removed in V13")] -public class MediaPickerConfiguration : IIgnoreUserStartNodesConfig -{ - [ConfigurationField("multiPicker", "Pick multiple items", "boolean")] - public bool Multiple { get; set; } - - [ConfigurationField("onlyImages", "Pick only images", "boolean", Description = "Only let the editor choose images from media.")] - public bool OnlyImages { get; set; } - - [ConfigurationField("disableFolderSelect", "Disable folder select", "boolean", Description = "Do not allow folders to be picked.")] - public bool DisableFolderSelect { get; set; } - - [ConfigurationField("startNodeId", "Start node", "mediapicker")] - public Udi? StartNodeId { get; set; } - - [ConfigurationField( - Constants.DataTypes.ReservedPreValueKeys.IgnoreUserStartNodes, - "Ignore User Start Nodes", - "boolean", - Description = "Selecting this option allows a user to choose nodes that they normally don't have access to.")] - public bool IgnoreUserStartNodes { get; set; } -} diff --git a/src/Umbraco.Core/PropertyEditors/MediaPickerConfigurationEditor.cs b/src/Umbraco.Core/PropertyEditors/MediaPickerConfigurationEditor.cs deleted file mode 100644 index 5f12f65988..0000000000 --- a/src/Umbraco.Core/PropertyEditors/MediaPickerConfigurationEditor.cs +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; -using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Services; - -namespace Umbraco.Cms.Core.PropertyEditors; - -/// -/// Represents the configuration editor for the media picker value editor. -/// -[Obsolete("Please use the MediaPicker3 instead, will be removed in V13")] -public class MediaPickerConfigurationEditor : ConfigurationEditor -{ - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] - public MediaPickerConfigurationEditor(IIOHelper ioHelper) - : this(ioHelper, StaticServiceProvider.Instance.GetRequiredService()) - { - } - - /// - /// Initializes a new instance of the class. - /// - public MediaPickerConfigurationEditor(IIOHelper ioHelper, IEditorConfigurationParser editorConfigurationParser) - : base(ioHelper, editorConfigurationParser) => - - // configure fields - // this is not part of ContentPickerConfiguration, - // but is required to configure the UI editor (when editing the configuration) - Field(nameof(MediaPickerConfiguration.StartNodeId)) - .Config = new Dictionary { { "idType", "udi" } }; - - public override IDictionary ToValueEditor(IDictionary configuration) - { - // get the configuration fields - IDictionary config = base.ToValueEditor(configuration); - - // add extra fields - // not part of ContentPickerConfiguration but used to configure the UI editor - config["idType"] = "udi"; - - return config; - } -} diff --git a/src/Umbraco.Core/PropertyEditors/MemberGroupPickerPropertyEditor.cs b/src/Umbraco.Core/PropertyEditors/MemberGroupPickerPropertyEditor.cs index dcb19624be..141d4140d7 100644 --- a/src/Umbraco.Core/PropertyEditors/MemberGroupPickerPropertyEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/MemberGroupPickerPropertyEditor.cs @@ -2,16 +2,11 @@ namespace Umbraco.Cms.Core.PropertyEditors; [DataEditor( Constants.PropertyEditors.Aliases.MemberGroupPicker, - "Member Group Picker", - "membergrouppicker", ValueType = ValueTypes.Text, - Group = Constants.PropertyEditors.Groups.People, - Icon = Constants.Icons.MemberGroup, ValueEditorIsReusable = true)] public class MemberGroupPickerPropertyEditor : DataEditor { - public MemberGroupPickerPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory) - : base(dataValueEditorFactory) => - SupportsReadOnly = true; + public MemberGroupPickerPropertyEditor(IDataValueEditorFactory dataValueEditorFactory) + : base(dataValueEditorFactory) + => SupportsReadOnly = true; } diff --git a/src/Umbraco.Core/PropertyEditors/MemberPickerConfiguration.cs b/src/Umbraco.Core/PropertyEditors/MemberPickerConfiguration.cs deleted file mode 100644 index dc0ab648df..0000000000 --- a/src/Umbraco.Core/PropertyEditors/MemberPickerConfiguration.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Umbraco.Cms.Core.PropertyEditors; - -public class MemberPickerConfiguration : ConfigurationEditor -{ - public override IDictionary DefaultConfiguration => - new Dictionary { { "idType", "udi" } }; -} diff --git a/src/Umbraco.Core/PropertyEditors/MemberPickerPropertyEditor.cs b/src/Umbraco.Core/PropertyEditors/MemberPickerPropertyEditor.cs index b16acaffb1..e7cc3970d1 100644 --- a/src/Umbraco.Core/PropertyEditors/MemberPickerPropertyEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/MemberPickerPropertyEditor.cs @@ -2,18 +2,11 @@ namespace Umbraco.Cms.Core.PropertyEditors; [DataEditor( Constants.PropertyEditors.Aliases.MemberPicker, - "Member Picker", - "memberpicker", ValueType = ValueTypes.String, - Group = Constants.PropertyEditors.Groups.People, - Icon = Constants.Icons.Member, ValueEditorIsReusable = true)] public class MemberPickerPropertyEditor : DataEditor { - public MemberPickerPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory) - : base(dataValueEditorFactory) => - SupportsReadOnly = true; - - protected override IConfigurationEditor CreateConfigurationEditor() => new MemberPickerConfiguration(); + public MemberPickerPropertyEditor(IDataValueEditorFactory dataValueEditorFactory) + : base(dataValueEditorFactory) + => SupportsReadOnly = true; } diff --git a/src/Umbraco.Core/PropertyEditors/MissingPropertyEditor.cs b/src/Umbraco.Core/PropertyEditors/MissingPropertyEditor.cs index 560795dfb5..2f449666bd 100644 --- a/src/Umbraco.Core/PropertyEditors/MissingPropertyEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/MissingPropertyEditor.cs @@ -1,3 +1,4 @@ +using Umbraco.Cms.Core.Composing; using Umbraco.Cms.Core.Models; namespace Umbraco.Cms.Core.PropertyEditors; @@ -6,18 +7,13 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// Represents a temporary representation of an editor for cases where a data type is created but not editor is /// available. /// +[HideFromTypeFinder] public class MissingPropertyEditor : IDataEditor { public string Alias => "Umbraco.Missing"; - public EditorType Type => EditorType.Nothing; - public string Name => "Missing property editor"; - public string Icon => string.Empty; - - public string Group => string.Empty; - public bool IsDeprecated => false; public IDictionary DefaultConfiguration => throw new NotImplementedException(); diff --git a/src/Umbraco.Core/PropertyEditors/MultiNodePickerConfiguration.cs b/src/Umbraco.Core/PropertyEditors/MultiNodePickerConfiguration.cs index c1ca368c47..3c199e58af 100644 --- a/src/Umbraco.Core/PropertyEditors/MultiNodePickerConfiguration.cs +++ b/src/Umbraco.Core/PropertyEditors/MultiNodePickerConfiguration.cs @@ -5,25 +5,15 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// public class MultiNodePickerConfiguration : IIgnoreUserStartNodesConfig { - [ConfigurationField("startNode", "Node type", "treesource")] + [ConfigurationField("startNode")] public MultiNodePickerConfigurationTreeSource? TreeSource { get; set; } - [ConfigurationField("filter", "Allow items of type", "treesourcetypepicker", Description = "Select the applicable types")] - public string? Filter { get; set; } - - [ConfigurationField("minNumber", "Minimum number of items", "number")] + [ConfigurationField("minNumber")] public int MinNumber { get; set; } - [ConfigurationField("maxNumber", "Maximum number of items", "number")] + [ConfigurationField("maxNumber")] public int MaxNumber { get; set; } - [ConfigurationField("showOpenButton", "Show open button", "boolean", Description = "Opens the node in a dialog")] - public bool ShowOpen { get; set; } - - [ConfigurationField( - Constants.DataTypes.ReservedPreValueKeys.IgnoreUserStartNodes, - "Ignore User Start Nodes", - "boolean", - Description = "Selecting this option allows a user to choose nodes that they normally don't have access to.")] + [ConfigurationField(Constants.DataTypes.ReservedPreValueKeys.IgnoreUserStartNodes)] public bool IgnoreUserStartNodes { get; set; } } diff --git a/src/Umbraco.Core/PropertyEditors/MultiNodePickerConfigurationEditor.cs b/src/Umbraco.Core/PropertyEditors/MultiNodePickerConfigurationEditor.cs index 60cc295210..b2c5b0bf8c 100644 --- a/src/Umbraco.Core/PropertyEditors/MultiNodePickerConfigurationEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/MultiNodePickerConfigurationEditor.cs @@ -1,10 +1,7 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Services; namespace Umbraco.Cms.Core.PropertyEditors; @@ -13,40 +10,8 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// public class MultiNodePickerConfigurationEditor : ConfigurationEditor { - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] public MultiNodePickerConfigurationEditor(IIOHelper ioHelper) - : this(ioHelper, StaticServiceProvider.Instance.GetRequiredService()) + : base(ioHelper) { } - - public MultiNodePickerConfigurationEditor(IIOHelper ioHelper, IEditorConfigurationParser editorConfigurationParser) - : base(ioHelper, editorConfigurationParser) => - Field(nameof(MultiNodePickerConfiguration.TreeSource)) - .Config = new Dictionary { { "idType", "udi" } }; - - public override IDictionary ToConfigurationEditor(IDictionary configuration) - { - IDictionary config = base.ToConfigurationEditor(configuration); - // TODO: this belongs on the client side! - if (config.TryGetValue("maxNumber", out var maxNumberValue) - && int.TryParse(maxNumberValue.ToString(), out var maxNumber) - && maxNumber > 1) - { - config["multiPicker"] = true; - } - - return config; - } - - public override IDictionary ToValueEditor(IDictionary configuration) - { - IDictionary config = base.ToValueEditor(configuration); - // TODO: this belongs on the client side! - config["multiPicker"] = true; - config["showEditButton"] = false; - config["showPathOnHover"] = false; - config["idType"] = "udi"; - return config; - } } diff --git a/src/Umbraco.Core/PropertyEditors/MultiUrlPickerConfiguration.cs b/src/Umbraco.Core/PropertyEditors/MultiUrlPickerConfiguration.cs index 35d51cb944..c6e9ec6340 100644 --- a/src/Umbraco.Core/PropertyEditors/MultiUrlPickerConfiguration.cs +++ b/src/Umbraco.Core/PropertyEditors/MultiUrlPickerConfiguration.cs @@ -2,26 +2,12 @@ namespace Umbraco.Cms.Core.PropertyEditors; public class MultiUrlPickerConfiguration : IIgnoreUserStartNodesConfig { - [ConfigurationField("minNumber", "Minimum number of items", "number")] + [ConfigurationField("minNumber")] public int MinNumber { get; set; } - [ConfigurationField("maxNumber", "Maximum number of items", "number")] + [ConfigurationField("maxNumber")] public int MaxNumber { get; set; } - [ConfigurationField("overlaySize", "Overlay Size", "overlaysize", Description = "Select the width of the overlay.")] - public string? OverlaySize { get; set; } - - [ConfigurationField( - "hideAnchor", - "Hide anchor/query string input", - "boolean", - Description = "Selecting this hides the anchor/query string input field in the linkpicker overlay.")] - public bool HideAnchor { get; set; } - - [ConfigurationField( - Constants.DataTypes.ReservedPreValueKeys.IgnoreUserStartNodes, - "Ignore user start nodes", - "boolean", - Description = "Selecting this option allows a user to choose nodes that they normally don't have access to.")] + [ConfigurationField(Constants.DataTypes.ReservedPreValueKeys.IgnoreUserStartNodes)] public bool IgnoreUserStartNodes { get; set; } } diff --git a/src/Umbraco.Core/PropertyEditors/MultiUrlPickerConfigurationEditor.cs b/src/Umbraco.Core/PropertyEditors/MultiUrlPickerConfigurationEditor.cs index 4dfe988a3b..7d2f71bef1 100644 --- a/src/Umbraco.Core/PropertyEditors/MultiUrlPickerConfigurationEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/MultiUrlPickerConfigurationEditor.cs @@ -1,24 +1,14 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Services; namespace Umbraco.Cms.Core.PropertyEditors; public class MultiUrlPickerConfigurationEditor : ConfigurationEditor { - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] public MultiUrlPickerConfigurationEditor(IIOHelper ioHelper) - : this(ioHelper, StaticServiceProvider.Instance.GetRequiredService()) - { - } - - public MultiUrlPickerConfigurationEditor(IIOHelper ioHelper, IEditorConfigurationParser editorConfigurationParser) - : base(ioHelper, editorConfigurationParser) + : base(ioHelper) { } } diff --git a/src/Umbraco.Core/PropertyEditors/NestedContentConfiguration.cs b/src/Umbraco.Core/PropertyEditors/NestedContentConfiguration.cs deleted file mode 100644 index 01656fe78f..0000000000 --- a/src/Umbraco.Core/PropertyEditors/NestedContentConfiguration.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.PropertyEditors; - -/// -/// Represents the configuration for the nested content value editor. -/// -[Obsolete("Nested content is obsolete, will be removed in V13")] -public class NestedContentConfiguration -{ - [ConfigurationField("contentTypes", "Element Types", "views/propertyeditors/nestedcontent/nestedcontent.doctypepicker.html", Description = "Select the Element Types to use as models for the items.")] - public ContentType[]? ContentTypes { get; set; } - - [ConfigurationField("minItems", "Min Items", "number", Description = "Minimum number of items allowed.")] - public int? MinItems { get; set; } - - [ConfigurationField("maxItems", "Max Items", "number", Description = "Maximum number of items allowed.")] - public int? MaxItems { get; set; } - - [ConfigurationField("confirmDeletes", "Confirm Deletes", "boolean", Description = "Requires editor confirmation for delete actions.")] - public bool ConfirmDeletes { get; set; } = true; - - [ConfigurationField("showIcons", "Show Icons", "boolean", Description = "Show the Element Type icons.")] - public bool ShowIcons { get; set; } = true; - - [ConfigurationField("expandsOnLoad", "Expands on load", "boolean", Description = "A single item is automatically expanded")] - public bool ExpandsOnLoad { get; set; } = true; - - [ConfigurationField("hideLabel", "Hide Label", "boolean", Description = "Hide the property label and let the item list span the full width of the editor window.")] - public bool HideLabel { get; set; } - - [DataContract] - public class ContentType - { - [DataMember(Name = "ncAlias")] - public string? Alias { get; set; } - - [DataMember(Name = "ncTabAlias")] - public string? TabAlias { get; set; } - - [DataMember(Name = "nameTemplate")] - public string? Template { get; set; } - } -} diff --git a/src/Umbraco.Core/PropertyEditors/NestedContentConfigurationEditor.cs b/src/Umbraco.Core/PropertyEditors/NestedContentConfigurationEditor.cs deleted file mode 100644 index aad5529e1f..0000000000 --- a/src/Umbraco.Core/PropertyEditors/NestedContentConfigurationEditor.cs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; -using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Services; - -namespace Umbraco.Cms.Core.PropertyEditors; - -/// -/// Represents the configuration editor for the nested content value editor. -/// -[Obsolete("Nested content is obsolete, will be removed in V13")] -public class NestedContentConfigurationEditor : ConfigurationEditor -{ - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] - public NestedContentConfigurationEditor(IIOHelper ioHelper) - : this(ioHelper, StaticServiceProvider.Instance.GetRequiredService()) - { - } - - public NestedContentConfigurationEditor(IIOHelper ioHelper, IEditorConfigurationParser editorConfigurationParser) - : base(ioHelper, editorConfigurationParser) - { - } -} diff --git a/src/Umbraco.Core/PropertyEditors/ParameterEditorCollection.cs b/src/Umbraco.Core/PropertyEditors/ParameterEditorCollection.cs deleted file mode 100644 index 746a4e2c5e..0000000000 --- a/src/Umbraco.Core/PropertyEditors/ParameterEditorCollection.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Umbraco.Cms.Core.Composing; -using Umbraco.Cms.Core.Manifest; - -namespace Umbraco.Cms.Core.PropertyEditors; - -public class ParameterEditorCollection : BuilderCollectionBase -{ - public ParameterEditorCollection(DataEditorCollection dataEditors, ILegacyManifestParser legacyManifestParser) - : base(() => dataEditors - .Where(x => (x.Type & EditorType.MacroParameter) > 0) - .Union(legacyManifestParser.CombinedManifest.PropertyEditors)) - { - } - - // note: virtual so it can be mocked - public virtual IDataEditor? this[string alias] - => this.SingleOrDefault(x => x.Alias == alias); - - public virtual bool TryGet(string alias, out IDataEditor? editor) - { - editor = this.FirstOrDefault(x => x.Alias == alias); - return editor != null; - } -} diff --git a/src/Umbraco.Core/PropertyEditors/ParameterEditors/ContentTypeParameterEditor.cs b/src/Umbraco.Core/PropertyEditors/ParameterEditors/ContentTypeParameterEditor.cs deleted file mode 100644 index a283b33747..0000000000 --- a/src/Umbraco.Core/PropertyEditors/ParameterEditors/ContentTypeParameterEditor.cs +++ /dev/null @@ -1,25 +0,0 @@ -namespace Umbraco.Cms.Core.PropertyEditors.ParameterEditors; - -/// -/// Represents a content type parameter editor. -/// -[DataEditor( - "contentType", - EditorType.MacroParameter, - "Content Type Picker", - "entitypicker")] -public class ContentTypeParameterEditor : DataEditor -{ - /// - /// Initializes a new instance of the class. - /// - public ContentTypeParameterEditor( - IDataValueEditorFactory dataValueEditorFactory) - : base(dataValueEditorFactory) - { - // configure - DefaultConfiguration.Add("multiple", false); - DefaultConfiguration.Add("entityType", "DocumentType"); - SupportsReadOnly = true; - } -} diff --git a/src/Umbraco.Core/PropertyEditors/ParameterEditors/MultipleContentPickerParameterEditor.cs b/src/Umbraco.Core/PropertyEditors/ParameterEditors/MultipleContentPickerParameterEditor.cs deleted file mode 100644 index b5e7adb670..0000000000 --- a/src/Umbraco.Core/PropertyEditors/ParameterEditors/MultipleContentPickerParameterEditor.cs +++ /dev/null @@ -1,53 +0,0 @@ -using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Models; -using Umbraco.Cms.Core.Serialization; -using Umbraco.Cms.Core.Services; -using Umbraco.Cms.Core.Strings; - -namespace Umbraco.Cms.Core.PropertyEditors.ParameterEditors; - -/// -/// Represents a parameter editor of some sort. -/// -[DataEditor( - Constants.PropertyEditors.Aliases.MultiNodeTreePicker, - EditorType.MacroParameter, - "Multiple Content Picker", - "contentpicker")] -public class MultipleContentPickerParameterEditor : DataEditor -{ - /// - /// Initializes a new instance of the class. - /// - public MultipleContentPickerParameterEditor( - IDataValueEditorFactory dataValueEditorFactory) - : base(dataValueEditorFactory) - { - // configure - DefaultConfiguration.Add("multiPicker", "1"); - DefaultConfiguration.Add("minNumber", 0); - DefaultConfiguration.Add("maxNumber", 0); - SupportsReadOnly = true; - } - - protected override IDataValueEditor CreateValueEditor() => - DataValueEditorFactory.Create(Attribute!); - - internal class MultipleContentPickerParamateterValueEditor : MultiplePickerParamateterValueEditorBase - { - public MultipleContentPickerParamateterValueEditor( - ILocalizedTextService localizedTextService, - IShortStringHelper shortStringHelper, - IJsonSerializer jsonSerializer, - IIOHelper ioHelper, - DataEditorAttribute attribute, - IEntityService entityService) - : base(localizedTextService, shortStringHelper, jsonSerializer, ioHelper, attribute, entityService) - { - } - - public override string UdiEntityType { get; } = Constants.UdiEntityType.Document; - - public override UmbracoObjectTypes UmbracoObjectType { get; } = UmbracoObjectTypes.Document; - } -} diff --git a/src/Umbraco.Core/PropertyEditors/ParameterEditors/MultipleContentTypeParameterEditor.cs b/src/Umbraco.Core/PropertyEditors/ParameterEditors/MultipleContentTypeParameterEditor.cs deleted file mode 100644 index d024ba839f..0000000000 --- a/src/Umbraco.Core/PropertyEditors/ParameterEditors/MultipleContentTypeParameterEditor.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace Umbraco.Cms.Core.PropertyEditors.ParameterEditors; - -[DataEditor( - "contentTypeMultiple", - EditorType.MacroParameter, - "Multiple Content Type Picker", - "entitypicker")] -public class MultipleContentTypeParameterEditor : DataEditor -{ - public MultipleContentTypeParameterEditor( - IDataValueEditorFactory dataValueEditorFactory) - : base(dataValueEditorFactory) - { - // configure - DefaultConfiguration.Add("multiple", true); - DefaultConfiguration.Add("entityType", "DocumentType"); - SupportsReadOnly = true; - } -} diff --git a/src/Umbraco.Core/PropertyEditors/ParameterEditors/MultipleMediaPickerParameterEditor.cs b/src/Umbraco.Core/PropertyEditors/ParameterEditors/MultipleMediaPickerParameterEditor.cs deleted file mode 100644 index a60ff0ff0d..0000000000 --- a/src/Umbraco.Core/PropertyEditors/ParameterEditors/MultipleMediaPickerParameterEditor.cs +++ /dev/null @@ -1,51 +0,0 @@ -using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Models; -using Umbraco.Cms.Core.Serialization; -using Umbraco.Cms.Core.Services; -using Umbraco.Cms.Core.Strings; - -namespace Umbraco.Cms.Core.PropertyEditors.ParameterEditors; - -/// -/// Represents a multiple media picker macro parameter editor. -/// -[DataEditor( - Constants.PropertyEditors.Aliases.MultipleMediaPicker, - EditorType.MacroParameter, - "Multiple Media Picker", - "mediapicker", - ValueType = ValueTypes.Text)] -public class MultipleMediaPickerParameterEditor : DataEditor -{ - /// - /// Initializes a new instance of the class. - /// - public MultipleMediaPickerParameterEditor( - IDataValueEditorFactory dataValueEditorFactory) - : base(dataValueEditorFactory) - { - DefaultConfiguration.Add("multiPicker", "1"); - SupportsReadOnly = true; - } - - protected override IDataValueEditor CreateValueEditor() => - DataValueEditorFactory.Create(Attribute!); - - internal class MultipleMediaPickerPropertyValueEditor : MultiplePickerParamateterValueEditorBase - { - public MultipleMediaPickerPropertyValueEditor( - ILocalizedTextService localizedTextService, - IShortStringHelper shortStringHelper, - IJsonSerializer jsonSerializer, - IIOHelper ioHelper, - DataEditorAttribute attribute, - IEntityService entityService) - : base(localizedTextService, shortStringHelper, jsonSerializer, ioHelper, attribute, entityService) - { - } - - public override string UdiEntityType { get; } = Constants.UdiEntityType.Media; - - public override UmbracoObjectTypes UmbracoObjectType { get; } = UmbracoObjectTypes.Media; - } -} diff --git a/src/Umbraco.Core/PropertyEditors/ParameterEditors/MultiplePickerParamateterValueEditorBase.cs b/src/Umbraco.Core/PropertyEditors/ParameterEditors/MultiplePickerParamateterValueEditorBase.cs deleted file mode 100644 index 8aaea32ab4..0000000000 --- a/src/Umbraco.Core/PropertyEditors/ParameterEditors/MultiplePickerParamateterValueEditorBase.cs +++ /dev/null @@ -1,57 +0,0 @@ -using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Models; -using Umbraco.Cms.Core.Models.Editors; -using Umbraco.Cms.Core.Serialization; -using Umbraco.Cms.Core.Services; -using Umbraco.Cms.Core.Strings; - -namespace Umbraco.Cms.Core.PropertyEditors.ParameterEditors; - -internal abstract class MultiplePickerParamateterValueEditorBase : DataValueEditor, IDataValueReference -{ - private readonly IEntityService _entityService; - - public MultiplePickerParamateterValueEditorBase( - ILocalizedTextService localizedTextService, - IShortStringHelper shortStringHelper, - IJsonSerializer jsonSerializer, - IIOHelper ioHelper, - DataEditorAttribute attribute, - IEntityService entityService) - : base(localizedTextService, shortStringHelper, jsonSerializer, ioHelper, attribute) => - _entityService = entityService; - - public abstract string UdiEntityType { get; } - - public abstract UmbracoObjectTypes UmbracoObjectType { get; } - - public IEnumerable GetReferences(object? value) - { - var asString = value is string str ? str : value?.ToString(); - - if (string.IsNullOrEmpty(asString)) - { - yield break; - } - - foreach (var udiStr in asString.Split(',')) - { - if (UdiParser.TryParse(udiStr, out Udi? udi)) - { - yield return new UmbracoEntityReference(udi); - } - - // this is needed to support the legacy case when the multiple media picker parameter editor stores ints not udis - if (int.TryParse(udiStr, out var id)) - { - Attempt guidAttempt = _entityService.GetKey(id, UmbracoObjectType); - Guid guid = guidAttempt.Success ? guidAttempt.Result : Guid.Empty; - - if (guid != Guid.Empty) - { - yield return new UmbracoEntityReference(new GuidUdi(Constants.UdiEntityType.Media, guid)); - } - } - } - } -} diff --git a/src/Umbraco.Core/PropertyEditors/ParameterEditors/MultiplePropertyGroupParameterEditor.cs b/src/Umbraco.Core/PropertyEditors/ParameterEditors/MultiplePropertyGroupParameterEditor.cs deleted file mode 100644 index 0a6c6d4fe5..0000000000 --- a/src/Umbraco.Core/PropertyEditors/ParameterEditors/MultiplePropertyGroupParameterEditor.cs +++ /dev/null @@ -1,22 +0,0 @@ -namespace Umbraco.Cms.Core.PropertyEditors.ParameterEditors; - -[DataEditor( - "tabPickerMultiple", - EditorType.MacroParameter, - "Multiple Tab Picker", - "entitypicker")] -public class MultiplePropertyGroupParameterEditor : DataEditor -{ - public MultiplePropertyGroupParameterEditor( - IDataValueEditorFactory dataValueEditorFactory) - : base(dataValueEditorFactory) - { - // configure - DefaultConfiguration.Add("multiple", true); - DefaultConfiguration.Add("entityType", "PropertyGroup"); - - // don't publish the id for a property group, publish its alias, which is actually just its lower cased name - DefaultConfiguration.Add("publishBy", "alias"); - SupportsReadOnly = true; - } -} diff --git a/src/Umbraco.Core/PropertyEditors/ParameterEditors/MultiplePropertyTypeParameterEditor.cs b/src/Umbraco.Core/PropertyEditors/ParameterEditors/MultiplePropertyTypeParameterEditor.cs deleted file mode 100644 index 3fc2c31d18..0000000000 --- a/src/Umbraco.Core/PropertyEditors/ParameterEditors/MultiplePropertyTypeParameterEditor.cs +++ /dev/null @@ -1,22 +0,0 @@ -namespace Umbraco.Cms.Core.PropertyEditors.ParameterEditors; - -[DataEditor( - "propertyTypePickerMultiple", - EditorType.MacroParameter, - "Multiple Property Type Picker", - "entitypicker")] -public class MultiplePropertyTypeParameterEditor : DataEditor -{ - public MultiplePropertyTypeParameterEditor( - IDataValueEditorFactory dataValueEditorFactory) - : base(dataValueEditorFactory) - { - // configure - DefaultConfiguration.Add("multiple", "1"); - DefaultConfiguration.Add("entityType", "PropertyType"); - - // don't publish the id for a property type, publish its alias - DefaultConfiguration.Add("publishBy", "alias"); - SupportsReadOnly = true; - } -} diff --git a/src/Umbraco.Core/PropertyEditors/ParameterEditors/PropertyGroupParameterEditor.cs b/src/Umbraco.Core/PropertyEditors/ParameterEditors/PropertyGroupParameterEditor.cs deleted file mode 100644 index dd642dd38f..0000000000 --- a/src/Umbraco.Core/PropertyEditors/ParameterEditors/PropertyGroupParameterEditor.cs +++ /dev/null @@ -1,22 +0,0 @@ -namespace Umbraco.Cms.Core.PropertyEditors.ParameterEditors; - -[DataEditor( - "tabPicker", - EditorType.MacroParameter, - "Tab Picker", - "entitypicker")] -public class PropertyGroupParameterEditor : DataEditor -{ - public PropertyGroupParameterEditor( - IDataValueEditorFactory dataValueEditorFactory) - : base(dataValueEditorFactory) - { - // configure - DefaultConfiguration.Add("multiple", "0"); - DefaultConfiguration.Add("entityType", "PropertyGroup"); - - // don't publish the id for a property group, publish it's alias (which is actually just it's lower cased name) - DefaultConfiguration.Add("publishBy", "alias"); - SupportsReadOnly = true; - } -} diff --git a/src/Umbraco.Core/PropertyEditors/ParameterEditors/PropertyTypeParameterEditor.cs b/src/Umbraco.Core/PropertyEditors/ParameterEditors/PropertyTypeParameterEditor.cs deleted file mode 100644 index 8d7f252615..0000000000 --- a/src/Umbraco.Core/PropertyEditors/ParameterEditors/PropertyTypeParameterEditor.cs +++ /dev/null @@ -1,22 +0,0 @@ -namespace Umbraco.Cms.Core.PropertyEditors.ParameterEditors; - -[DataEditor( - "propertyTypePicker", - EditorType.MacroParameter, - "Property Type Picker", - "entitypicker")] -public class PropertyTypeParameterEditor : DataEditor -{ - public PropertyTypeParameterEditor( - IDataValueEditorFactory dataValueEditorFactory) - : base(dataValueEditorFactory) - { - // configure - DefaultConfiguration.Add("multiple", "0"); - DefaultConfiguration.Add("entityType", "PropertyType"); - - // don't publish the id for a property type, publish its alias - DefaultConfiguration.Add("publishBy", "alias"); - SupportsReadOnly = true; - } -} diff --git a/src/Umbraco.Core/PropertyEditors/PlainDateTimePropertyEditor.cs b/src/Umbraco.Core/PropertyEditors/PlainDateTimePropertyEditor.cs index 0ccfce2d28..0bc559972e 100644 --- a/src/Umbraco.Core/PropertyEditors/PlainDateTimePropertyEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/PlainDateTimePropertyEditor.cs @@ -8,10 +8,6 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// [DataEditor( Constants.PropertyEditors.Aliases.PlainDateTime, - EditorType.PropertyValue, - "Configuration-less date/time", - "not-applicable", - Icon = "umb:edit", ValueEditorIsReusable = true, ValueType = ValueTypes.DateTime)] public class PlainDateTimePropertyEditor : DataEditor diff --git a/src/Umbraco.Core/PropertyEditors/PlainDecimalPropertyEditor.cs b/src/Umbraco.Core/PropertyEditors/PlainDecimalPropertyEditor.cs index 4ed9dc3a3c..89b7442662 100644 --- a/src/Umbraco.Core/PropertyEditors/PlainDecimalPropertyEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/PlainDecimalPropertyEditor.cs @@ -5,10 +5,6 @@ /// [DataEditor( Constants.PropertyEditors.Aliases.PlainDecimal, - EditorType.PropertyValue, - "Configuration-less decimal", - "not-applicable", - Icon = "umb:edit", ValueEditorIsReusable = true, ValueType = ValueTypes.Decimal)] public class PlainDecimalPropertyEditor : DataEditor diff --git a/src/Umbraco.Core/PropertyEditors/PlainIntegerPropertyEditor.cs b/src/Umbraco.Core/PropertyEditors/PlainIntegerPropertyEditor.cs index c7aa1391c8..3cedbd19fb 100644 --- a/src/Umbraco.Core/PropertyEditors/PlainIntegerPropertyEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/PlainIntegerPropertyEditor.cs @@ -5,10 +5,6 @@ /// [DataEditor( Constants.PropertyEditors.Aliases.PlainInteger, - EditorType.PropertyValue, - "Configuration-less integer", - "not-applicable", - Icon = "umb:edit", ValueEditorIsReusable = true, ValueType = ValueTypes.Integer)] public class PlainIntegerPropertyEditor : DataEditor diff --git a/src/Umbraco.Core/PropertyEditors/PlainJsonPropertyEditor.cs b/src/Umbraco.Core/PropertyEditors/PlainJsonPropertyEditor.cs index 4124907de4..040dd74023 100644 --- a/src/Umbraco.Core/PropertyEditors/PlainJsonPropertyEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/PlainJsonPropertyEditor.cs @@ -5,10 +5,6 @@ /// [DataEditor( Constants.PropertyEditors.Aliases.PlainJson, - EditorType.PropertyValue, - "Configuration-less JSON", - "not-applicable", - Icon = "umb:edit", ValueEditorIsReusable = true, ValueType = ValueTypes.Json)] public class PlainJsonPropertyEditor : DataEditor diff --git a/src/Umbraco.Core/PropertyEditors/PlainStringPropertyEditor.cs b/src/Umbraco.Core/PropertyEditors/PlainStringPropertyEditor.cs index 4ed3bf592a..16986b1931 100644 --- a/src/Umbraco.Core/PropertyEditors/PlainStringPropertyEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/PlainStringPropertyEditor.cs @@ -5,10 +5,6 @@ /// [DataEditor( Constants.PropertyEditors.Aliases.PlainString, - EditorType.PropertyValue, - "Configuration-less string", - "not-applicable", - Icon = "umb:edit", ValueEditorIsReusable = true, ValueType = ValueTypes.Text)] // NOTE: for ease of use it's called "String", but it's really stored as TEXT public class PlainStringPropertyEditor : DataEditor diff --git a/src/Umbraco.Core/PropertyEditors/PlainTimePropertyEditor.cs b/src/Umbraco.Core/PropertyEditors/PlainTimePropertyEditor.cs index 1a93d626fe..d807ac96f8 100644 --- a/src/Umbraco.Core/PropertyEditors/PlainTimePropertyEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/PlainTimePropertyEditor.cs @@ -5,15 +5,11 @@ /// [DataEditor( Constants.PropertyEditors.Aliases.PlainTime, - EditorType.PropertyValue, - "Configuration-less time", - "not-applicable", - Icon = "umb:edit", ValueEditorIsReusable = true, ValueType = ValueTypes.Time)] public class PlainTimePropertyEditor : DataEditor { - public PlainTimePropertyEditor(IDataValueEditorFactory dataValueEditorFactory, EditorType type = EditorType.PropertyValue) - : base(dataValueEditorFactory, type) + public PlainTimePropertyEditor(IDataValueEditorFactory dataValueEditorFactory) + : base(dataValueEditorFactory) => SupportsReadOnly = true; } diff --git a/src/Umbraco.Core/PropertyEditors/PropertyEditorCollection.cs b/src/Umbraco.Core/PropertyEditors/PropertyEditorCollection.cs index 04a111733c..91346aa9cc 100644 --- a/src/Umbraco.Core/PropertyEditors/PropertyEditorCollection.cs +++ b/src/Umbraco.Core/PropertyEditors/PropertyEditorCollection.cs @@ -8,14 +8,12 @@ public class PropertyEditorCollection : BuilderCollectionBase { public PropertyEditorCollection(DataEditorCollection dataEditors, ILegacyManifestParser legacyManifestParser) : base(() => dataEditors - .Where(x => (x.Type & EditorType.PropertyValue) > 0) .Union(legacyManifestParser.CombinedManifest.PropertyEditors)) { } public PropertyEditorCollection(DataEditorCollection dataEditors) - : base(() => dataEditors - .Where(x => (x.Type & EditorType.PropertyValue) > 0)) + : base(() => dataEditors) { } diff --git a/src/Umbraco.Core/PropertyEditors/RichTextConfiguration.cs b/src/Umbraco.Core/PropertyEditors/RichTextConfiguration.cs index 3c028b9a39..c6dbf4bd06 100644 --- a/src/Umbraco.Core/PropertyEditors/RichTextConfiguration.cs +++ b/src/Umbraco.Core/PropertyEditors/RichTextConfiguration.cs @@ -1,5 +1,3 @@ -using System.Runtime.Serialization; - namespace Umbraco.Cms.Core.PropertyEditors; /// @@ -7,66 +5,19 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// public class RichTextConfiguration : IIgnoreUserStartNodesConfig { - // TODO: Make these strongly typed, for now this works though - [ConfigurationField("editor", "Editor", "views/propertyeditors/rte/rte.prevalues.html", HideLabel = true)] - public object? Editor { get; set; } - - [ConfigurationField("blocks", "Available Blocks", "views/propertyeditors/rte/blocks/prevalue/blockrte.blockconfiguration.html", Description = "Define the available blocks.")] + [ConfigurationField("blocks")] public RichTextBlockConfiguration[]? Blocks { get; set; } = null!; - [ConfigurationField("useLiveEditing", "Blocks Live editing mode", "boolean", Description = "Live updated Block Elements when they are edited.")] - public bool UseLiveEditing { get; set; } - - [ConfigurationField("overlaySize", "Overlay Size", "overlaysize", Description = "Select the width of the link picker overlay.")] - public string? OverlaySize { get; set; } - - [ConfigurationField("hideLabel", "Hide Label", "boolean")] - public bool HideLabel { get; set; } - - [ConfigurationField("mediaParentId", "Image Upload Folder", "mediafolderpicker", Description = "Choose the upload location of pasted images")] + [ConfigurationField("mediaParentId")] public GuidUdi? MediaParentId { get; set; } - [ConfigurationField( - Constants.DataTypes.ReservedPreValueKeys.IgnoreUserStartNodes, - "Ignore User Start Nodes", - "boolean", - Description = "Selecting this option allows a user to choose nodes that they normally don't have access to.")] + [ConfigurationField(Constants.DataTypes.ReservedPreValueKeys.IgnoreUserStartNodes)] public bool IgnoreUserStartNodes { get; set; } - [DataContract] public class RichTextBlockConfiguration : IBlockConfiguration { - [DataMember(Name = "backgroundColor")] - public string? BackgroundColor { get; set; } - - [DataMember(Name = "iconColor")] - public string? IconColor { get; set; } - - [DataMember(Name = "thumbnail")] - public string? Thumbnail { get; set; } - - [DataMember(Name = "contentElementTypeKey")] public Guid ContentElementTypeKey { get; set; } - [DataMember(Name = "settingsElementTypeKey")] public Guid? SettingsElementTypeKey { get; set; } - - [DataMember(Name = "view")] - public string? View { get; set; } - - [DataMember(Name = "stylesheet")] - public string? Stylesheet { get; set; } - - [DataMember(Name = "label")] - public string? Label { get; set; } - - [DataMember(Name = "editorSize")] - public string? EditorSize { get; set; } - - [DataMember(Name = "forceHideContentEditorInOverlay")] - public bool ForceHideContentEditorInOverlay { get; set; } - - [DataMember(Name = "displayInline")] - public bool DisplayInline { get; set; } } } diff --git a/src/Umbraco.Core/PropertyEditors/RichTextConfigurationEditor.cs b/src/Umbraco.Core/PropertyEditors/RichTextConfigurationEditor.cs index d0afbf80d3..a6dbf923b8 100644 --- a/src/Umbraco.Core/PropertyEditors/RichTextConfigurationEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/RichTextConfigurationEditor.cs @@ -1,10 +1,7 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Services; namespace Umbraco.Cms.Core.PropertyEditors; @@ -13,15 +10,8 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// public class RichTextConfigurationEditor : ConfigurationEditor { - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] public RichTextConfigurationEditor(IIOHelper ioHelper) - : this(ioHelper, StaticServiceProvider.Instance.GetRequiredService()) - { - } - - public RichTextConfigurationEditor(IIOHelper ioHelper, IEditorConfigurationParser editorConfigurationParser) - : base(ioHelper, editorConfigurationParser) + : base(ioHelper) { } } diff --git a/src/Umbraco.Core/PropertyEditors/SliderConfiguration.cs b/src/Umbraco.Core/PropertyEditors/SliderConfiguration.cs index 4000af6b82..68b90c7403 100644 --- a/src/Umbraco.Core/PropertyEditors/SliderConfiguration.cs +++ b/src/Umbraco.Core/PropertyEditors/SliderConfiguration.cs @@ -5,21 +5,12 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// public class SliderConfiguration { - [ConfigurationField("enableRange", "Enable range", "boolean")] + [ConfigurationField("enableRange")] public bool EnableRange { get; set; } - [ConfigurationField("initVal1", "Initial value", "number")] - public decimal InitialValue { get; set; } - - [ConfigurationField("initVal2", "Initial value 2", "number", Description = "Used when range is enabled")] - public decimal InitialValue2 { get; set; } - - [ConfigurationField("minVal", "Minimum value", "number", Description = "Must be smaller than the Maximum value")] + [ConfigurationField("minVal")] public decimal MinimumValue { get; set; } - [ConfigurationField("maxVal", "Maximum value", "number", Description = "Must be larger than the Minimum value")] + [ConfigurationField("maxVal")] public decimal MaximumValue { get; set; } - - [ConfigurationField("step", "Step increments", "number", Description = "Must be a positive value")] - public decimal StepIncrements { get; set; } } diff --git a/src/Umbraco.Core/PropertyEditors/SliderConfigurationEditor.cs b/src/Umbraco.Core/PropertyEditors/SliderConfigurationEditor.cs index 915e92d709..e239ea002c 100644 --- a/src/Umbraco.Core/PropertyEditors/SliderConfigurationEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/SliderConfigurationEditor.cs @@ -1,10 +1,7 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Services; namespace Umbraco.Cms.Core.PropertyEditors; @@ -13,16 +10,8 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// public class SliderConfigurationEditor : ConfigurationEditor { - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] public SliderConfigurationEditor(IIOHelper ioHelper) - : this(ioHelper, StaticServiceProvider.Instance.GetRequiredService()) - { - } - - public SliderConfigurationEditor(IIOHelper ioHelper, IEditorConfigurationParser editorConfigurationParser) - : base( - ioHelper, editorConfigurationParser) + : base(ioHelper) { } } diff --git a/src/Umbraco.Core/PropertyEditors/TagConfiguration.cs b/src/Umbraco.Core/PropertyEditors/TagConfiguration.cs index 5a9808f227..32f8846d10 100644 --- a/src/Umbraco.Core/PropertyEditors/TagConfiguration.cs +++ b/src/Umbraco.Core/PropertyEditors/TagConfiguration.cs @@ -7,14 +7,10 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// public class TagConfiguration { - [ConfigurationField("group", "Tag group", "requiredfield", Description = "Define a tag group")] + [ConfigurationField("group")] public string Group { get; set; } = "default"; - [ConfigurationField( - "storageType", - "Storage Type", - "views/propertyeditors/tags/tags.prevalues.html", - Description = "Select whether to store the tags in cache as JSON (default) or as CSV. The only benefits of storage as JSON is that you are able to have commas in a tag value")] + [ConfigurationField("storageType")] public TagsStorageType StorageType { get; set; } = TagsStorageType.Json; // not a field diff --git a/src/Umbraco.Core/PropertyEditors/TagConfigurationEditor.cs b/src/Umbraco.Core/PropertyEditors/TagConfigurationEditor.cs index 935c332abf..c50788165f 100644 --- a/src/Umbraco.Core/PropertyEditors/TagConfigurationEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/TagConfigurationEditor.cs @@ -2,9 +2,7 @@ // See LICENSE for more details. using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.PropertyEditors.Validators; -using Umbraco.Cms.Core.Services; namespace Umbraco.Cms.Core.PropertyEditors; @@ -13,30 +11,10 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// public class TagConfigurationEditor : ConfigurationEditor { - [Obsolete($"Use the constructor that does not accept {nameof(ILocalizedTextService)}. Will be removed in V15.")] - public TagConfigurationEditor(ManifestValueValidatorCollection validators, IIOHelper ioHelper, ILocalizedTextService localizedTextService, IEditorConfigurationParser editorConfigurationParser) - : this(ioHelper, editorConfigurationParser) - { - } - - public TagConfigurationEditor(IIOHelper ioHelper, IEditorConfigurationParser editorConfigurationParser) - : base(ioHelper, editorConfigurationParser) + public TagConfigurationEditor(IIOHelper ioHelper) + : base(ioHelper) { Field(nameof(TagConfiguration.Group)).Validators.Add(new RequiredValidator()); Field(nameof(TagConfiguration.StorageType)).Validators.Add(new RequiredValidator()); } - - public override IDictionary ToConfigurationEditor(IDictionary configuration) - { - IDictionary config = base.ToConfigurationEditor(configuration); - - // the front-end editor expects the string value of the storage type - // TODO: this (default value) belongs on the client side! - if (!config.ContainsKey("storageType")) - { - config["storageType"] = TagsStorageType.Json.ToString(); - } - - return config; - } } diff --git a/src/Umbraco.Core/PropertyEditors/TextAreaConfiguration.cs b/src/Umbraco.Core/PropertyEditors/TextAreaConfiguration.cs index 8e6355258b..7ab29b27cd 100644 --- a/src/Umbraco.Core/PropertyEditors/TextAreaConfiguration.cs +++ b/src/Umbraco.Core/PropertyEditors/TextAreaConfiguration.cs @@ -5,9 +5,6 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// public class TextAreaConfiguration { - [ConfigurationField("maxChars", "Maximum allowed characters", "number", Description = "If empty - no character limit")] + [ConfigurationField("maxChars")] public int? MaxChars { get; set; } - - [ConfigurationField("rows", "Number of rows", "number", Description = "If empty - 10 rows would be set as the default value")] - public int? Rows { get; set; } } diff --git a/src/Umbraco.Core/PropertyEditors/TextAreaConfigurationEditor.cs b/src/Umbraco.Core/PropertyEditors/TextAreaConfigurationEditor.cs index 027010b62e..7e3c8a1770 100644 --- a/src/Umbraco.Core/PropertyEditors/TextAreaConfigurationEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/TextAreaConfigurationEditor.cs @@ -1,10 +1,7 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Services; namespace Umbraco.Cms.Core.PropertyEditors; @@ -13,15 +10,8 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// public class TextAreaConfigurationEditor : ConfigurationEditor { - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] public TextAreaConfigurationEditor(IIOHelper ioHelper) - : this(ioHelper, StaticServiceProvider.Instance.GetRequiredService()) - { - } - - public TextAreaConfigurationEditor(IIOHelper ioHelper, IEditorConfigurationParser editorConfigurationParser) - : base(ioHelper, editorConfigurationParser) + : base(ioHelper) { } } diff --git a/src/Umbraco.Core/PropertyEditors/TextboxConfiguration.cs b/src/Umbraco.Core/PropertyEditors/TextboxConfiguration.cs index 26262f3589..880c121b69 100644 --- a/src/Umbraco.Core/PropertyEditors/TextboxConfiguration.cs +++ b/src/Umbraco.Core/PropertyEditors/TextboxConfiguration.cs @@ -5,6 +5,6 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// public class TextboxConfiguration { - [ConfigurationField("maxChars", "Maximum allowed characters", "textstringlimited", Description = "If empty, 512 character limit")] + [ConfigurationField("maxChars")] public int? MaxChars { get; set; } } diff --git a/src/Umbraco.Core/PropertyEditors/TextboxConfigurationEditor.cs b/src/Umbraco.Core/PropertyEditors/TextboxConfigurationEditor.cs index e97717fc88..f9cfcf01dd 100644 --- a/src/Umbraco.Core/PropertyEditors/TextboxConfigurationEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/TextboxConfigurationEditor.cs @@ -1,10 +1,7 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Services; namespace Umbraco.Cms.Core.PropertyEditors; @@ -13,15 +10,8 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// public class TextboxConfigurationEditor : ConfigurationEditor { - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] public TextboxConfigurationEditor(IIOHelper ioHelper) - : this(ioHelper, StaticServiceProvider.Instance.GetRequiredService()) - { - } - - public TextboxConfigurationEditor(IIOHelper ioHelper, IEditorConfigurationParser editorConfigurationParser) - : base(ioHelper, editorConfigurationParser) + : base(ioHelper) { } } diff --git a/src/Umbraco.Core/PropertyEditors/TrueFalseConfiguration.cs b/src/Umbraco.Core/PropertyEditors/TrueFalseConfiguration.cs deleted file mode 100644 index 604f4d3c30..0000000000 --- a/src/Umbraco.Core/PropertyEditors/TrueFalseConfiguration.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace Umbraco.Cms.Core.PropertyEditors; - -/// -/// Represents the configuration for the boolean value editor. -/// -public class TrueFalseConfiguration -{ - [ConfigurationField("default", "Initial State", "boolean", Description = "The initial state for the toggle, when it is displayed for the first time in the backoffice, eg. for a new content item.")] - public bool Default { get; set; } - - [ConfigurationField("showLabels", "Show toggle labels", "boolean", Description = "Show labels next to toggle button.")] - public bool ShowLabels { get; set; } - - [ConfigurationField("labelOn", "Label On", "textstring", Description = "Label text when enabled.")] - public string? LabelOn { get; set; } - - [ConfigurationField("labelOff", "Label Off", "textstring", Description = "Label text when disabled.")] - public string? LabelOff { get; set; } -} diff --git a/src/Umbraco.Core/PropertyEditors/TrueFalseConfigurationEditor.cs b/src/Umbraco.Core/PropertyEditors/TrueFalseConfigurationEditor.cs deleted file mode 100644 index b85c67453d..0000000000 --- a/src/Umbraco.Core/PropertyEditors/TrueFalseConfigurationEditor.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; -using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Services; - -namespace Umbraco.Cms.Core.PropertyEditors; - -/// -/// Represents the configuration editor for the boolean value editor. -/// -public class TrueFalseConfigurationEditor : ConfigurationEditor -{ - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] - public TrueFalseConfigurationEditor(IIOHelper ioHelper) - : this(ioHelper, StaticServiceProvider.Instance.GetRequiredService()) - { - } - - public TrueFalseConfigurationEditor(IIOHelper ioHelper, IEditorConfigurationParser editorConfigurationParser) - : base(ioHelper, editorConfigurationParser) - { - } -} diff --git a/src/Umbraco.Core/PropertyEditors/UserPickerConfiguration.cs b/src/Umbraco.Core/PropertyEditors/UserPickerConfiguration.cs deleted file mode 100644 index 9dce63bf12..0000000000 --- a/src/Umbraco.Core/PropertyEditors/UserPickerConfiguration.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Umbraco.Cms.Core.PropertyEditors; - -public class UserPickerConfiguration : ConfigurationEditor -{ - public override IDictionary DefaultConfiguration => new Dictionary - { - { "entityType", "User" }, { "multiPicker", "0" }, - }; -} diff --git a/src/Umbraco.Core/PropertyEditors/UserPickerPropertyEditor.cs b/src/Umbraco.Core/PropertyEditors/UserPickerPropertyEditor.cs index 79f9c6795b..1bd0b3ee26 100644 --- a/src/Umbraco.Core/PropertyEditors/UserPickerPropertyEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/UserPickerPropertyEditor.cs @@ -2,18 +2,11 @@ namespace Umbraco.Cms.Core.PropertyEditors; [DataEditor( Constants.PropertyEditors.Aliases.UserPicker, - "User Picker", - "userpicker", ValueType = ValueTypes.Integer, - Group = Constants.PropertyEditors.Groups.People, - Icon = Constants.Icons.User, ValueEditorIsReusable = true)] public class UserPickerPropertyEditor : DataEditor { - public UserPickerPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory) - : base(dataValueEditorFactory) => - SupportsReadOnly = true; - - protected override IConfigurationEditor CreateConfigurationEditor() => new UserPickerConfiguration(); + public UserPickerPropertyEditor(IDataValueEditorFactory dataValueEditorFactory) + : base(dataValueEditorFactory) + => SupportsReadOnly = true; } diff --git a/src/Umbraco.Core/PropertyEditors/ValueConverters/MediaPickerValueConverter.cs b/src/Umbraco.Core/PropertyEditors/ValueConverters/MediaPickerValueConverter.cs deleted file mode 100644 index a702c813ad..0000000000 --- a/src/Umbraco.Core/PropertyEditors/ValueConverters/MediaPickerValueConverter.cs +++ /dev/null @@ -1,152 +0,0 @@ -using System.Collections; -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DeliveryApi; -using Umbraco.Cms.Core.Models.DeliveryApi; -using Umbraco.Cms.Core.Models.PublishedContent; -using Umbraco.Cms.Core.PropertyEditors.DeliveryApi; -using Umbraco.Cms.Core.PublishedCache; -using Umbraco.Cms.Core.Routing; -using Umbraco.Cms.Web.Common.DependencyInjection; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.PropertyEditors.ValueConverters; - -/// -/// The media picker property value converter. -/// -[DefaultPropertyValueConverter] -[Obsolete("Please use the MediaPicker3 instead, will be removed in V13")] -public class MediaPickerValueConverter : PropertyValueConverterBase, IDeliveryApiPropertyValueConverter -{ - // hard-coding "image" here but that's how it works at UI level too - private const string ImageTypeAlias = "image"; - - private readonly IPublishedSnapshotAccessor _publishedSnapshotAccessor; - private readonly IApiMediaBuilder _apiMediaBuilder; - - [Obsolete("Use constructor that takes all parameters, scheduled for removal in V13")] - public MediaPickerValueConverter( - IPublishedSnapshotAccessor publishedSnapshotAccessor, - IPublishedModelFactory publishedModelFactory) - : this( - publishedSnapshotAccessor, - publishedModelFactory, - StaticServiceProvider.Instance.GetRequiredService()) - { - } - - public MediaPickerValueConverter( - IPublishedSnapshotAccessor publishedSnapshotAccessor, - // annoyingly not even ActivatorUtilitiesConstructor can fix ambiguous constructor exceptions. - // we need to keep this unused parameter, at least until the other constructor is removed - IPublishedModelFactory publishedModelFactory, - IApiMediaBuilder apiMediaBuilder) - { - _publishedSnapshotAccessor = publishedSnapshotAccessor ?? - throw new ArgumentNullException(nameof(publishedSnapshotAccessor)); - _apiMediaBuilder = apiMediaBuilder; - } - - public override bool IsConverter(IPublishedPropertyType propertyType) => - propertyType.EditorAlias.Equals(Constants.PropertyEditors.Aliases.MediaPicker); - - public override Type GetPropertyValueType(IPublishedPropertyType propertyType) - { - var isMultiple = IsMultipleDataType(propertyType.DataType); - return isMultiple - ? typeof(IEnumerable) - : typeof(IPublishedContent); - } - - public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType) - => PropertyCacheLevel.Snapshot; - - public override object? ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object? source, bool preview) - { - if (source == null) - { - return null; - } - - Udi[]? nodeIds = source.ToString()? - .Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries) - .Select(UdiParser.Parse) - .ToArray(); - return nodeIds; - } - - private bool IsMultipleDataType(PublishedDataType dataType) - { - MediaPickerConfiguration? config = - ConfigurationEditor.ConfigurationAs(dataType.ConfigurationObject); - return config?.Multiple ?? false; - } - - public override object? ConvertIntermediateToObject( - IPublishedElement owner, - IPublishedPropertyType propertyType, - PropertyCacheLevel cacheLevel, - object? source, - bool preview) - { - var isMultiple = IsMultipleDataType(propertyType.DataType); - - var udis = (Udi[]?)source; - var mediaItems = new List(); - - if (source == null) - { - return isMultiple ? mediaItems : null; - } - - if (udis?.Any() ?? false) - { - IPublishedSnapshot publishedSnapshot = _publishedSnapshotAccessor.GetRequiredPublishedSnapshot(); - foreach (Udi udi in udis) - { - if (udi is not GuidUdi guidUdi) - { - continue; - } - - IPublishedContent? item = publishedSnapshot?.Media?.GetById(guidUdi.Guid); - if (item != null) - { - mediaItems.Add(item); - } - } - - return isMultiple ? mediaItems : FirstOrDefault(mediaItems); - } - - return source; - } - - public PropertyCacheLevel GetDeliveryApiPropertyCacheLevel(IPublishedPropertyType propertyType) => PropertyCacheLevel.Elements; - - public PropertyCacheLevel GetDeliveryApiPropertyCacheLevelForExpansion(IPublishedPropertyType propertyType) => PropertyCacheLevel.Snapshot; - - public Type GetDeliveryApiPropertyValueType(IPublishedPropertyType propertyType) => typeof(IEnumerable); - - public object? ConvertIntermediateToDeliveryApiObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object? inter, bool preview, bool expanding) - { - var isMultiple = IsMultipleDataType(propertyType.DataType); - - // NOTE: eventually we might implement this explicitly instead of piggybacking on the default object conversion. however, this only happens once per cache rebuild, - // and the performance gain from an explicit implementation is negligible, so... at least for the time being this will do just fine. - var converted = ConvertIntermediateToObject(owner, propertyType, referenceCacheLevel, inter, preview); - if (isMultiple && converted is IEnumerable items) - { - return items.Select(_apiMediaBuilder.Build).ToArray(); - } - - if (isMultiple == false && converted is IPublishedContent item) - { - return new[] { _apiMediaBuilder.Build(item) }; - } - - return Array.Empty(); - } - - private object? FirstOrDefault(IList mediaItems) => mediaItems.Count == 0 ? null : mediaItems[0]; -} diff --git a/src/Umbraco.Core/PropertyEditors/ValueListConfiguration.cs b/src/Umbraco.Core/PropertyEditors/ValueListConfiguration.cs index ca727f7008..95dbf9db5c 100644 --- a/src/Umbraco.Core/PropertyEditors/ValueListConfiguration.cs +++ b/src/Umbraco.Core/PropertyEditors/ValueListConfiguration.cs @@ -1,5 +1,3 @@ -using System.Runtime.Serialization; - namespace Umbraco.Cms.Core.PropertyEditors; /// @@ -7,16 +5,11 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// public class ValueListConfiguration { - [ConfigurationField("items", "Configure", "multivalues", Description = "Add, remove or sort values for the list.")] + [ConfigurationField("items")] public List Items { get; set; } = new(); - [DataContract] public class ValueListItem { - [DataMember(Name = "id")] - public int Id { get; set; } - - [DataMember(Name = "value")] public string? Value { get; set; } } } diff --git a/src/Umbraco.Core/Services/DataTypeService.cs b/src/Umbraco.Core/Services/DataTypeService.cs index c27c72a6d8..4eeae15ca0 100644 --- a/src/Umbraco.Core/Services/DataTypeService.cs +++ b/src/Umbraco.Core/Services/DataTypeService.cs @@ -29,41 +29,9 @@ namespace Umbraco.Cms.Core.Services.Implement private readonly IContentTypeRepository _contentTypeRepository; private readonly IAuditRepository _auditRepository; private readonly IIOHelper _ioHelper; - private readonly IEditorConfigurationParser _editorConfigurationParser; private readonly IDataTypeContainerService _dataTypeContainerService; private readonly IUserIdKeyResolver _userIdKeyResolver; - [Obsolete("Please use the constructor that takes less parameters. Will be removed in V15.")] - public DataTypeService( - IDataValueEditorFactory dataValueEditorFactory, - ICoreScopeProvider provider, - ILoggerFactory loggerFactory, - IEventMessagesFactory eventMessagesFactory, - IDataTypeRepository dataTypeRepository, - IDataTypeContainerRepository dataTypeContainerRepository, - IAuditRepository auditRepository, - IEntityRepository entityRepository, - IContentTypeRepository contentTypeRepository, - IIOHelper ioHelper, - ILocalizedTextService localizedTextService, - ILocalizationService localizationService, - IShortStringHelper shortStringHelper, - IJsonSerializer jsonSerializer, - IEditorConfigurationParser editorConfigurationParser) - : this( - provider, - loggerFactory, - eventMessagesFactory, - dataTypeRepository, - dataValueEditorFactory, - auditRepository, - contentTypeRepository, - ioHelper, - editorConfigurationParser) - { - } - - public DataTypeService( ICoreScopeProvider provider, ILoggerFactory loggerFactory, @@ -72,8 +40,7 @@ namespace Umbraco.Cms.Core.Services.Implement IDataValueEditorFactory dataValueEditorFactory, IAuditRepository auditRepository, IContentTypeRepository contentTypeRepository, - IIOHelper ioHelper, - IEditorConfigurationParser editorConfigurationParser) + IIOHelper ioHelper) : base(provider, loggerFactory, eventMessagesFactory) { _dataValueEditorFactory = dataValueEditorFactory; @@ -81,7 +48,6 @@ namespace Umbraco.Cms.Core.Services.Implement _auditRepository = auditRepository; _contentTypeRepository = contentTypeRepository; _ioHelper = ioHelper; - _editorConfigurationParser = editorConfigurationParser; // resolve dependencies for obsolete methods through the static service provider, so they don't pollute the constructor signature _dataTypeContainerService = StaticServiceProvider.Instance.GetRequiredService(); @@ -372,7 +338,7 @@ namespace Umbraco.Cms.Core.Services.Implement .Where(x => x.Editor is MissingPropertyEditor); foreach (IDataType dataType in dataTypesWithMissingEditors) { - dataType.Editor = new LabelPropertyEditor(_dataValueEditorFactory, _ioHelper, _editorConfigurationParser); + dataType.Editor = new LabelPropertyEditor(_dataValueEditorFactory, _ioHelper); } } diff --git a/src/Umbraco.Core/Services/IEditorConfigurationParser.cs b/src/Umbraco.Core/Services/IEditorConfigurationParser.cs deleted file mode 100644 index 1a37045490..0000000000 --- a/src/Umbraco.Core/Services/IEditorConfigurationParser.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Umbraco.Cms.Core.PropertyEditors; - -namespace Umbraco.Cms.Core.Services; - -public interface IEditorConfigurationParser -{ - TConfiguration? ParseFromConfigurationEditor( - IDictionary? editorValues, - IEnumerable fields); - - Dictionary ParseToConfigurationEditor(TConfiguration? configuration); -} diff --git a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs index c58c705a52..4de064f11e 100644 --- a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs +++ b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs @@ -252,7 +252,6 @@ public static partial class UmbracoBuilderExtensions public static IUmbracoBuilder AddPropertyIndexValueFactories(this IUmbracoBuilder builder) { builder.Services.AddSingleton(); - builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); @@ -365,9 +364,6 @@ public static partial class UmbracoBuilderExtensions .AddNotificationHandler() .AddNotificationHandler() .AddNotificationHandler() - .AddNotificationHandler() - .AddNotificationHandler() - .AddNotificationHandler() .AddNotificationHandler() .AddNotificationHandler() .AddNotificationHandler() diff --git a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.MappingProfiles.cs b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.MappingProfiles.cs index 86c35d1099..7f0efa7b96 100644 --- a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.MappingProfiles.cs +++ b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.MappingProfiles.cs @@ -26,7 +26,6 @@ public static partial class UmbracoBuilderExtensions .Add() .Add() .Add() - .Add() .Add() .Add() .Add() diff --git a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.Services.cs b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.Services.cs index b9137e32d2..63204ec0b1 100644 --- a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.Services.cs +++ b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.Services.cs @@ -55,12 +55,10 @@ public static partial class UmbracoBuilderExtensions builder.Services.AddUnique(); builder.Services.AddSingleton(CreatePackageDataInstallation); builder.Services.AddUnique(); - builder.Services.AddUnique(); builder.Services.AddTransient(); builder.Services.AddUnique(); builder.Services.AddUnique(); builder.Services.AddTransient(); - builder.Services.AddSingleton(); builder.Services.AddTransient(); builder.Services.AddUnique(); builder.Services.AddUnique(); diff --git a/src/Umbraco.Infrastructure/Deploy/GridCellValueConnectorExtensions.cs b/src/Umbraco.Infrastructure/Deploy/GridCellValueConnectorExtensions.cs deleted file mode 100644 index d421dcd771..0000000000 --- a/src/Umbraco.Infrastructure/Deploy/GridCellValueConnectorExtensions.cs +++ /dev/null @@ -1,52 +0,0 @@ -using Umbraco.Cms.Core.Models; - -namespace Umbraco.Cms.Core.Deploy; - -/// -/// Extension methods adding backwards-compatability between and . -/// -/// -/// These extension methods will be removed in Umbraco 13. -/// -[Obsolete("The grid is obsolete, will be removed in V13")] -public static class GridCellValueConnectorExtensions -{ - /// - /// Gets the value. - /// - /// The connector. - /// The grid control. - /// The dependencies. - /// The context cache. - /// - /// The value. - /// - /// - /// This extension method tries to make use of the on types also implementing . - /// - public static string? GetValue(this IGridCellValueConnector connector, GridValue.GridControl gridControl, ICollection dependencies, IContextCache contextCache) - => connector is IGridCellValueConnector2 connector2 - ? connector2.GetValue(gridControl, dependencies, contextCache) - : connector.GetValue(gridControl, dependencies); - - /// - /// Sets the value. - /// - /// The connector. - /// The grid control. - /// The context cache. - /// - /// This extension method tries to make use of the on types also implementing . - /// - public static void SetValue(this IGridCellValueConnector connector, GridValue.GridControl gridControl, IContextCache contextCache) - { - if (connector is IGridCellValueConnector2 connector2) - { - connector2.SetValue(gridControl, contextCache); - } - else - { - connector.SetValue(gridControl); - } - } -} diff --git a/src/Umbraco.Infrastructure/Deploy/IGridCellValueConnector.cs b/src/Umbraco.Infrastructure/Deploy/IGridCellValueConnector.cs deleted file mode 100644 index 4395202a56..0000000000 --- a/src/Umbraco.Infrastructure/Deploy/IGridCellValueConnector.cs +++ /dev/null @@ -1,52 +0,0 @@ -using Umbraco.Cms.Core.Models; - -namespace Umbraco.Cms.Core.Deploy; - -/// -/// Defines methods that can convert a grid cell value to / from an environment-agnostic string. -/// -/// -/// Grid cell values may contain values such as content identifiers, that would be local -/// to one environment, and need to be converted in order to be deployed. -/// -public interface IGridCellValueConnector -{ - /// - /// Gets a value indicating whether the connector supports a specified grid editor view. - /// - /// The grid editor view. It needs to be the view instead of the alias as the view is really what - /// identifies what kind of connector should be used. Alias can be anything and you can have multiple different aliases - /// using the same kind of view. - /// - /// true if the specified view is connector; otherwise, false. - /// - /// - /// A value indicating whether the connector supports the grid editor view. - /// - bool IsConnector(string view); - - /// - /// Gets the value to be deployed from the control value as a string. - /// - /// The control containing the value. - /// The dependencies of the property. - /// - /// The grid cell value to be deployed. - /// - /// - /// Note that - /// - [Obsolete($"Implement {nameof(IGridCellValueConnector2)} and use the overload accepting {nameof(IContextCache)} instead. This overload will be removed in Umbraco 13.")] - string? GetValue(GridValue.GridControl gridControl, ICollection dependencies); - - /// - /// Allows you to modify the value of a control being deployed. - /// - /// The control being deployed. - /// - /// Follows the pattern of the property value connectors (). - /// The SetValue method is used to modify the value of the . - /// - [Obsolete($"Implement {nameof(IGridCellValueConnector2)} and use the overload accepting {nameof(IContextCache)} instead. This overload will be removed in Umbraco 13.")] - void SetValue(GridValue.GridControl gridControl); -} diff --git a/src/Umbraco.Infrastructure/Deploy/IGridCellValueConnector2.cs b/src/Umbraco.Infrastructure/Deploy/IGridCellValueConnector2.cs deleted file mode 100644 index 44a36677e9..0000000000 --- a/src/Umbraco.Infrastructure/Deploy/IGridCellValueConnector2.cs +++ /dev/null @@ -1,42 +0,0 @@ -using Umbraco.Cms.Core.Models; - -namespace Umbraco.Cms.Core.Deploy; - -/// -/// -/// This interface will be merged back into and removed in Umbraco 13. -/// -public interface IGridCellValueConnector2 : IGridCellValueConnector -{ - /// - [Obsolete($"Use the overload accepting {nameof(IContextCache)} instead. This overload will be removed in Umbraco 13.")] - string? IGridCellValueConnector.GetValue(GridValue.GridControl gridControl, ICollection dependencies) - => GetValue(gridControl, dependencies, PassThroughCache.Instance); - - /// - /// Gets the value to be deployed from the control value as a string. - /// - /// The control containing the value. - /// The dependencies of the property. - /// The context cache. - /// - /// The grid cell value to be deployed. - /// - string? GetValue(GridValue.GridControl gridControl, ICollection dependencies, IContextCache contextCache); - - /// - [Obsolete($"Use the overload accepting {nameof(IContextCache)} instead. This overload will be removed in Umbraco 13.")] - void IGridCellValueConnector.SetValue(GridValue.GridControl gridControl) - => SetValue(gridControl, PassThroughCache.Instance); - - /// - /// Allows you to modify the value of a control being deployed. - /// - /// The control being deployed. - /// The context cache. - /// - /// Follows the pattern of the property value connectors (). - /// The SetValue method is used to modify the value of the . - /// - void SetValue(GridValue.GridControl gridControl, IContextCache contextCache); -} diff --git a/src/Umbraco.Infrastructure/Manifest/DataEditorConverter.cs b/src/Umbraco.Infrastructure/Manifest/DataEditorConverter.cs index c5cd5596ec..02ef9a584f 100644 --- a/src/Umbraco.Infrastructure/Manifest/DataEditorConverter.cs +++ b/src/Umbraco.Infrastructure/Manifest/DataEditorConverter.cs @@ -49,32 +49,7 @@ internal class DataEditorConverter : JsonReadConverter /// protected override IDataEditor Create(Type objectType, string path, JObject jobject) - { - // in PackageManifest, property editors are IConfiguredDataEditor[] whereas - // parameter editors are IDataEditor[] - both will end up here because we handle - // IDataEditor and IConfiguredDataEditor implements it, but we can check the - // type to figure out what to create - EditorType type = EditorType.PropertyValue; - - var isPropertyEditor = path.StartsWith("propertyEditors["); - - if (isPropertyEditor) - { - // property editor - jobject["isPropertyEditor"] = JToken.FromObject(true); - if (jobject["isParameterEditor"] is JToken jToken && jToken.Value()) - { - type |= EditorType.MacroParameter; - } - } - else - { - // parameter editor - type = EditorType.MacroParameter; - } - - return new DataEditor(_dataValueEditorFactory, type); - } + => new DataEditor(_dataValueEditorFactory); /// protected override void Deserialize(JObject jobject, IDataEditor target, JsonSerializer serializer) diff --git a/src/Umbraco.Infrastructure/Manifest/LegacyManifestParser.cs b/src/Umbraco.Infrastructure/Manifest/LegacyManifestParser.cs index e4ce537454..4b57ccbde9 100644 --- a/src/Umbraco.Infrastructure/Manifest/LegacyManifestParser.cs +++ b/src/Umbraco.Infrastructure/Manifest/LegacyManifestParser.cs @@ -216,20 +216,6 @@ public class LegacyManifestParser : ILegacyManifestParser dashboard.View = _ioHelper.ResolveRelativeOrVirtualUrl(dashboard.View); } - foreach (GridEditor gridEditor in manifest.GridEditors) - { - gridEditor.View = _ioHelper.ResolveRelativeOrVirtualUrl(gridEditor.View); - gridEditor.Render = _ioHelper.ResolveRelativeOrVirtualUrl(gridEditor.Render); - } - - // add property editors that are also parameter editors, to the parameter editors list - // (the manifest format is kinda legacy) - var ppEditors = manifest.PropertyEditors.Where(x => (x.Type & EditorType.MacroParameter) > 0).ToList(); - if (ppEditors.Count > 0) - { - manifest.ParameterEditors = manifest.ParameterEditors.Union(ppEditors).ToArray(); - } - return manifest; } @@ -258,7 +244,6 @@ public class LegacyManifestParser : ILegacyManifestParser var stylesheets = new Dictionary>(); var propertyEditors = new List(); var parameterEditors = new List(); - var gridEditors = new List(); var contentApps = new List(); var dashboards = new List(); var sections = new List(); @@ -285,8 +270,6 @@ public class LegacyManifestParser : ILegacyManifestParser parameterEditors.AddRange(manifest.ParameterEditors); - gridEditors.AddRange(manifest.GridEditors); - contentApps.AddRange(manifest.ContentApps); dashboards.AddRange(manifest.Dashboards); @@ -297,7 +280,6 @@ public class LegacyManifestParser : ILegacyManifestParser return new CompositeLegacyPackageManifest( propertyEditors, parameterEditors, - gridEditors, contentApps, dashboards, sections, diff --git a/src/Umbraco.Infrastructure/Migrations/Install/DatabaseDataCreator.cs b/src/Umbraco.Infrastructure/Migrations/Install/DatabaseDataCreator.cs index 0ee9760349..ae55b9c5c1 100644 --- a/src/Umbraco.Infrastructure/Migrations/Install/DatabaseDataCreator.cs +++ b/src/Umbraco.Infrastructure/Migrations/Install/DatabaseDataCreator.cs @@ -2166,32 +2166,6 @@ internal class DatabaseDataCreator }); } - if (_database.Exists(1048)) - { - _database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, - new DataTypeDto - { - NodeId = 1048, - EditorAlias = Constants.PropertyEditors.Aliases.MediaPicker, - DbType = "Ntext", - }); - } - - if (_database.Exists(1049)) - { - _database.Insert( - Constants.DatabaseSchema.Tables.DataType, - "pk", - false, - new DataTypeDto - { - NodeId = 1049, - EditorAlias = Constants.PropertyEditors.Aliases.MediaPicker, - DbType = "Ntext", - Configuration = "{\"multiPicker\":1}", - }); - } - if (_database.Exists(1050)) { _database.Insert(Constants.DatabaseSchema.Tables.DataType, "pk", false, diff --git a/src/Umbraco.Infrastructure/Models/GridValue.cs b/src/Umbraco.Infrastructure/Models/GridValue.cs deleted file mode 100644 index e8eca571ce..0000000000 --- a/src/Umbraco.Infrastructure/Models/GridValue.cs +++ /dev/null @@ -1,88 +0,0 @@ -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; - -namespace Umbraco.Cms.Core.Models; - -// TODO: Make a property value converter for this! - -/// -/// A model representing the value saved for the grid -/// -[Obsolete("The grid is obsolete, will be removed in V13")] -public class GridValue -{ - [JsonProperty("name")] - public string? Name { get; set; } - - [JsonProperty("sections")] - public IEnumerable Sections { get; set; } = null!; - - public class GridSection - { - [JsonProperty("grid")] - public string? Grid { get; set; } // TODO: what is this? - - [JsonProperty("rows")] - public IEnumerable Rows { get; set; } = null!; - } - - public class GridRow - { - [JsonProperty("name")] - public string? Name { get; set; } - - [JsonProperty("id")] - public Guid Id { get; set; } - - [JsonProperty("areas")] - public IEnumerable Areas { get; set; } = null!; - - [JsonProperty("styles")] - public JToken? Styles { get; set; } - - [JsonProperty("config")] - public JToken? Config { get; set; } - } - - [Obsolete("The grid is obsolete, will be removed in V13")] - public class GridArea - { - [JsonProperty("grid")] - public string? Grid { get; set; } // TODO: what is this? - - [JsonProperty("controls")] - public IEnumerable Controls { get; set; } = null!; - - [JsonProperty("styles")] - public JToken? Styles { get; set; } - - [JsonProperty("config")] - public JToken? Config { get; set; } - } - - [Obsolete("The grid is obsolete, will be removed in V13")] - public class GridControl - { - [JsonProperty("value")] - public JToken? Value { get; set; } - - [JsonProperty("editor")] - public GridEditor Editor { get; set; } = null!; - - [JsonProperty("styles")] - public JToken? Styles { get; set; } - - [JsonProperty("config")] - public JToken? Config { get; set; } - } - - [Obsolete("The grid is obsolete, will be removed in V13")] - public class GridEditor - { - [JsonProperty("alias")] - public string Alias { get; set; } = null!; - - [JsonProperty("view")] - public string? View { get; set; } - } -} diff --git a/src/Umbraco.Infrastructure/PropertyEditors/BlockGridPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/BlockGridPropertyEditor.cs index 361b8c86f0..8b6ef4862c 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/BlockGridPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/BlockGridPropertyEditor.cs @@ -1,9 +1,7 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using Microsoft.Extensions.DependencyInjection; using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Web.Common.DependencyInjection; namespace Umbraco.Cms.Core.PropertyEditors; @@ -12,33 +10,17 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// [DataEditor( Constants.PropertyEditors.Aliases.BlockGrid, - "Block Grid", - "blockgrid", - ValueType = ValueTypes.Json, - Group = Constants.PropertyEditors.Groups.RichContent, - Icon = "icon-layout")] + ValueType = ValueTypes.Json)] public class BlockGridPropertyEditor : BlockGridPropertyEditorBase { private readonly IIOHelper _ioHelper; - [Obsolete("Use non-obsoleted ctor. This will be removed in Umbraco 13.")] - public BlockGridPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IIOHelper ioHelper) - : this(dataValueEditorFactory, ioHelper, StaticServiceProvider.Instance.GetRequiredService()) - { - - } - - public BlockGridPropertyEditor( IDataValueEditorFactory dataValueEditorFactory, IIOHelper ioHelper, IBlockValuePropertyIndexValueFactory blockValuePropertyIndexValueFactory) : base(dataValueEditorFactory, blockValuePropertyIndexValueFactory) - { - _ioHelper = ioHelper; - } + => _ioHelper = ioHelper; #region Pre Value Editor diff --git a/src/Umbraco.Infrastructure/PropertyEditors/BlockListConfigurationEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/BlockListConfigurationEditor.cs index 431b006b1e..d20cffa933 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/BlockListConfigurationEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/BlockListConfigurationEditor.cs @@ -8,8 +8,8 @@ namespace Umbraco.Cms.Core.PropertyEditors; internal class BlockListConfigurationEditor : ConfigurationEditor { - public BlockListConfigurationEditor(IIOHelper ioHelper, IEditorConfigurationParser editorConfigurationParser) - : base(ioHelper, editorConfigurationParser) + public BlockListConfigurationEditor(IIOHelper ioHelper) + : base(ioHelper) { } } diff --git a/src/Umbraco.Infrastructure/PropertyEditors/BlockListPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/BlockListPropertyEditor.cs index b3855609b0..dbb8407907 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/BlockListPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/BlockListPropertyEditor.cs @@ -1,11 +1,8 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.Serialization; -using Umbraco.Cms.Core.Services; namespace Umbraco.Cms.Core.PropertyEditors; @@ -14,47 +11,25 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// [DataEditor( Constants.PropertyEditors.Aliases.BlockList, - "Block List", - "blocklist", ValueType = ValueTypes.Json, - Group = Constants.PropertyEditors.Groups.Lists, - Icon = "icon-thumbnail-list", ValueEditorIsReusable = false)] public class BlockListPropertyEditor : BlockEditorPropertyEditor { - private readonly IEditorConfigurationParser _editorConfigurationParser; private readonly IIOHelper _ioHelper; - - [Obsolete("Use non-obsoleted ctor. This will be removed in Umbraco 15.")] public BlockListPropertyEditor( IDataValueEditorFactory dataValueEditorFactory, PropertyEditorCollection propertyEditors, IIOHelper ioHelper, - IEditorConfigurationParser editorConfigurationParser, - IBlockValuePropertyIndexValueFactory blockValuePropertyIndexValueFactory) - : this(dataValueEditorFactory, propertyEditors, ioHelper, editorConfigurationParser, blockValuePropertyIndexValueFactory, StaticServiceProvider.Instance.GetRequiredService()) - { - - } - - public BlockListPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - PropertyEditorCollection propertyEditors, - IIOHelper ioHelper, - IEditorConfigurationParser editorConfigurationParser, IBlockValuePropertyIndexValueFactory blockValuePropertyIndexValueFactory, IJsonSerializer jsonSerializer) : base(dataValueEditorFactory, propertyEditors, blockValuePropertyIndexValueFactory, jsonSerializer) - { - _ioHelper = ioHelper; - _editorConfigurationParser = editorConfigurationParser; - } + => _ioHelper = ioHelper; #region Pre Value Editor protected override IConfigurationEditor CreateConfigurationEditor() => - new BlockListConfigurationEditor(_ioHelper, _editorConfigurationParser); + new BlockListConfigurationEditor(_ioHelper); #endregion } diff --git a/src/Umbraco.Infrastructure/PropertyEditors/CheckBoxListPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/CheckBoxListPropertyEditor.cs index a257be0c26..cd06118041 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/CheckBoxListPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/CheckBoxListPropertyEditor.cs @@ -1,11 +1,9 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.Models; -using Umbraco.Cms.Core.Services; +using Umbraco.Cms.Core.Serialization; namespace Umbraco.Cms.Core.PropertyEditors; @@ -14,46 +12,26 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// [DataEditor( Constants.PropertyEditors.Aliases.CheckBoxList, - "Checkbox list", - "checkboxlist", - Icon = "icon-bulleted-list", - Group = Constants.PropertyEditors.Groups.Lists, ValueEditorIsReusable = true)] public class CheckBoxListPropertyEditor : DataEditor { - private readonly IEditorConfigurationParser _editorConfigurationParser; private readonly IIOHelper _ioHelper; - private readonly ILocalizedTextService _textService; - - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] - public CheckBoxListPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - ILocalizedTextService textService, - IIOHelper ioHelper) - : this(dataValueEditorFactory, textService, ioHelper, StaticServiceProvider.Instance.GetRequiredService()) - { - } + private readonly IConfigurationEditorJsonSerializer _configurationEditorJsonSerializer; /// /// The constructor will setup the property editor based on the attribute if one is found /// - public CheckBoxListPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - ILocalizedTextService textService, - IIOHelper ioHelper, - IEditorConfigurationParser editorConfigurationParser) + public CheckBoxListPropertyEditor(IDataValueEditorFactory dataValueEditorFactory, IIOHelper ioHelper, IConfigurationEditorJsonSerializer configurationEditorJsonSerializer) : base(dataValueEditorFactory) { - _textService = textService; _ioHelper = ioHelper; - _editorConfigurationParser = editorConfigurationParser; + _configurationEditorJsonSerializer = configurationEditorJsonSerializer; SupportsReadOnly = true; } /// protected override IConfigurationEditor CreateConfigurationEditor() => - new ValueListConfigurationEditor(_textService, _ioHelper, _editorConfigurationParser); + new ValueListConfigurationEditor(_ioHelper, _configurationEditorJsonSerializer); /// protected override IDataValueEditor CreateValueEditor() => diff --git a/src/Umbraco.Infrastructure/PropertyEditors/ColorPickerConfigurationEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/ColorPickerConfigurationEditor.cs index edc727014c..6a3f73e9bb 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/ColorPickerConfigurationEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/ColorPickerConfigurationEditor.cs @@ -2,66 +2,58 @@ // See LICENSE for more details. using System.ComponentModel.DataAnnotations; -using System.Runtime.Serialization; using System.Text.RegularExpressions; -using Newtonsoft.Json.Linq; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.Serialization; -using Umbraco.Cms.Core.Services; using Umbraco.Extensions; namespace Umbraco.Cms.Core.PropertyEditors; internal class ColorPickerConfigurationEditor : ConfigurationEditor { - private readonly IJsonSerializer _jsonSerializer; - - public ColorPickerConfigurationEditor(IIOHelper ioHelper, IJsonSerializer jsonSerializer, - IEditorConfigurationParser editorConfigurationParser) - : base(ioHelper, editorConfigurationParser) + public ColorPickerConfigurationEditor(IIOHelper ioHelper, IConfigurationEditorJsonSerializer configurationEditorJsonSerializer) + : base(ioHelper) { - _jsonSerializer = jsonSerializer; ConfigurationField items = Fields.First(x => x.Key == "items"); - - // customize the items field - items.View = "views/propertyeditors/colorpicker/colorpicker.prevalues.html"; - items.Description = "Add, remove or sort colors"; - items.Name = "Colors"; - items.Validators.Add(new ColorListValidator()); + items.Validators.Add(new ColorListValidator(configurationEditorJsonSerializer)); } internal class ColorListValidator : IValueValidator { + private readonly IConfigurationEditorJsonSerializer _configurationEditorJsonSerializer; + + public ColorListValidator(IConfigurationEditorJsonSerializer configurationEditorJsonSerializer) + => _configurationEditorJsonSerializer = configurationEditorJsonSerializer; + public IEnumerable Validate(object? value, string? valueType, object? dataTypeConfiguration) { - if (!(value is JArray json)) + var stringValue = value?.ToString(); + if (stringValue.IsNullOrWhiteSpace()) { yield break; } - // validate each item which is a json object - for (var index = 0; index < json.Count; index++) + ColorPickerConfiguration.ColorPickerItem[]? items = null; + try { - JToken i = json[index]; - if (!(i is JObject jItem) || jItem["value"] == null) - { - continue; - } + items = _configurationEditorJsonSerializer.Deserialize(stringValue); + } + catch + { + // swallow and report error below + } - // NOTE: we will be removing empty values when persisting so no need to validate - var asString = jItem["value"]?.ToString(); - if (asString.IsNullOrWhiteSpace()) - { - continue; - } + if (items is null) + { + yield return new ValidationResult($"The configuration value {stringValue} is not a valid color picker configuration", new[] { "items" }); + yield break; + } - if (Regex.IsMatch(asString!, "^([0-9a-f]{3}|[0-9a-f]{6})$", RegexOptions.IgnoreCase) == false) + foreach (ColorPickerConfiguration.ColorPickerItem item in items) + { + if (Regex.IsMatch(item.Value, "^([0-9a-f]{3}|[0-9a-f]{6})$", RegexOptions.IgnoreCase) == false) { - yield return new ValidationResult("The value " + asString + " is not a valid hex color", new[] - { - // we'll make the server field the index number of the value so it can be wired up to the view - "item_" + index.ToInvariantString(), - }); + yield return new ValidationResult($"The value {item.Value} is not a valid hex color", new[] { "items" }); } } } diff --git a/src/Umbraco.Infrastructure/PropertyEditors/ColorPickerPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/ColorPickerPropertyEditor.cs index 56f43c0762..9b5fce4a2f 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/ColorPickerPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/ColorPickerPropertyEditor.cs @@ -1,47 +1,24 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.Serialization; -using Umbraco.Cms.Core.Services; namespace Umbraco.Cms.Core.PropertyEditors; [DataEditor( Constants.PropertyEditors.Aliases.ColorPicker, - "Color Picker", - "colorpicker", - Icon = "icon-colorpicker", - Group = Constants.PropertyEditors.Groups.Pickers, ValueEditorIsReusable = true)] public class ColorPickerPropertyEditor : DataEditor { - private readonly IEditorConfigurationParser _editorConfigurationParser; private readonly IIOHelper _ioHelper; - private readonly IJsonSerializer _jsonSerializer; + private readonly IConfigurationEditorJsonSerializer _configurationEditorJsonSerializer; - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] - public ColorPickerPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IIOHelper ioHelper, - IJsonSerializer jsonSerializer) - : this(dataValueEditorFactory, ioHelper, jsonSerializer, StaticServiceProvider.Instance.GetRequiredService()) - { - } - - public ColorPickerPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IIOHelper ioHelper, - IJsonSerializer jsonSerializer, - IEditorConfigurationParser editorConfigurationParser) + public ColorPickerPropertyEditor(IDataValueEditorFactory dataValueEditorFactory, IIOHelper ioHelper, IConfigurationEditorJsonSerializer configurationEditorJsonSerializer) : base(dataValueEditorFactory) { _ioHelper = ioHelper; - _jsonSerializer = jsonSerializer; - _editorConfigurationParser = editorConfigurationParser; + _configurationEditorJsonSerializer = configurationEditorJsonSerializer; SupportsReadOnly = true; } @@ -50,5 +27,5 @@ public class ColorPickerPropertyEditor : DataEditor /// protected override IConfigurationEditor CreateConfigurationEditor() => - new ColorPickerConfigurationEditor(_ioHelper, _jsonSerializer, _editorConfigurationParser); + new ColorPickerConfigurationEditor(_ioHelper, _configurationEditorJsonSerializer); } diff --git a/src/Umbraco.Infrastructure/PropertyEditors/DateTimePropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/DateTimePropertyEditor.cs index 23fd9d11d7..3c1e7cd683 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/DateTimePropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/DateTimePropertyEditor.cs @@ -1,12 +1,8 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; -using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.PropertyEditors.Validators; -using Umbraco.Cms.Core.Services; namespace Umbraco.Cms.Core.PropertyEditors; @@ -15,31 +11,16 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// [DataEditor( Constants.PropertyEditors.Aliases.DateTime, - "Date/Time", - "datepicker", ValueType = ValueTypes.DateTime, - Icon = "icon-time", ValueEditorIsReusable = true)] public class DateTimePropertyEditor : DataEditor { - private readonly IEditorConfigurationParser _editorConfigurationParser; - private readonly IIOHelper _ioHelper; - - public DateTimePropertyEditor(IDataValueEditorFactory dataValueEditorFactory, IIOHelper ioHelper) - : this(dataValueEditorFactory, ioHelper, StaticServiceProvider.Instance.GetRequiredService()) - { - } - /// /// Initializes a new instance of the class. /// - public DateTimePropertyEditor(IDataValueEditorFactory dataValueEditorFactory, IIOHelper ioHelper, IEditorConfigurationParser editorConfigurationParser) + public DateTimePropertyEditor(IDataValueEditorFactory dataValueEditorFactory) : base(dataValueEditorFactory) - { - _ioHelper = ioHelper; - _editorConfigurationParser = editorConfigurationParser; - SupportsReadOnly = true; - } + => SupportsReadOnly = true; /// protected override IDataValueEditor CreateValueEditor() @@ -48,8 +29,4 @@ public class DateTimePropertyEditor : DataEditor editor.Validators.Add(new DateTimeValidator()); return editor; } - - /// - protected override IConfigurationEditor CreateConfigurationEditor() => - new DateTimeConfigurationEditor(_ioHelper, _editorConfigurationParser); } diff --git a/src/Umbraco.Infrastructure/PropertyEditors/DropDownFlexibleConfigurationEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/DropDownFlexibleConfigurationEditor.cs index e09bf5556a..ef6e6c7808 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/DropDownFlexibleConfigurationEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/DropDownFlexibleConfigurationEditor.cs @@ -2,20 +2,16 @@ // See LICENSE for more details. using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Services; -using Umbraco.Extensions; +using Umbraco.Cms.Core.Serialization; namespace Umbraco.Cms.Core.PropertyEditors; internal class DropDownFlexibleConfigurationEditor : ConfigurationEditor { - public DropDownFlexibleConfigurationEditor(ILocalizedTextService textService, IIOHelper ioHelper, IEditorConfigurationParser editorConfigurationParser) - : base(ioHelper, editorConfigurationParser) + public DropDownFlexibleConfigurationEditor(IIOHelper ioHelper, IConfigurationEditorJsonSerializer configurationEditorJsonSerializer) + : base(ioHelper) { ConfigurationField items = Fields.First(x => x.Key == "items"); - - // customize the items field - items.Name = textService.Localize("editdatatype", "addPrevalue"); - items.Validators.Add(new ValueListUniqueValueValidator()); + items.Validators.Add(new ValueListUniqueValueValidator(configurationEditorJsonSerializer)); } } diff --git a/src/Umbraco.Infrastructure/PropertyEditors/DropDownFlexiblePropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/DropDownFlexiblePropertyEditor.cs index 6d523ae612..9b5886f685 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/DropDownFlexiblePropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/DropDownFlexiblePropertyEditor.cs @@ -1,51 +1,25 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.Models; -using Umbraco.Cms.Core.Services; +using Umbraco.Cms.Core.Serialization; namespace Umbraco.Cms.Core.PropertyEditors; [DataEditor( Constants.PropertyEditors.Aliases.DropDownListFlexible, - "Dropdown", - "dropdownFlexible", - Group = Constants.PropertyEditors.Groups.Lists, - Icon = "icon-indent", ValueEditorIsReusable = true)] public class DropDownFlexiblePropertyEditor : DataEditor { - private readonly IEditorConfigurationParser _editorConfigurationParser; private readonly IIOHelper _ioHelper; - private readonly ILocalizedTextService _textService; + private readonly IConfigurationEditorJsonSerializer _configurationEditorJsonSerializer; - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] - public DropDownFlexiblePropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - ILocalizedTextService textService, - IIOHelper ioHelper) - : this( - dataValueEditorFactory, - textService, - ioHelper, - StaticServiceProvider.Instance.GetRequiredService()) - { - } - - public DropDownFlexiblePropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - ILocalizedTextService textService, - IIOHelper ioHelper, - IEditorConfigurationParser editorConfigurationParser) + public DropDownFlexiblePropertyEditor(IDataValueEditorFactory dataValueEditorFactory, IIOHelper ioHelper, IConfigurationEditorJsonSerializer configurationEditorJsonSerializer) : base(dataValueEditorFactory) { - _textService = textService; _ioHelper = ioHelper; - _editorConfigurationParser = editorConfigurationParser; + _configurationEditorJsonSerializer = configurationEditorJsonSerializer; SupportsReadOnly = true; } @@ -53,5 +27,5 @@ public class DropDownFlexiblePropertyEditor : DataEditor DataValueEditorFactory.Create(Attribute!); protected override IConfigurationEditor CreateConfigurationEditor() => - new DropDownFlexibleConfigurationEditor(_textService, _ioHelper, _editorConfigurationParser); + new DropDownFlexibleConfigurationEditor(_ioHelper, _configurationEditorJsonSerializer); } diff --git a/src/Umbraco.Infrastructure/PropertyEditors/EmailAddressPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/EmailAddressPropertyEditor.cs index 6edcb61f4d..cbd7ef3a8c 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/EmailAddressPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/EmailAddressPropertyEditor.cs @@ -1,7 +1,6 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.PropertyEditors.Validators; @@ -9,26 +8,15 @@ namespace Umbraco.Cms.Core.PropertyEditors; [DataEditor( Constants.PropertyEditors.Aliases.EmailAddress, - EditorType.PropertyValue | EditorType.MacroParameter, - "Email address", - "email", - Icon = "icon-message", ValueEditorIsReusable = true)] public class EmailAddressPropertyEditor : DataEditor { - private readonly IIOHelper _ioHelper; - /// /// The constructor will setup the property editor based on the attribute if one is found /// - public EmailAddressPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IIOHelper ioHelper) + public EmailAddressPropertyEditor(IDataValueEditorFactory dataValueEditorFactory) : base(dataValueEditorFactory) - { - _ioHelper = ioHelper; - SupportsReadOnly = true; - } + => SupportsReadOnly = true; protected override IDataValueEditor CreateValueEditor() { @@ -38,7 +26,4 @@ public class EmailAddressPropertyEditor : DataEditor editor.Validators.Add(new EmailValidator()); return editor; } - - protected override IConfigurationEditor CreateConfigurationEditor() => - new EmailAddressConfigurationEditor(_ioHelper); } diff --git a/src/Umbraco.Infrastructure/PropertyEditors/FileUploadPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/FileUploadPropertyEditor.cs index f1b6c482c4..1d1b5a633f 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/FileUploadPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/FileUploadPropertyEditor.cs @@ -2,10 +2,8 @@ // See LICENSE for more details. using System.Diagnostics.CodeAnalysis; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Umbraco.Cms.Core.Configuration.Models; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.Media; @@ -18,10 +16,6 @@ namespace Umbraco.Cms.Core.PropertyEditors; [DataEditor( Constants.PropertyEditors.Aliases.UploadField, - "File upload", - "fileupload", - Group = Constants.PropertyEditors.Groups.Media, - Icon = "icon-download-alt", ValueEditorIsReusable = true)] public class FileUploadPropertyEditor : DataEditor, IMediaUrlGenerator, INotificationHandler, INotificationHandler, @@ -30,52 +24,24 @@ public class FileUploadPropertyEditor : DataEditor, IMediaUrlGenerator, { private readonly IContentService _contentService; private readonly IOptionsMonitor _contentSettings; - private readonly IEditorConfigurationParser _editorConfigurationParser; private readonly IIOHelper _ioHelper; - private readonly ILocalizedTextService _localizedTextService; private readonly MediaFileManager _mediaFileManager; private readonly UploadAutoFillProperties _uploadAutoFillProperties; - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] public FileUploadPropertyEditor( IDataValueEditorFactory dataValueEditorFactory, MediaFileManager mediaFileManager, IOptionsMonitor contentSettings, - ILocalizedTextService localizedTextService, UploadAutoFillProperties uploadAutoFillProperties, IContentService contentService, IIOHelper ioHelper) - : this( - dataValueEditorFactory, - mediaFileManager, - contentSettings, - localizedTextService, - uploadAutoFillProperties, - contentService, - ioHelper, - StaticServiceProvider.Instance.GetRequiredService()) - { - } - - public FileUploadPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - MediaFileManager mediaFileManager, - IOptionsMonitor contentSettings, - ILocalizedTextService localizedTextService, - UploadAutoFillProperties uploadAutoFillProperties, - IContentService contentService, - IIOHelper ioHelper, - IEditorConfigurationParser editorConfigurationParser) : base(dataValueEditorFactory) { _mediaFileManager = mediaFileManager ?? throw new ArgumentNullException(nameof(mediaFileManager)); _contentSettings = contentSettings; - _localizedTextService = localizedTextService; _uploadAutoFillProperties = uploadAutoFillProperties; _contentService = contentService; _ioHelper = ioHelper; - _editorConfigurationParser = editorConfigurationParser; SupportsReadOnly = true; } @@ -142,7 +108,7 @@ public class FileUploadPropertyEditor : DataEditor, IMediaUrlGenerator, /// protected override IConfigurationEditor CreateConfigurationEditor() => - new FileUploadConfigurationEditor(_ioHelper, _editorConfigurationParser); + new FileUploadConfigurationEditor(_ioHelper); /// /// Creates the corresponding property value editor. diff --git a/src/Umbraco.Infrastructure/PropertyEditors/GridConfiguration.cs b/src/Umbraco.Infrastructure/PropertyEditors/GridConfiguration.cs deleted file mode 100644 index ea72156a12..0000000000 --- a/src/Umbraco.Infrastructure/PropertyEditors/GridConfiguration.cs +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using Newtonsoft.Json.Linq; - -namespace Umbraco.Cms.Core.PropertyEditors; - -/// -/// Represents the configuration for the grid value editor. -/// -[Obsolete("The grid is obsolete, will be removed in V13")] -public class GridConfiguration : IIgnoreUserStartNodesConfig -{ - // TODO: Make these strongly typed, for now this works though - [ConfigurationField("items", "Grid", "views/propertyeditors/grid/grid.prevalues.html", Description = "Grid configuration")] - public JObject? Items { get; set; } - - // TODO: Make these strongly typed, for now this works though - [ConfigurationField("rte", "Rich text editor", "views/propertyeditors/rte/rte.prevalues.html", Description = "Rich text editor configuration", HideLabel = true)] - public JObject? Rte { get; set; } - - [ConfigurationField("mediaParentId", "Image Upload Folder", "mediafolderpicker", Description = "Choose the upload location of pasted images")] - public GuidUdi? MediaParentId { get; set; } - - [ConfigurationField( - Constants.DataTypes.ReservedPreValueKeys.IgnoreUserStartNodes, - "Ignore User Start Nodes", - "boolean", - Description = "Selecting this option allows a user to choose nodes that they normally don't have access to.")] - public bool IgnoreUserStartNodes { get; set; } -} diff --git a/src/Umbraco.Infrastructure/PropertyEditors/GridConfigurationEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/GridConfigurationEditor.cs deleted file mode 100644 index d2b8fba42d..0000000000 --- a/src/Umbraco.Infrastructure/PropertyEditors/GridConfigurationEditor.cs +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using System.ComponentModel.DataAnnotations; -using Microsoft.Extensions.DependencyInjection; -using Newtonsoft.Json; -using Umbraco.Cms.Core.DependencyInjection; -using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Services; - -namespace Umbraco.Cms.Core.PropertyEditors; - -/// -/// Represents the configuration editor for the grid value editor. -/// -[Obsolete("The grid is obsolete, will be removed in V13")] -public class GridConfigurationEditor : ConfigurationEditor -{ - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] - public GridConfigurationEditor(IIOHelper ioHelper) - : this(ioHelper, StaticServiceProvider.Instance.GetRequiredService()) - { - } - - public GridConfigurationEditor(IIOHelper ioHelper, IEditorConfigurationParser editorConfigurationParser) - : base(ioHelper, editorConfigurationParser) - { - ConfigurationField items = Fields.First(x => x.Key == "items"); - - items.Validators.Add(new GridValidator()); - } -} - -[Obsolete("The grid is obsolete, will be removed in V13")] -public class GridValidator : IValueValidator -{ - public IEnumerable Validate(object? rawValue, string? valueType, object? dataTypeConfiguration) - { - if (rawValue == null) - { - yield break; - } - - GridEditorModel? model = JsonConvert.DeserializeObject(rawValue.ToString()!); - - if (model?.Templates?.Any(t => t.Sections?.Sum(s => s.Grid) > model.Columns) ?? false) - { - yield return new ValidationResult( - "Columns must be at least the same size as the largest layout", - new[] { nameof(model.Columns) }); - } - } -} - -[Obsolete("The grid is obsolete, will be removed in V13")] -public class GridEditorModel -{ - public GridEditorTemplateModel[]? Templates { get; set; } - - public int Columns { get; set; } -} - -[Obsolete("The grid is obsolete, will be removed in V13")] -public class GridEditorTemplateModel -{ - public GridEditorSectionModel[]? Sections { get; set; } -} - -[Obsolete("The grid is obsolete, will be removed in V13")] -public class GridEditorSectionModel -{ - public int Grid { get; set; } -} diff --git a/src/Umbraco.Infrastructure/PropertyEditors/GridPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/GridPropertyEditor.cs deleted file mode 100644 index 1259fb2b3d..0000000000 --- a/src/Umbraco.Infrastructure/PropertyEditors/GridPropertyEditor.cs +++ /dev/null @@ -1,337 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using Microsoft.Extensions.DependencyInjection; -using Newtonsoft.Json; -using Umbraco.Cms.Core.DependencyInjection; -using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Media; -using Umbraco.Cms.Core.Models; -using Umbraco.Cms.Core.Models.Editors; -using Umbraco.Cms.Core.Security; -using Umbraco.Cms.Core.Serialization; -using Umbraco.Cms.Core.Services; -using Umbraco.Cms.Core.Strings; -using Umbraco.Cms.Core.Templates; -using Umbraco.Cms.Infrastructure.Templates; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.PropertyEditors -{ - /// - /// Represents a grid property and parameter editor. - /// - [DataEditor( - Constants.PropertyEditors.Aliases.Grid, - "Grid layout (legacy)", - "grid", - HideLabel = true, - ValueType = ValueTypes.Json, - Icon = "icon-layout", - Group = Constants.PropertyEditors.Groups.RichContent, - ValueEditorIsReusable = false, - IsDeprecated = true)] - [Obsolete("The grid is obsolete, will be removed in V13")] - public class GridPropertyEditor : DataEditor - { - private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor; - private readonly IIOHelper _ioHelper; - private readonly HtmlImageSourceParser _imageSourceParser; - private readonly RichTextEditorPastedImages _pastedImages; - private readonly HtmlLocalLinkParser _localLinkParser; - private readonly IImageUrlGenerator _imageUrlGenerator; - private readonly IHtmlMacroParameterParser _macroParameterParser; - private readonly IEditorConfigurationParser _editorConfigurationParser; - - // Scheduled for removal in v12 - [Obsolete("Use the constructor which takes an IHtmlMacroParameterParser instead")] - public GridPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IBackOfficeSecurityAccessor backOfficeSecurityAccessor, - HtmlImageSourceParser imageSourceParser, - RichTextEditorPastedImages pastedImages, - HtmlLocalLinkParser localLinkParser, - IIOHelper ioHelper, - IImageUrlGenerator imageUrlGenerator, - IHtmlMacroParameterParser macroParameterParser) - : this( - dataValueEditorFactory, - backOfficeSecurityAccessor, - imageSourceParser, - pastedImages, - localLinkParser, - ioHelper, - imageUrlGenerator, - macroParameterParser, - StaticServiceProvider.Instance.GetRequiredService()) - { - } - - [Obsolete("Use the constructor which takes an IHtmlMacroParameterParser instead")] - public GridPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IBackOfficeSecurityAccessor backOfficeSecurityAccessor, - HtmlImageSourceParser imageSourceParser, - RichTextEditorPastedImages pastedImages, - HtmlLocalLinkParser localLinkParser, - IIOHelper ioHelper, - IImageUrlGenerator imageUrlGenerator) - : this( - dataValueEditorFactory, - backOfficeSecurityAccessor, - imageSourceParser, - pastedImages, - localLinkParser, - ioHelper, - imageUrlGenerator, - StaticServiceProvider.Instance.GetRequiredService(), - StaticServiceProvider.Instance.GetRequiredService()) - { - } - - public GridPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IBackOfficeSecurityAccessor backOfficeSecurityAccessor, - HtmlImageSourceParser imageSourceParser, - RichTextEditorPastedImages pastedImages, - HtmlLocalLinkParser localLinkParser, - IIOHelper ioHelper, - IImageUrlGenerator imageUrlGenerator, - IHtmlMacroParameterParser macroParameterParser, - IEditorConfigurationParser editorConfigurationParser) - : base(dataValueEditorFactory) - { - _backOfficeSecurityAccessor = backOfficeSecurityAccessor; - _ioHelper = ioHelper; - _imageSourceParser = imageSourceParser; - _pastedImages = pastedImages; - _localLinkParser = localLinkParser; - _imageUrlGenerator = imageUrlGenerator; - _macroParameterParser = macroParameterParser; - _editorConfigurationParser = editorConfigurationParser; - SupportsReadOnly = true; - } - - public override IPropertyIndexValueFactory PropertyIndexValueFactory => new GridPropertyIndexValueFactory(); - - /// - /// Overridden to ensure that the value is validated - /// - /// - protected override IDataValueEditor CreateValueEditor() => DataValueEditorFactory.Create(Attribute!); - - protected override IConfigurationEditor CreateConfigurationEditor() => new GridConfigurationEditor(_ioHelper, _editorConfigurationParser); - - internal class GridPropertyValueEditor : DataValueEditor, IDataValueReference - { - private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor; - private readonly HtmlImageSourceParser _imageSourceParser; - private readonly RichTextEditorPastedImages _pastedImages; - private readonly RichTextPropertyEditor.RichTextPropertyValueEditor _richTextPropertyValueEditor; - private readonly MediaPickerPropertyEditor.MediaPickerPropertyValueEditor _mediaPickerPropertyValueEditor; - private readonly IImageUrlGenerator _imageUrlGenerator; - private readonly IHtmlMacroParameterParser _macroParameterParser; - - public GridPropertyValueEditor( - IDataValueEditorFactory dataValueEditorFactory, - DataEditorAttribute attribute, - IBackOfficeSecurityAccessor backOfficeSecurityAccessor, - ILocalizedTextService localizedTextService, - HtmlImageSourceParser imageSourceParser, - RichTextEditorPastedImages pastedImages, - IShortStringHelper shortStringHelper, - IImageUrlGenerator imageUrlGenerator, - IJsonSerializer jsonSerializer, - IIOHelper ioHelper, - IHtmlMacroParameterParser macroParameterParser) - : base(localizedTextService, shortStringHelper, jsonSerializer, ioHelper, attribute) - { - _backOfficeSecurityAccessor = backOfficeSecurityAccessor; - _imageSourceParser = imageSourceParser; - _pastedImages = pastedImages; - _richTextPropertyValueEditor = - dataValueEditorFactory.Create(attribute); - _mediaPickerPropertyValueEditor = - dataValueEditorFactory.Create(attribute); - _imageUrlGenerator = imageUrlGenerator; - _macroParameterParser = macroParameterParser; - } - - [Obsolete("Use the constructor which takes an IHtmlMacroParameterParser instead")] - public GridPropertyValueEditor( - IDataValueEditorFactory dataValueEditorFactory, - DataEditorAttribute attribute, - IBackOfficeSecurityAccessor backOfficeSecurityAccessor, - ILocalizedTextService localizedTextService, - HtmlImageSourceParser imageSourceParser, - RichTextEditorPastedImages pastedImages, - IShortStringHelper shortStringHelper, - IImageUrlGenerator imageUrlGenerator, - IJsonSerializer jsonSerializer, - IIOHelper ioHelper) - : this( - dataValueEditorFactory, - attribute, - backOfficeSecurityAccessor, - localizedTextService, - imageSourceParser, - pastedImages, - shortStringHelper, - imageUrlGenerator, - jsonSerializer, - ioHelper, - StaticServiceProvider.Instance.GetRequiredService()) - { - } - - /// - /// Format the data for persistence - /// This to ensure if a RTE is used in a Grid cell/control that we parse it for tmp stored images - /// to persist to the media library when we go to persist this to the DB - /// - /// - /// - /// - public override object? FromEditor(ContentPropertyData editorValue, object? currentValue) - { - if (editorValue.Value == null) - { - return null; - } - - // editorValue.Value is a JSON string of the grid - var rawJson = editorValue.Value.ToString(); - if (rawJson.IsNullOrWhiteSpace()) - { - return null; - } - - var config = editorValue.DataTypeConfiguration as GridConfiguration; - GuidUdi? mediaParent = config?.MediaParentId; - Guid mediaParentId = mediaParent?.Guid ?? Guid.Empty; - - GridValue? grid = DeserializeGridValue(rawJson!, out var rtes, out _, out _); - - var userId = _backOfficeSecurityAccessor?.BackOfficeSecurity?.CurrentUser?.Id ?? Constants.Security.SuperUserId; - - if (rtes is null) - { - return JsonConvert.SerializeObject(grid, Formatting.None); - } - // Process the rte values - foreach (GridValue.GridControl rte in rtes) - { - // Parse the HTML - var html = rte.Value?.ToString(); - - if (html is not null) - { - var parseAndSaveBase64Images = _pastedImages.FindAndPersistPastedTempImages( - html, mediaParentId, userId, _imageUrlGenerator); - var parseAndSavedTempImages = _pastedImages.FindAndPersistPastedTempImages(parseAndSaveBase64Images, mediaParentId, userId, _imageUrlGenerator); - var editorValueWithMediaUrlsRemoved = _imageSourceParser.RemoveImageSources(parseAndSavedTempImages); - rte.Value = editorValueWithMediaUrlsRemoved; - } - } - - // Convert back to raw JSON for persisting - return JsonConvert.SerializeObject(grid, Formatting.None); - } - - /// - /// Ensures that the rich text editor values are processed within the grid - /// - /// - /// - /// - /// - public override object? ToEditor(IProperty property, string? culture = null, string? segment = null) - { - var val = property.GetValue(culture, segment)?.ToString(); - if (val.IsNullOrWhiteSpace()) - { - return string.Empty; - } - - GridValue? grid = DeserializeGridValue(val!, out var rtes, out _, out _); - - if (rtes is null) - { - return null; - } - //process the rte values - foreach (GridValue.GridControl rte in rtes.ToList()) - { - var html = rte.Value?.ToString(); - - if (html is not null) - { - var propertyValueWithMediaResolved = _imageSourceParser.EnsureImageSources(html); - rte.Value = propertyValueWithMediaResolved; - } - - } - - return grid; - } - - private GridValue? DeserializeGridValue(string rawJson, out IEnumerable? richTextValues, out IEnumerable? mediaValues, out IEnumerable? macroValues) - { - GridValue? grid = JsonConvert.DeserializeObject(rawJson); - - // Find all controls that use the RTE editor - GridValue.GridControl[]? controls = grid?.Sections.SelectMany(x => x.Rows.SelectMany(r => r.Areas).SelectMany(a => a.Controls)).ToArray(); - richTextValues = controls?.Where(x => x.Editor.Alias.ToLowerInvariant() == "rte"); - mediaValues = controls?.Where(x => x.Editor.Alias.ToLowerInvariant() == "media"); - - // Find all the macros - macroValues = controls?.Where(x => x.Editor.Alias.ToLowerInvariant() == "macro"); - - return grid; - } - - /// - /// Resolve references from values - /// - /// - /// - public IEnumerable GetReferences(object? value) - { - var rawJson = value == null ? string.Empty : value is string str ? str : value.ToString(); - - if (rawJson.IsNullOrWhiteSpace()) - { - yield break; - } - - DeserializeGridValue(rawJson!, out IEnumerable? richTextEditorValues, out IEnumerable? mediaValues, out IEnumerable? macroValues); - - if (richTextEditorValues is not null) - { - foreach (UmbracoEntityReference umbracoEntityReference in richTextEditorValues.SelectMany(x => - _richTextPropertyValueEditor.GetReferences(x.Value))) - { - yield return umbracoEntityReference; - } - } - - if (mediaValues is not null) - { - foreach (UmbracoEntityReference umbracoEntityReference in mediaValues.Where(x => x.Value?.HasValues ?? false) - .SelectMany(x => _mediaPickerPropertyValueEditor.GetReferences(x.Value!["udi"]))) - { - yield return umbracoEntityReference; - } - } - - if (macroValues is not null) - { - foreach (UmbracoEntityReference umbracoEntityReference in _macroParameterParser.FindUmbracoEntityReferencesFromGridControlMacros(macroValues)) - { - yield return umbracoEntityReference; - } - } - } - } - } -} diff --git a/src/Umbraco.Infrastructure/PropertyEditors/GridPropertyIndexValueFactory.cs b/src/Umbraco.Infrastructure/PropertyEditors/GridPropertyIndexValueFactory.cs deleted file mode 100644 index c190a7b6a8..0000000000 --- a/src/Umbraco.Infrastructure/PropertyEditors/GridPropertyIndexValueFactory.cs +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using System.Text; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using Umbraco.Cms.Core.Models; -using Umbraco.Cms.Core.Xml; -using Umbraco.Cms.Infrastructure.Examine; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.PropertyEditors -{ - /// - /// Parses the grid value into indexable values - /// - [Obsolete("The grid is obsolete, will be removed in V13")] - public class GridPropertyIndexValueFactory : IPropertyIndexValueFactory - { - public IEnumerable>> GetIndexValues(IProperty property, string? culture, string? segment, bool published, IEnumerable availableCultures) - { - var result = new List>>(); - - var val = property.GetValue(culture, segment, published); - - //if there is a value, it's a string and it's detected as json - if (val is string rawVal && rawVal.DetectIsJson()) - { - try - { - GridValue? gridVal = JsonConvert.DeserializeObject(rawVal); - - //get all values and put them into a single field (using JsonPath) - var sb = new StringBuilder(); - foreach (GridValue.GridRow row in gridVal!.Sections.SelectMany(x => x.Rows)) - { - var rowName = row.Name; - - foreach (GridValue.GridControl control in row.Areas.SelectMany(x => x.Controls)) - { - JToken? controlVal = control.Value; - - if (controlVal?.Type == JTokenType.String) - { - var str = controlVal.Value(); - str = XmlHelper.CouldItBeXml(str) ? str!.StripHtml() : str; - sb.Append(str); - sb.Append(" "); - - //add the row name as an individual field - result.Add(new KeyValuePair>($"{property.Alias}.{rowName}", new[] { str })); - } - else if (controlVal is JContainer jc) - { - foreach (JToken s in jc.Descendants().Where(t => t.Type == JTokenType.String)) - { - sb.Append(s.Value()); - sb.Append(" "); - } - } - } - } - - //First save the raw value to a raw field - result.Add(new KeyValuePair>($"{UmbracoExamineFieldNames.RawFieldPrefix}{property.Alias}", new[] { rawVal })); - - if (sb.Length > 0) - { - //index the property with the combined/cleaned value - result.Add(new KeyValuePair>(property.Alias, new[] { sb.ToString() })); - } - } - catch (InvalidCastException) - { - //swallow...on purpose, there's a chance that this isn't the json format we are looking for - // and we don't want that to affect the website. - } - catch (JsonException) - { - //swallow...on purpose, there's a chance that this isn't json and we don't want that to affect - // the website. - } - catch (ArgumentException) - { - //swallow on purpose to prevent this error: - // Can not add Newtonsoft.Json.Linq.JValue to Newtonsoft.Json.Linq.JObject. - } - } - - return result; - } - - [Obsolete("Use the overload that specifies availableCultures, scheduled for removal in v14")] - public IEnumerable>> GetIndexValues(IProperty property, string? culture, string? segment, bool published) - => GetIndexValues(property, culture, segment, published, Enumerable.Empty()); - } -} diff --git a/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperConfiguration.cs b/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperConfiguration.cs index 0f844b94b8..9df860a314 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperConfiguration.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperConfiguration.cs @@ -1,7 +1,6 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using System.Runtime.Serialization; using Umbraco.Cms.Core.PropertyEditors.ValueConverters; namespace Umbraco.Cms.Core.PropertyEditors; @@ -11,19 +10,15 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// public class ImageCropperConfiguration { - [ConfigurationField("crops", "Define crops", "views/propertyeditors/imagecropper/imagecropper.prevalues.html")] + [ConfigurationField("crops")] public Crop[]? Crops { get; set; } - [DataContract] public class Crop { - [DataMember(Name = "alias")] public string Alias { get; set; } = null!; - [DataMember(Name = "width")] public int Width { get; set; } - [DataMember(Name = "height")] public int Height { get; set; } } } diff --git a/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperConfigurationEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperConfigurationEditor.cs index 12c5f6a91d..27c52f48b0 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperConfigurationEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperConfigurationEditor.cs @@ -2,7 +2,6 @@ // See LICENSE for more details. using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Services; namespace Umbraco.Cms.Core.PropertyEditors; @@ -11,8 +10,8 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// internal class ImageCropperConfigurationEditor : ConfigurationEditor { - public ImageCropperConfigurationEditor(IIOHelper ioHelper, IEditorConfigurationParser editorConfigurationParser) - : base(ioHelper, editorConfigurationParser) + public ImageCropperConfigurationEditor(IIOHelper ioHelper) + : base(ioHelper) { } diff --git a/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperPropertyEditor.cs index 0be7cd4f72..73fd599ef6 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/ImageCropperPropertyEditor.cs @@ -1,13 +1,11 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Umbraco.Cms.Core.Configuration.Models; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.Media; @@ -23,12 +21,7 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// [DataEditor( Constants.PropertyEditors.Aliases.ImageCropper, - "Image Cropper", - "imagecropper", ValueType = ValueTypes.Json, - HideLabel = false, - Group = Constants.PropertyEditors.Groups.Media, - Icon = "icon-crop", ValueEditorIsReusable = true)] public class ImageCropperPropertyEditor : DataEditor, IMediaUrlGenerator, INotificationHandler, INotificationHandler, @@ -37,37 +30,11 @@ public class ImageCropperPropertyEditor : DataEditor, IMediaUrlGenerator, { private readonly UploadAutoFillProperties _autoFillProperties; private readonly IContentService _contentService; - private readonly IDataTypeService _dataTypeService; - private readonly IEditorConfigurationParser _editorConfigurationParser; private readonly IIOHelper _ioHelper; private readonly ILogger _logger; private readonly MediaFileManager _mediaFileManager; private ContentSettings _contentSettings; - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] - public ImageCropperPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - ILoggerFactory loggerFactory, - MediaFileManager mediaFileManager, - IOptionsMonitor contentSettings, - IDataTypeService dataTypeService, - IIOHelper ioHelper, - UploadAutoFillProperties uploadAutoFillProperties, - IContentService contentService) - : this( - dataValueEditorFactory, - loggerFactory, - mediaFileManager, - contentSettings, - dataTypeService, - ioHelper, - uploadAutoFillProperties, - contentService, - StaticServiceProvider.Instance.GetRequiredService()) - { - } - /// /// Initializes a new instance of the class. /// @@ -76,21 +43,17 @@ public class ImageCropperPropertyEditor : DataEditor, IMediaUrlGenerator, ILoggerFactory loggerFactory, MediaFileManager mediaFileManager, IOptionsMonitor contentSettings, - IDataTypeService dataTypeService, IIOHelper ioHelper, UploadAutoFillProperties uploadAutoFillProperties, - IContentService contentService, - IEditorConfigurationParser editorConfigurationParser) + IContentService contentService) : base(dataValueEditorFactory) { _mediaFileManager = mediaFileManager ?? throw new ArgumentNullException(nameof(mediaFileManager)); _contentSettings = contentSettings.CurrentValue ?? throw new ArgumentNullException(nameof(contentSettings)); - _dataTypeService = dataTypeService ?? throw new ArgumentNullException(nameof(dataTypeService)); _ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper)); _autoFillProperties = uploadAutoFillProperties ?? throw new ArgumentNullException(nameof(uploadAutoFillProperties)); _contentService = contentService; - _editorConfigurationParser = editorConfigurationParser; _logger = loggerFactory.CreateLogger(); contentSettings.OnChange(x => _contentSettings = x); @@ -177,7 +140,7 @@ public class ImageCropperPropertyEditor : DataEditor, IMediaUrlGenerator, /// /// The corresponding preValue editor. protected override IConfigurationEditor CreateConfigurationEditor() => - new ImageCropperConfigurationEditor(_ioHelper, _editorConfigurationParser); + new ImageCropperConfigurationEditor(_ioHelper); /// /// Gets a value indicating whether a property is an image cropper field. diff --git a/src/Umbraco.Infrastructure/PropertyEditors/ListViewPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/ListViewPropertyEditor.cs index 1dc07119d3..f9dfe88e02 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/ListViewPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/ListViewPropertyEditor.cs @@ -1,10 +1,7 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Services; namespace Umbraco.Cms.Core.PropertyEditors; @@ -13,38 +10,19 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// [DataEditor( Constants.PropertyEditors.Aliases.ListView, - "List view", - "listview", - HideLabel = true, - Group = Constants.PropertyEditors.Groups.Lists, - Icon = Constants.Icons.ListView, ValueEditorIsReusable = true)] public class ListViewPropertyEditor : DataEditor { - private readonly IEditorConfigurationParser _editorConfigurationParser; private readonly IIOHelper _iioHelper; - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] - public ListViewPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IIOHelper iioHelper) - : this(dataValueEditorFactory, iioHelper, StaticServiceProvider.Instance.GetRequiredService()) - { - } - - public ListViewPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IIOHelper iioHelper, - IEditorConfigurationParser editorConfigurationParser) + public ListViewPropertyEditor(IDataValueEditorFactory dataValueEditorFactory, IIOHelper iioHelper) : base(dataValueEditorFactory) { _iioHelper = iioHelper; - _editorConfigurationParser = editorConfigurationParser; SupportsReadOnly = true; } /// protected override IConfigurationEditor CreateConfigurationEditor() => - new ListViewConfigurationEditor(_iioHelper, _editorConfigurationParser); + new ListViewConfigurationEditor(_iioHelper); } diff --git a/src/Umbraco.Infrastructure/PropertyEditors/MediaPicker3PropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/MediaPicker3PropertyEditor.cs index 146e4b8949..29a31f6205 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/MediaPicker3PropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/MediaPicker3PropertyEditor.cs @@ -1,6 +1,4 @@ using System.Text.Json.Nodes; -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models.Editors; @@ -20,41 +18,19 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// [DataEditor( Constants.PropertyEditors.Aliases.MediaPicker3, - EditorType.PropertyValue, - "Media Picker", - "mediapicker3", ValueType = ValueTypes.Json, - Group = Constants.PropertyEditors.Groups.Media, - Icon = Constants.Icons.MediaImage, ValueEditorIsReusable = true)] public class MediaPicker3PropertyEditor : DataEditor { - private readonly IEditorConfigurationParser _editorConfigurationParser; private readonly IIOHelper _ioHelper; - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] - public MediaPicker3PropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IIOHelper ioHelper, - EditorType type = EditorType.PropertyValue) - : this(dataValueEditorFactory, ioHelper, - StaticServiceProvider.Instance.GetRequiredService(), type) - { - } - /// /// Initializes a new instance of the class. /// - public MediaPicker3PropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IIOHelper ioHelper, - IEditorConfigurationParser editorConfigurationParser, - EditorType type = EditorType.PropertyValue) - : base(dataValueEditorFactory, type) + public MediaPicker3PropertyEditor(IDataValueEditorFactory dataValueEditorFactory, IIOHelper ioHelper) + : base(dataValueEditorFactory) { _ioHelper = ioHelper; - _editorConfigurationParser = editorConfigurationParser; SupportsReadOnly = true; } @@ -62,7 +38,7 @@ public class MediaPicker3PropertyEditor : DataEditor /// protected override IConfigurationEditor CreateConfigurationEditor() => - new MediaPicker3ConfigurationEditor(_ioHelper, _editorConfigurationParser); + new MediaPicker3ConfigurationEditor(_ioHelper); /// protected override IDataValueEditor CreateValueEditor() => @@ -81,7 +57,6 @@ public class MediaPicker3PropertyEditor : DataEditor private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor; public MediaPicker3PropertyValueEditor( - ILocalizedTextService localizedTextService, IShortStringHelper shortStringHelper, IJsonSerializer jsonSerializer, IIOHelper ioHelper, @@ -92,7 +67,7 @@ public class MediaPicker3PropertyEditor : DataEditor ITemporaryFileService temporaryFileService, IScopeProvider scopeProvider, IBackOfficeSecurityAccessor backOfficeSecurityAccessor) - : base(localizedTextService, shortStringHelper, jsonSerializer, ioHelper, attribute) + : base(shortStringHelper, jsonSerializer, ioHelper, attribute) { _jsonSerializer = jsonSerializer; _dataTypeService = dataTypeService; diff --git a/src/Umbraco.Infrastructure/PropertyEditors/MediaPickerPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/MediaPickerPropertyEditor.cs deleted file mode 100644 index 2eed35c8aa..0000000000 --- a/src/Umbraco.Infrastructure/PropertyEditors/MediaPickerPropertyEditor.cs +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; -using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Models; -using Umbraco.Cms.Core.Models.Editors; -using Umbraco.Cms.Core.Serialization; -using Umbraco.Cms.Core.Services; -using Umbraco.Cms.Core.Strings; - -namespace Umbraco.Cms.Core.PropertyEditors; - -/// -/// Represents a media picker property editor. -/// -/// -/// Named "(legacy)" as it's best to use the NEW Media Picker aka MediaPicker3 -/// -[DataEditor( - Constants.PropertyEditors.Aliases.MediaPicker, - EditorType.PropertyValue | EditorType.MacroParameter, - "Media Picker (legacy)", - "mediapicker", - ValueType = ValueTypes.Text, - Group = Constants.PropertyEditors.Groups.Media, - Icon = Constants.Icons.MediaImage, - IsDeprecated = false, - ValueEditorIsReusable = true)] -[Obsolete("Please use the MediaPicker3 instead, will be removed in V13")] -public class MediaPickerPropertyEditor : DataEditor -{ - private readonly IEditorConfigurationParser _editorConfigurationParser; - private readonly IIOHelper _ioHelper; - - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] - public MediaPickerPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IIOHelper ioHelper) - : this(dataValueEditorFactory, ioHelper, StaticServiceProvider.Instance.GetRequiredService()) - { - } - - /// - /// Initializes a new instance of the class. - /// - public MediaPickerPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IIOHelper ioHelper, - IEditorConfigurationParser editorConfigurationParser) - : base(dataValueEditorFactory) - { - _ioHelper = ioHelper; - _editorConfigurationParser = editorConfigurationParser; - SupportsReadOnly = true; - } - - /// - protected override IConfigurationEditor CreateConfigurationEditor() => - new MediaPickerConfigurationEditor(_ioHelper, _editorConfigurationParser); - - protected override IDataValueEditor CreateValueEditor() => - DataValueEditorFactory.Create(Attribute!); - - public class MediaPickerPropertyValueEditor : DataValueEditor, IDataValueReference - { - public MediaPickerPropertyValueEditor( - ILocalizedTextService localizedTextService, - IShortStringHelper shortStringHelper, - IJsonSerializer jsonSerializer, - IIOHelper ioHelper, - DataEditorAttribute attribute) - : base(localizedTextService, shortStringHelper, jsonSerializer, ioHelper, attribute) => - SupportsReadOnly = true; - - public IEnumerable GetReferences(object? value) - { - var asString = value is string str ? str : value?.ToString(); - - if (string.IsNullOrEmpty(asString)) - { - yield break; - } - - foreach (var udiStr in asString.Split(',')) - { - if (UdiParser.TryParse(udiStr, out Udi? udi)) - { - yield return new UmbracoEntityReference(udi); - } - } - } - } -} diff --git a/src/Umbraco.Infrastructure/PropertyEditors/MultiNodeTreePickerPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/MultiNodeTreePickerPropertyEditor.cs index 6d9a7b801b..17890fdb53 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/MultiNodeTreePickerPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/MultiNodeTreePickerPropertyEditor.cs @@ -1,13 +1,10 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models.Editors; using Umbraco.Cms.Core.Serialization; -using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Strings; using Umbraco.Extensions; @@ -15,39 +12,21 @@ namespace Umbraco.Cms.Core.PropertyEditors; [DataEditor( Constants.PropertyEditors.Aliases.MultiNodeTreePicker, - "Multinode Treepicker", - "contentpicker", ValueType = ValueTypes.Text, - Group = Constants.PropertyEditors.Groups.Pickers, - Icon = "icon-page-add", ValueEditorIsReusable = true)] public class MultiNodeTreePickerPropertyEditor : DataEditor { - private readonly IEditorConfigurationParser _editorConfigurationParser; private readonly IIOHelper _ioHelper; - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] - public MultiNodeTreePickerPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IIOHelper ioHelper) - : this(dataValueEditorFactory, ioHelper, StaticServiceProvider.Instance.GetRequiredService()) - { - } - - public MultiNodeTreePickerPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IIOHelper ioHelper, - IEditorConfigurationParser editorConfigurationParser) + public MultiNodeTreePickerPropertyEditor(IDataValueEditorFactory dataValueEditorFactory, IIOHelper ioHelper) : base(dataValueEditorFactory) { _ioHelper = ioHelper; - _editorConfigurationParser = editorConfigurationParser; SupportsReadOnly = true; } protected override IConfigurationEditor CreateConfigurationEditor() => - new MultiNodePickerConfigurationEditor(_ioHelper, _editorConfigurationParser); + new MultiNodePickerConfigurationEditor(_ioHelper); protected override IDataValueEditor CreateValueEditor() => DataValueEditorFactory.Create(Attribute!); @@ -55,12 +34,11 @@ public class MultiNodeTreePickerPropertyEditor : DataEditor public class MultiNodeTreePickerPropertyValueEditor : DataValueEditor, IDataValueReference { public MultiNodeTreePickerPropertyValueEditor( - ILocalizedTextService localizedTextService, IShortStringHelper shortStringHelper, IJsonSerializer jsonSerializer, IIOHelper ioHelper, DataEditorAttribute attribute) - : base(localizedTextService, shortStringHelper, jsonSerializer, ioHelper, attribute) + : base(shortStringHelper, jsonSerializer, ioHelper, attribute) { } diff --git a/src/Umbraco.Infrastructure/PropertyEditors/MultiUrlPickerPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/MultiUrlPickerPropertyEditor.cs index e65fed679a..921d57d68b 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/MultiUrlPickerPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/MultiUrlPickerPropertyEditor.cs @@ -1,52 +1,30 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.Models; -using Umbraco.Cms.Core.Services; namespace Umbraco.Cms.Core.PropertyEditors; [DataEditor( Constants.PropertyEditors.Aliases.MultiUrlPicker, - EditorType.PropertyValue, - "Multi URL Picker", - "multiurlpicker", ValueType = ValueTypes.Json, - Group = Constants.PropertyEditors.Groups.Pickers, - Icon = "icon-link", ValueEditorIsReusable = true)] public class MultiUrlPickerPropertyEditor : DataEditor { - private readonly IEditorConfigurationParser _editorConfigurationParser; private readonly IIOHelper _ioHelper; - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] - public MultiUrlPickerPropertyEditor( - IIOHelper ioHelper, - IDataValueEditorFactory dataValueEditorFactory) - : this(ioHelper, dataValueEditorFactory, StaticServiceProvider.Instance.GetRequiredService()) - { - } - - public MultiUrlPickerPropertyEditor( - IIOHelper ioHelper, - IDataValueEditorFactory dataValueEditorFactory, - IEditorConfigurationParser editorConfigurationParser) + public MultiUrlPickerPropertyEditor(IIOHelper ioHelper, IDataValueEditorFactory dataValueEditorFactory) : base(dataValueEditorFactory) { _ioHelper = ioHelper; - _editorConfigurationParser = editorConfigurationParser; SupportsReadOnly = true; } public override IPropertyIndexValueFactory PropertyIndexValueFactory { get; } = new NoopPropertyIndexValueFactory(); protected override IConfigurationEditor CreateConfigurationEditor() => - new MultiUrlPickerConfigurationEditor(_ioHelper, _editorConfigurationParser); + new MultiUrlPickerConfigurationEditor(_ioHelper); protected override IDataValueEditor CreateValueEditor() => DataValueEditorFactory.Create(Attribute!); diff --git a/src/Umbraco.Infrastructure/PropertyEditors/MultipleTextStringConfigurationEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/MultipleTextStringConfigurationEditor.cs index 3b65fcb876..7b6eebff33 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/MultipleTextStringConfigurationEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/MultipleTextStringConfigurationEditor.cs @@ -3,9 +3,6 @@ using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.PropertyEditors.Validators; -using Umbraco.Cms.Core.Serialization; -using Umbraco.Cms.Core.Services; -using Umbraco.Extensions; namespace Umbraco.Cms.Core.PropertyEditors; @@ -14,26 +11,18 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// internal class MultipleTextStringConfigurationEditor : ConfigurationEditor { - public MultipleTextStringConfigurationEditor( - IIOHelper ioHelper, - IEditorConfigurationParser editorConfigurationParser) - : base(ioHelper, editorConfigurationParser) + public MultipleTextStringConfigurationEditor(IIOHelper ioHelper) + : base(ioHelper) { Fields.Add(new ConfigurationField(new IntegerValidator()) { - Description = "Enter the minimum amount of text boxes to be displayed", Key = "min", - View = "requiredfield", - Name = "Minimum", PropertyName = nameof(MultipleTextStringConfiguration.Min), }); Fields.Add(new ConfigurationField(new IntegerValidator()) { - Description = "Enter the maximum amount of text boxes to be displayed, enter 0 for unlimited", Key = "max", - View = "requiredfield", - Name = "Maximum", PropertyName = nameof(MultipleTextStringConfiguration.Max), }); } diff --git a/src/Umbraco.Infrastructure/PropertyEditors/MultipleTextStringPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/MultipleTextStringPropertyEditor.cs index cc3c5bece7..7b86cb1bb4 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/MultipleTextStringPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/MultipleTextStringPropertyEditor.cs @@ -8,7 +8,6 @@ using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models.Editors; using Umbraco.Cms.Core.PropertyEditors.Validators; using Umbraco.Cms.Core.Serialization; -using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Strings; namespace Umbraco.Cms.Core.PropertyEditors; @@ -18,28 +17,19 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// [DataEditor( Constants.PropertyEditors.Aliases.MultipleTextstring, - "Repeatable textstrings", - "multipletextbox", ValueType = ValueTypes.Text, - Group = Constants.PropertyEditors.Groups.Lists, - Icon = "icon-ordered-list", ValueEditorIsReusable = true)] public class MultipleTextStringPropertyEditor : DataEditor { - private readonly IEditorConfigurationParser _editorConfigurationParser; private readonly IIOHelper _ioHelper; /// /// Initializes a new instance of the class. /// - public MultipleTextStringPropertyEditor( - IIOHelper ioHelper, - IDataValueEditorFactory dataValueEditorFactory, - IEditorConfigurationParser editorConfigurationParser) + public MultipleTextStringPropertyEditor(IIOHelper ioHelper, IDataValueEditorFactory dataValueEditorFactory) : base(dataValueEditorFactory) { _ioHelper = ioHelper; - _editorConfigurationParser = editorConfigurationParser; SupportsReadOnly = true; } @@ -49,7 +39,7 @@ public class MultipleTextStringPropertyEditor : DataEditor /// protected override IConfigurationEditor CreateConfigurationEditor() => - new MultipleTextStringConfigurationEditor(_ioHelper, _editorConfigurationParser); + new MultipleTextStringConfigurationEditor(_ioHelper); /// /// Custom value editor so we can format the value for the editor and the database diff --git a/src/Umbraco.Infrastructure/PropertyEditors/NestedContentPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/NestedContentPropertyEditor.cs deleted file mode 100644 index f71212d6f9..0000000000 --- a/src/Umbraco.Infrastructure/PropertyEditors/NestedContentPropertyEditor.cs +++ /dev/null @@ -1,575 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using Umbraco.Cms.Core.DependencyInjection; -using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Models; -using Umbraco.Cms.Core.Models.Editors; -using Umbraco.Cms.Core.Serialization; -using Umbraco.Cms.Core.Services; -using Umbraco.Cms.Core.Strings; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.PropertyEditors; - -/// -/// Represents a nested content property editor. -/// -[DataEditor( - Constants.PropertyEditors.Aliases.NestedContent, - "Nested Content (legacy)", - "nestedcontent", - ValueType = ValueTypes.Json, - Group = Constants.PropertyEditors.Groups.Lists, - Icon = "icon-thumbnail-list", - ValueEditorIsReusable = false, - IsDeprecated = true)] -[Obsolete("Nested content is obsolete, will be removed in Umbraco 14")] -public class NestedContentPropertyEditor : DataEditor -{ - public const string ContentTypeAliasPropertyKey = "ncContentTypeAlias"; - private readonly IEditorConfigurationParser _editorConfigurationParser; - private readonly IIOHelper _ioHelper; - private readonly INestedContentPropertyIndexValueFactory _nestedContentPropertyIndexValueFactory; - - [Obsolete("Use non-obsoleted ctor. This will be removed in Umbraco 14.")] - public NestedContentPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IIOHelper ioHelper) - : this(dataValueEditorFactory, ioHelper, StaticServiceProvider.Instance.GetRequiredService()) - { - } - - [Obsolete("Use non-obsoleted ctor. This will be removed in Umbraco 14.")] - public NestedContentPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IIOHelper ioHelper, - IEditorConfigurationParser editorConfigurationParser) - : this( - dataValueEditorFactory, - ioHelper, - editorConfigurationParser, - StaticServiceProvider.Instance.GetRequiredService()) - { - - } - - public NestedContentPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IIOHelper ioHelper, - IEditorConfigurationParser editorConfigurationParser, - INestedContentPropertyIndexValueFactory nestedContentPropertyIndexValueFactory) - : base(dataValueEditorFactory) - { - _ioHelper = ioHelper; - _editorConfigurationParser = editorConfigurationParser; - _nestedContentPropertyIndexValueFactory = nestedContentPropertyIndexValueFactory; - SupportsReadOnly = true; - } - - public override IPropertyIndexValueFactory PropertyIndexValueFactory => _nestedContentPropertyIndexValueFactory; - - #region Pre Value Editor - - protected override IConfigurationEditor CreateConfigurationEditor() => - new NestedContentConfigurationEditor(_ioHelper, _editorConfigurationParser); - - #endregion - - private static bool IsSystemPropertyKey(string propKey) => - propKey == "name" || propKey == "key" || propKey == ContentTypeAliasPropertyKey; - - #region Value Editor - - protected override IDataValueEditor CreateValueEditor() - => DataValueEditorFactory.Create(Attribute!); - - internal class NestedContentPropertyValueEditor : DataValueEditor, IDataValueReference, IDataValueTags - { - private readonly IDataTypeService _dataTypeService; - private readonly PropertyEditorCollection _propertyEditors; - private readonly DataValueReferenceFactoryCollection _dataValueReferenceFactories; - private readonly ILogger _logger; - private readonly NestedContentValues _nestedContentValues; - - public NestedContentPropertyValueEditor( - IDataTypeService dataTypeService, - ILocalizedTextService localizedTextService, - IContentTypeService contentTypeService, - IShortStringHelper shortStringHelper, - DataEditorAttribute attribute, - PropertyEditorCollection propertyEditors, - DataValueReferenceFactoryCollection dataValueReferenceFactories, - ILogger logger, - IJsonSerializer jsonSerializer, - IIOHelper ioHelper, - IPropertyValidationService propertyValidationService) - : base(localizedTextService, shortStringHelper, jsonSerializer, ioHelper, attribute) - { - _dataTypeService = dataTypeService; - _propertyEditors = propertyEditors; - _dataValueReferenceFactories = dataValueReferenceFactories; - _logger = logger; - _nestedContentValues = new NestedContentValues(contentTypeService); - - Validators.Add(new NestedContentValidator(propertyValidationService, _nestedContentValues, contentTypeService)); - } - - /// - public override object? ConfigurationObject - { - get => base.ConfigurationObject; - set - { - if (value == null) - { - throw new ArgumentNullException(nameof(value)); - } - - if (!(value is NestedContentConfiguration configuration)) - { - throw new ArgumentException( - $"Expected a {typeof(NestedContentConfiguration).Name} instance, but got {value.GetType().Name}.", - nameof(value)); - } - - base.ConfigurationObject = value; - - HideLabel = configuration.HideLabel.TryConvertTo().Result; - } - } - - /// - public IEnumerable GetReferences(object? value) - { - // Group by property editor alias to avoid duplicate lookups and optimize value parsing - foreach (var valuesByPropertyEditorAlias in GetAllPropertyValues(value).GroupBy(x => x.PropertyType.PropertyEditorAlias, x => x.Value)) - { - if (!_propertyEditors.TryGet(valuesByPropertyEditorAlias.Key, out IDataEditor? dataEditor)) - { - continue; - } - - // Use distinct values to avoid duplicate parsing of the same value - foreach (UmbracoEntityReference reference in _dataValueReferenceFactories.GetReferences(dataEditor, valuesByPropertyEditorAlias.Distinct())) - { - yield return reference; - } - } - } - - /// - public IEnumerable GetTags(object? value, object? dataTypeConfiguration, int? languageId) - { - foreach (NestedContentValues.NestedContentPropertyValue propertyValue in GetAllPropertyValues(value)) - { - if (!_propertyEditors.TryGet(propertyValue.PropertyType.PropertyEditorAlias, out IDataEditor? dataEditor) || - dataEditor.GetValueEditor() is not IDataValueTags dataValueTags) - { - continue; - } - - object? configurationObject = _dataTypeService.GetDataType(propertyValue.PropertyType.DataTypeKey)?.ConfigurationObject; - foreach (ITag tag in dataValueTags.GetTags(propertyValue.Value, configurationObject, languageId)) - { - yield return tag; - } - } - } - - private IEnumerable GetAllPropertyValues(object? value) - => _nestedContentValues.GetPropertyValues(value).SelectMany(x => x.PropertyValues.Values); - - #region DB to String - - public override string ConvertDbToString(IPropertyType propertyType, object? propertyValue) - { - IReadOnlyList rows = - _nestedContentValues.GetPropertyValues(propertyValue); - - if (rows.Count == 0) - { - return string.Empty; - } - - foreach (NestedContentValues.NestedContentRowValue row in rows.ToList()) - { - foreach (KeyValuePair prop in row.PropertyValues - .ToList()) - { - try - { - // convert the value, and store the converted value - IDataEditor? propEditor = _propertyEditors[prop.Value.PropertyType.PropertyEditorAlias]; - if (propEditor == null) - { - continue; - } - - var tempConfig = _dataTypeService.GetDataType(prop.Value.PropertyType.DataTypeId) - ?.ConfigurationObject; - IDataValueEditor valEditor = propEditor.GetValueEditor(tempConfig); - var convValue = valEditor.ConvertDbToString(prop.Value.PropertyType, prop.Value.Value); - - // update the raw value since this is what will get serialized out - row.RawPropertyValues[prop.Key] = convValue; - } - catch (InvalidOperationException ex) - { - // deal with weird situations by ignoring them (no comment) - row.RawPropertyValues.Remove(prop.Key); - _logger.LogWarning(ex, "ConvertDbToString removed property value {PropertyKey} in row {RowId} for property type {PropertyTypeAlias}", prop.Key, row.Id, propertyType.Alias); - } - } - } - - return JsonConvert.SerializeObject(rows, Formatting.None).ToXmlString(); - } - - #endregion - - #region Convert database // editor - - // note: there is NO variant support here - - /// - /// Ensure that sub-editor values are translated through their ToEditor methods - /// - /// - /// - /// - /// - public override object ToEditor(IProperty property, string? culture = null, string? segment = null) - { - var val = property.GetValue(culture, segment); - var valEditors = new Dictionary(); - - IReadOnlyList rows = _nestedContentValues.GetPropertyValues(val); - - if (rows.Count == 0) - { - return string.Empty; - } - - foreach (NestedContentValues.NestedContentRowValue row in rows.ToList()) - { - foreach (KeyValuePair prop in row.PropertyValues - .ToList()) - { - try - { - // create a temp property with the value - // - force it to be culture invariant as NC can't handle culture variant element properties - prop.Value.PropertyType.Variations = ContentVariation.Nothing; - var tempProp = new Property(prop.Value.PropertyType); - - tempProp.SetValue(prop.Value.Value); - - // convert that temp property, and store the converted value - IDataEditor? propEditor = _propertyEditors[prop.Value.PropertyType.PropertyEditorAlias]; - if (propEditor == null) - { - // update the raw value since this is what will get serialized out - row.RawPropertyValues[prop.Key] = tempProp.GetValue()?.ToString(); - continue; - } - - var dataTypeId = prop.Value.PropertyType.DataTypeId; - if (!valEditors.TryGetValue(dataTypeId, out IDataValueEditor? valEditor)) - { - var tempConfig = _dataTypeService.GetDataType(dataTypeId)?.ConfigurationObject; - valEditor = propEditor.GetValueEditor(tempConfig); - - valEditors.Add(dataTypeId, valEditor); - } - - var convValue = valEditor.ToEditor(tempProp); - - // update the raw value since this is what will get serialized out - row.RawPropertyValues[prop.Key] = convValue == null ? null : JToken.FromObject(convValue); - } - catch (InvalidOperationException ex) - { - // deal with weird situations by ignoring them (no comment) - row.RawPropertyValues.Remove(prop.Key); - _logger.LogWarning(ex, "ToEditor removed property value {PropertyKey} in row {RowId} for property type {PropertyTypeAlias}", prop.Key, row.Id, property.PropertyType.Alias); - } - } - } - - // return the object, there's a native json converter for this so it will serialize correctly - return rows; - } - - /// - /// Ensure that sub-editor values are translated through their FromEditor methods - /// - /// - /// - /// - public override object? FromEditor(ContentPropertyData editorValue, object? currentValue) - { - if (editorValue.Value == null || string.IsNullOrWhiteSpace(editorValue.Value.ToString())) - { - return null; - } - - IReadOnlyList rows = - _nestedContentValues.GetPropertyValues(editorValue.Value); - - if (rows.Count == 0) - { - return null; - } - - foreach (NestedContentValues.NestedContentRowValue row in rows.ToList()) - { - foreach (KeyValuePair prop in row.PropertyValues - .ToList()) - { - // Fetch the property types prevalue - var propConfiguration = - _dataTypeService.GetDataType(prop.Value.PropertyType.DataTypeId)?.ConfigurationObject; - - // Lookup the property editor - IDataEditor? propEditor = _propertyEditors[prop.Value.PropertyType.PropertyEditorAlias]; - if (propEditor == null) - { - continue; - } - - // Create a fake content property data object - var contentPropData = new ContentPropertyData(prop.Value.Value, propConfiguration); - - // Get the property editor to do it's conversion - var newValue = propEditor.GetValueEditor().FromEditor(contentPropData, prop.Value.Value); - - // update the raw value since this is what will get serialized out - row.RawPropertyValues[prop.Key] = newValue == null ? null : JToken.FromObject(newValue); - } - } - - // return json - return JsonConvert.SerializeObject(rows, Formatting.None); - } - - #endregion - } - - /// - /// Validator for nested content to ensure that all nesting of editors is validated - /// - internal class NestedContentValidator : ComplexEditorValidator - { - private readonly IContentTypeService _contentTypeService; - private readonly NestedContentValues _nestedContentValues; - - public NestedContentValidator(IPropertyValidationService propertyValidationService, NestedContentValues nestedContentValues, IContentTypeService contentTypeService) - : base(propertyValidationService) - { - _nestedContentValues = nestedContentValues; - _contentTypeService = contentTypeService; - } - - protected override IEnumerable GetElementTypeValidation(object? value) - { - IReadOnlyList rows = - _nestedContentValues.GetPropertyValues(value); - if (rows.Count == 0) - { - yield break; - } - - // There is no guarantee that the client will post data for every property defined in the Element Type but we still - // need to validate that data for each property especially for things like 'required' data to work. - // Lookup all element types for all content/settings and then we can populate any empty properties. - var allElementAliases = rows.Select(x => x.ContentTypeAlias).ToList(); - - // unfortunately we need to get all content types and post filter - but they are cached so its ok, there's - // no overload to lookup by many aliases. - var allElementTypes = _contentTypeService.GetAll().Where(x => allElementAliases.Contains(x.Alias)) - .ToDictionary(x => x.Alias); - - foreach (NestedContentValues.NestedContentRowValue row in rows) - { - if (!allElementTypes.TryGetValue(row.ContentTypeAlias, out IContentType? elementType)) - { - throw new InvalidOperationException($"No element type found with alias {row.ContentTypeAlias}"); - } - - // now ensure missing properties - foreach (IPropertyType elementTypeProp in elementType.CompositionPropertyTypes) - { - if (!row.PropertyValues.ContainsKey(elementTypeProp.Alias)) - { - // set values to null - row.PropertyValues[elementTypeProp.Alias] = new NestedContentValues.NestedContentPropertyValue - { - PropertyType = elementTypeProp, - Value = null, - }; - row.RawPropertyValues[elementTypeProp.Alias] = null; - } - } - - var elementValidation = new ElementTypeValidationModel(row.ContentTypeAlias, row.Id); - foreach (KeyValuePair prop in - row.PropertyValues) - { - elementValidation.AddPropertyTypeValidation( - new PropertyTypeValidationModel(prop.Value.PropertyType, prop.Value.Value, string.Empty)); - } - - yield return elementValidation; - } - } - } - - /// - /// Used to deserialize the nested content serialized value - /// - internal class NestedContentValues - { - private readonly Lazy> _contentTypes; - - public NestedContentValues(IContentTypeService contentTypeService) => _contentTypes = - new Lazy>(() => contentTypeService.GetAll().ToDictionary(c => c.Alias)); - - private IContentType? GetElementType(NestedContentRowValue item) - { - _contentTypes.Value.TryGetValue(item.ContentTypeAlias, out IContentType? contentType); - return contentType; - } - - /// - /// Deserialize the raw json property value - /// - /// - /// - public IReadOnlyList GetPropertyValues(object? propertyValue) - { - if (propertyValue == null || string.IsNullOrWhiteSpace(propertyValue.ToString())) - { - return new List(); - } - - if (!propertyValue.ToString()!.DetectIsJson()) - { - return new List(); - } - - List? rowValues = - JsonConvert.DeserializeObject>(propertyValue.ToString()!); - - // There was a note here about checking if the result had zero items and if so it would return null, so we'll continue to do that - // The original note was: "Issue #38 - Keep recursive property lookups working" - // Which is from the original NC tracker: https://github.com/umco/umbraco-nested-content/issues/38 - // This check should be used everywhere when iterating NC prop values, instead of just the one previous place so that - // empty values don't get persisted when there is nothing, it should actually be null. - if (rowValues == null || rowValues.Count == 0) - { - return new List(); - } - - var contentTypePropertyTypes = new Dictionary>(); - - foreach (NestedContentRowValue row in rowValues) - { - IContentType? contentType = GetElementType(row); - if (contentType == null) - { - continue; - } - - // get the prop types for this content type but keep a dictionary of found ones so we don't have to keep re-looking and re-creating - // objects on each iteration. - if (!contentTypePropertyTypes.TryGetValue(contentType.Alias, out Dictionary? propertyTypes)) - { - propertyTypes = contentTypePropertyTypes[contentType.Alias] = - contentType.CompositionPropertyTypes.ToDictionary(x => x.Alias, x => x); - } - - // find any keys that are not real property types and remove them - if (row.RawPropertyValues != null) - { - foreach (KeyValuePair prop in row.RawPropertyValues.ToList()) - { - if (IsSystemPropertyKey(prop.Key)) - { - continue; - } - - // doesn't exist so remove it - if (!propertyTypes.TryGetValue(prop.Key, out IPropertyType? propType)) - { - row.RawPropertyValues.Remove(prop.Key); - } - else - { - // set the value to include the resolved property type - row.PropertyValues[prop.Key] = new NestedContentPropertyValue - { - PropertyType = propType, - Value = prop.Value, - }; - } - } - } - } - - return rowValues; - } - - /// - /// Used during deserialization to populate the property value/property type of a nested content row property - /// - internal class NestedContentPropertyValue - { - public object? Value { get; set; } - - public IPropertyType PropertyType { get; set; } = null!; - } - - /// - /// Used to deserialize a nested content row - /// - internal class NestedContentRowValue - { - [JsonProperty("key")] - public Guid Id { get; set; } - - [JsonProperty("name")] - public string? Name { get; set; } - - [JsonProperty("ncContentTypeAlias")] - public string ContentTypeAlias { get; set; } = null!; - - public IPropertyType? PropType { get; } - - /// - /// The remaining properties will be serialized to a dictionary - /// - /// - /// The JsonExtensionDataAttribute is used to put the non-typed properties into a bucket - /// http://www.newtonsoft.com/json/help/html/DeserializeExtensionData.htm - /// NestedContent serializes to string, int, whatever eg - /// "stringValue":"Some String","numericValue":125,"otherNumeric":null - /// - [JsonExtensionData] - public IDictionary RawPropertyValues { get; set; } = null!; - - /// - /// Used during deserialization to convert the raw property data into data with a property type context - /// - [JsonIgnore] - public IDictionary PropertyValues { get; set; } = - new Dictionary(); - } - } - - #endregion -} diff --git a/src/Umbraco.Infrastructure/PropertyEditors/NestedContentPropertyHandler.cs b/src/Umbraco.Infrastructure/PropertyEditors/NestedContentPropertyHandler.cs deleted file mode 100644 index c46d680273..0000000000 --- a/src/Umbraco.Infrastructure/PropertyEditors/NestedContentPropertyHandler.cs +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.PropertyEditors; - -/// -/// A handler for NestedContent used to bind to notifications -/// -[Obsolete("Nested content is obsolete, will be removed in V13")] -public class NestedContentPropertyHandler : ComplexPropertyEditorContentNotificationHandler -{ - protected override string EditorAlias => Constants.PropertyEditors.Aliases.NestedContent; - - // internal for tests - internal string CreateNestedContentKeys(string rawJson, bool onlyMissingKeys, Func? createGuid = null) - { - // used so we can test nicely - if (createGuid == null) - { - createGuid = () => Guid.NewGuid(); - } - - if (string.IsNullOrWhiteSpace(rawJson) || !rawJson.DetectIsJson()) - { - return rawJson; - } - - // Parse JSON - var complexEditorValue = JToken.Parse(rawJson); - - UpdateNestedContentKeysRecursively(complexEditorValue, onlyMissingKeys, createGuid); - - return complexEditorValue.ToString(Formatting.None); - } - - protected override string FormatPropertyValue(string rawJson, bool onlyMissingKeys) => - CreateNestedContentKeys(rawJson, onlyMissingKeys); - - private void UpdateNestedContentKeysRecursively(JToken json, bool onlyMissingKeys, Func createGuid) - { - // check if this is NC - var isNestedContent = - json.SelectTokens($"$..['{NestedContentPropertyEditor.ContentTypeAliasPropertyKey}']", false).Any(); - - // select all values (flatten) - var allProperties = json.SelectTokens("$..*").OfType().Select(x => x.Parent as JProperty).WhereNotNull() - .ToList(); - foreach (JProperty prop in allProperties) - { - if (prop.Name == NestedContentPropertyEditor.ContentTypeAliasPropertyKey) - { - // get it's sibling 'key' property - var ncKeyVal = prop.Parent?["key"] as JValue; - if ((onlyMissingKeys && ncKeyVal == null) || (!onlyMissingKeys && ncKeyVal != null)) - { - // create or replace - prop.Parent!["key"] = createGuid().ToString(); - } - } - else if (!isNestedContent || prop.Name != "key") - { - // this is an arbitrary property that could contain a nested complex editor - var propVal = prop.Value.ToString(); - - // check if this might contain a nested NC - if (!propVal.IsNullOrWhiteSpace() && propVal.DetectIsJson() && - propVal.InvariantContains(NestedContentPropertyEditor.ContentTypeAliasPropertyKey)) - { - // recurse - var parsed = JToken.Parse(propVal); - UpdateNestedContentKeysRecursively(parsed, onlyMissingKeys, createGuid); - - // set the value to the updated one - prop.Value = parsed.ToString(Formatting.None); - } - } - } - } -} diff --git a/src/Umbraco.Infrastructure/PropertyEditors/NestedContentPropertyIndexValueFactory.cs b/src/Umbraco.Infrastructure/PropertyEditors/NestedContentPropertyIndexValueFactory.cs deleted file mode 100644 index 693c21060b..0000000000 --- a/src/Umbraco.Infrastructure/PropertyEditors/NestedContentPropertyIndexValueFactory.cs +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; -using Umbraco.Cms.Core.Configuration.Models; -using Umbraco.Cms.Core.Models; -using Umbraco.Cms.Core.Serialization; -using Umbraco.Cms.Core.Services; -using Umbraco.Cms.Web.Common.DependencyInjection; - -namespace Umbraco.Cms.Core.PropertyEditors; - -internal sealed class NestedContentPropertyIndexValueFactory - : NestedPropertyIndexValueFactoryBase< - NestedContentPropertyEditor.NestedContentValues.NestedContentRowValue[], - NestedContentPropertyEditor.NestedContentValues.NestedContentRowValue>, - INestedContentPropertyIndexValueFactory -{ - private readonly IContentTypeService _contentTypeService; - - public NestedContentPropertyIndexValueFactory( - PropertyEditorCollection propertyEditorCollection, - IContentTypeService contentTypeService, - IJsonSerializer jsonSerializer, - IOptionsMonitor indexingSettings) - : base(propertyEditorCollection, jsonSerializer, indexingSettings) - { - _contentTypeService = contentTypeService; - } - - [Obsolete("Use non-obsolete constructor. This will be removed in Umbraco 14.")] - public NestedContentPropertyIndexValueFactory( - PropertyEditorCollection propertyEditorCollection, - IContentTypeService contentTypeService, - IJsonSerializer jsonSerializer) - : this(propertyEditorCollection, contentTypeService, jsonSerializer, StaticServiceProvider.Instance.GetRequiredService>()) - { - _contentTypeService = contentTypeService; - } - - protected override IContentType? GetContentTypeOfNestedItem( - NestedContentPropertyEditor.NestedContentValues.NestedContentRowValue input, IDictionary contentTypeDictionary) - => contentTypeDictionary.Values.FirstOrDefault(x=>x.Alias.Equals(input.ContentTypeAlias)); - - [Obsolete("Use non-obsolete overload, scheduled for removal in v14")] - protected override IContentType? GetContentTypeOfNestedItem( - NestedContentPropertyEditor.NestedContentValues.NestedContentRowValue input) - => _contentTypeService.Get(input.ContentTypeAlias); - - protected override IDictionary GetRawProperty( - NestedContentPropertyEditor.NestedContentValues.NestedContentRowValue nestedContentRowValue) => - nestedContentRowValue.RawPropertyValues; - - protected override IEnumerable GetDataItems( - NestedContentPropertyEditor.NestedContentValues.NestedContentRowValue[] input) => input; -} diff --git a/src/Umbraco.Infrastructure/PropertyEditors/RadioButtonsPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/RadioButtonsPropertyEditor.cs index 81efcc835d..288ab7c158 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/RadioButtonsPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/RadioButtonsPropertyEditor.cs @@ -1,10 +1,8 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Services; +using Umbraco.Cms.Core.Serialization; namespace Umbraco.Cms.Core.PropertyEditors; @@ -13,41 +11,21 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// [DataEditor( Constants.PropertyEditors.Aliases.RadioButtonList, - "Radio button list", - "radiobuttons", ValueType = ValueTypes.String, - Group = Constants.PropertyEditors.Groups.Lists, - Icon = "icon-target", ValueEditorIsReusable = true)] public class RadioButtonsPropertyEditor : DataEditor { - private readonly IEditorConfigurationParser _editorConfigurationParser; private readonly IIOHelper _ioHelper; - private readonly ILocalizedTextService _localizedTextService; - - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] - public RadioButtonsPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IIOHelper ioHelper, - ILocalizedTextService localizedTextService) - : this(dataValueEditorFactory, ioHelper, localizedTextService, StaticServiceProvider.Instance.GetRequiredService()) - { - } + private readonly IConfigurationEditorJsonSerializer _configurationEditorJsonSerializer; /// /// The constructor will setup the property editor based on the attribute if one is found /// - public RadioButtonsPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IIOHelper ioHelper, - ILocalizedTextService localizedTextService, - IEditorConfigurationParser editorConfigurationParser) + public RadioButtonsPropertyEditor(IDataValueEditorFactory dataValueEditorFactory, IIOHelper ioHelper, IConfigurationEditorJsonSerializer configurationEditorJsonSerializer) : base(dataValueEditorFactory) { _ioHelper = ioHelper; - _localizedTextService = localizedTextService; - _editorConfigurationParser = editorConfigurationParser; + _configurationEditorJsonSerializer = configurationEditorJsonSerializer; SupportsReadOnly = true; } @@ -56,5 +34,5 @@ public class RadioButtonsPropertyEditor : DataEditor /// /// protected override IConfigurationEditor CreateConfigurationEditor() => - new ValueListConfigurationEditor(_localizedTextService, _ioHelper, _editorConfigurationParser); + new ValueListConfigurationEditor(_ioHelper, _configurationEditorJsonSerializer); } diff --git a/src/Umbraco.Infrastructure/PropertyEditors/RichTextPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/RichTextPropertyEditor.cs index 39722b5314..af45287d67 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/RichTextPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/RichTextPropertyEditor.cs @@ -2,11 +2,8 @@ // See LICENSE for more details. using System.Diagnostics.CodeAnalysis; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Media; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models.Blocks; using Umbraco.Cms.Core.Models.Editors; @@ -16,7 +13,6 @@ using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Strings; using Umbraco.Cms.Core.Templates; using Umbraco.Cms.Infrastructure.Macros; -using Umbraco.Cms.Infrastructure.Templates; using Umbraco.Extensions; namespace Umbraco.Cms.Core.PropertyEditors; @@ -26,122 +22,24 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// [DataEditor( Constants.PropertyEditors.Aliases.RichText, - "Rich Text Editor", - "rte", ValueType = ValueTypes.Text, - HideLabel = false, - Group = Constants.PropertyEditors.Groups.RichContent, - Icon = "icon-browser-window", ValueEditorIsReusable = true)] public class RichTextPropertyEditor : DataEditor { - private readonly IEditorConfigurationParser _editorConfigurationParser; private readonly IIOHelper _ioHelper; private readonly IRichTextPropertyIndexValueFactory _richTextPropertyIndexValueFactory; - [Obsolete("Use the constructor which takes an IHtmlMacroParameterParser instead. Will be removed in V15.")] - public RichTextPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IBackOfficeSecurityAccessor backOfficeSecurityAccessor, - HtmlImageSourceParser imageSourceParser, - HtmlLocalLinkParser localLinkParser, - RichTextEditorPastedImages pastedImages, - IIOHelper ioHelper, - IImageUrlGenerator imageUrlGenerator, - IHtmlMacroParameterParser macroParameterParser) - : this( - dataValueEditorFactory, - backOfficeSecurityAccessor, - imageSourceParser, - localLinkParser, - pastedImages, - ioHelper, - imageUrlGenerator, - macroParameterParser, - StaticServiceProvider.Instance.GetRequiredService()) - { - } - - [Obsolete("Use the constructor which takes an IHtmlMacroParameterParser instead. Will be removed in V15.")] - public RichTextPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IBackOfficeSecurityAccessor backOfficeSecurityAccessor, - HtmlImageSourceParser imageSourceParser, - HtmlLocalLinkParser localLinkParser, - RichTextEditorPastedImages pastedImages, - IIOHelper ioHelper, - IImageUrlGenerator imageUrlGenerator) - : this( - dataValueEditorFactory, - backOfficeSecurityAccessor, - imageSourceParser, - localLinkParser, - pastedImages, - ioHelper, - imageUrlGenerator, - StaticServiceProvider.Instance.GetRequiredService(), - StaticServiceProvider.Instance.GetRequiredService()) - { - } - - [Obsolete($"Use the constructor which accepts an {nameof(IRichTextPropertyIndexValueFactory)} parameter. Will be removed in V15.")] - public RichTextPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IBackOfficeSecurityAccessor backOfficeSecurityAccessor, - HtmlImageSourceParser imageSourceParser, - HtmlLocalLinkParser localLinkParser, - RichTextEditorPastedImages pastedImages, - IIOHelper ioHelper, - IImageUrlGenerator imageUrlGenerator, - IHtmlMacroParameterParser macroParameterParser, - IEditorConfigurationParser editorConfigurationParser) - : this( - dataValueEditorFactory, - backOfficeSecurityAccessor, - imageSourceParser, - localLinkParser, - pastedImages, - ioHelper, - imageUrlGenerator, - macroParameterParser, - editorConfigurationParser, - StaticServiceProvider.Instance.GetRequiredService()) - { - } - - [Obsolete($"Use the non-obsolete constructor. Will be removed in V15.")] - public RichTextPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IBackOfficeSecurityAccessor backOfficeSecurityAccessor, - HtmlImageSourceParser imageSourceParser, - HtmlLocalLinkParser localLinkParser, - RichTextEditorPastedImages pastedImages, - IIOHelper ioHelper, - IImageUrlGenerator imageUrlGenerator, - IHtmlMacroParameterParser macroParameterParser, - IEditorConfigurationParser editorConfigurationParser, - IRichTextPropertyIndexValueFactory richTextPropertyIndexValueFactory) - : this( - dataValueEditorFactory, - editorConfigurationParser, - ioHelper, - richTextPropertyIndexValueFactory) - { - } - /// /// The constructor will setup the property editor based on the attribute if one is found. /// public RichTextPropertyEditor( IDataValueEditorFactory dataValueEditorFactory, - IEditorConfigurationParser editorConfigurationParser, IIOHelper ioHelper, IRichTextPropertyIndexValueFactory richTextPropertyIndexValueFactory) : base(dataValueEditorFactory) { _ioHelper = ioHelper; _richTextPropertyIndexValueFactory = richTextPropertyIndexValueFactory; - _editorConfigurationParser = editorConfigurationParser; SupportsReadOnly = true; } @@ -155,7 +53,7 @@ public class RichTextPropertyEditor : DataEditor DataValueEditorFactory.Create(Attribute!); protected override IConfigurationEditor CreateConfigurationEditor() => - new RichTextConfigurationEditor(_ioHelper, _editorConfigurationParser); + new RichTextConfigurationEditor(_ioHelper); /// /// A custom value editor to ensure that macro syntax is parsed when being persisted and formatted correctly for @@ -167,7 +65,6 @@ public class RichTextPropertyEditor : DataEditor private readonly IHtmlSanitizer _htmlSanitizer; private readonly HtmlImageSourceParser _imageSourceParser; private readonly HtmlLocalLinkParser _localLinkParser; - private readonly IHtmlMacroParameterParser _macroParameterParser; private readonly RichTextEditorPastedImages _pastedImages; private readonly IJsonSerializer _jsonSerializer; private readonly IContentTypeService _contentTypeService; @@ -187,7 +84,6 @@ public class RichTextPropertyEditor : DataEditor IJsonSerializer jsonSerializer, IIOHelper ioHelper, IHtmlSanitizer htmlSanitizer, - IHtmlMacroParameterParser macroParameterParser, IContentTypeService contentTypeService, IPropertyValidationService propertyValidationService, DataValueReferenceFactoryCollection dataValueReferenceFactoryCollection) @@ -198,7 +94,6 @@ public class RichTextPropertyEditor : DataEditor _localLinkParser = localLinkParser; _pastedImages = pastedImages; _htmlSanitizer = htmlSanitizer; - _macroParameterParser = macroParameterParser; _contentTypeService = contentTypeService; _jsonSerializer = jsonSerializer; _logger = logger; @@ -225,8 +120,6 @@ public class RichTextPropertyEditor : DataEditor } base.ConfigurationObject = value; - - HideLabel = configuration.HideLabel; } } @@ -255,10 +148,6 @@ public class RichTextPropertyEditor : DataEditor .WhereNotNull() .Select(udi => new UmbracoEntityReference(udi))); - // TODO: Detect Macros too ... but we can save that for a later date, right now need to do media refs - // UPDATE: We are getting the Macros in 'FindUmbracoEntityReferencesFromEmbeddedMacros' - perhaps we just return the macro Udis here too or do they need their own relationAlias? - references.AddRange(_macroParameterParser.FindUmbracoEntityReferencesFromEmbeddedMacros(richTextEditorValue.Markup)); - // references from blocks if (richTextEditorValue.Blocks is not null) { diff --git a/src/Umbraco.Infrastructure/PropertyEditors/SliderPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/SliderPropertyEditor.cs index e5005bf1bd..cd675ff73e 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/SliderPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/SliderPropertyEditor.cs @@ -2,13 +2,10 @@ // See LICENSE for more details. using System.Text.Json.Nodes; -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models.Editors; using Umbraco.Cms.Core.Serialization; -using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Strings; namespace Umbraco.Cms.Core.PropertyEditors; @@ -18,35 +15,18 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// [DataEditor( Constants.PropertyEditors.Aliases.Slider, - "Slider", - "slider", - Icon = "icon-navigation-horizontal", ValueEditorIsReusable = true)] public class SliderPropertyEditor : DataEditor { - private readonly IEditorConfigurationParser _editorConfigurationParser; private readonly IIOHelper _ioHelper; - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] - public SliderPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IIOHelper ioHelper) - : this(dataValueEditorFactory, ioHelper, StaticServiceProvider.Instance.GetRequiredService()) - { - } - /// /// Initializes a new instance of the class. /// - public SliderPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IIOHelper ioHelper, - IEditorConfigurationParser editorConfigurationParser) + public SliderPropertyEditor(IDataValueEditorFactory dataValueEditorFactory, IIOHelper ioHelper) : base(dataValueEditorFactory) { _ioHelper = ioHelper; - _editorConfigurationParser = editorConfigurationParser; SupportsReadOnly = true; } @@ -56,19 +36,18 @@ public class SliderPropertyEditor : DataEditor /// protected override IConfigurationEditor CreateConfigurationEditor() => - new SliderConfigurationEditor(_ioHelper, _editorConfigurationParser); + new SliderConfigurationEditor(_ioHelper); internal class SliderPropertyValueEditor : DataValueEditor { private readonly IJsonSerializer _jsonSerializer; public SliderPropertyValueEditor( - ILocalizedTextService localizedTextService, IShortStringHelper shortStringHelper, IJsonSerializer jsonSerializer, IIOHelper ioHelper, DataEditorAttribute attribute) - : base(localizedTextService, shortStringHelper, jsonSerializer, ioHelper, attribute) => + : base(shortStringHelper, jsonSerializer, ioHelper, attribute) => _jsonSerializer = jsonSerializer; public override object? ToEditor(IProperty property, string? culture = null, string? segment = null) diff --git a/src/Umbraco.Infrastructure/PropertyEditors/TagsPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/TagsPropertyEditor.cs index b0f4c54878..086e698f1a 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/TagsPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/TagsPropertyEditor.cs @@ -20,38 +20,20 @@ namespace Umbraco.Cms.Core.PropertyEditors; [TagsPropertyEditor] [DataEditor( Constants.PropertyEditors.Aliases.Tags, - "Tags", - "tags", - Icon = "icon-tags", ValueEditorIsReusable = true, ValueType = ValueTypes.Text)] public class TagsPropertyEditor : DataEditor { - private readonly IEditorConfigurationParser _editorConfigurationParser; private readonly ITagPropertyIndexValueFactory _tagPropertyIndexValueFactory; private readonly IIOHelper _ioHelper; - [Obsolete($"Use the constructor that does not accept {nameof(ILocalizedTextService)}. Will be removed in V15.")] - public TagsPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - ManifestValueValidatorCollection validators, - IIOHelper ioHelper, - ILocalizedTextService localizedTextService, - IEditorConfigurationParser editorConfigurationParser, - ITagPropertyIndexValueFactory tagPropertyIndexValueFactory) - : this(dataValueEditorFactory, ioHelper, editorConfigurationParser, tagPropertyIndexValueFactory) - { - } - public TagsPropertyEditor( IDataValueEditorFactory dataValueEditorFactory, IIOHelper ioHelper, - IEditorConfigurationParser editorConfigurationParser, ITagPropertyIndexValueFactory tagPropertyIndexValueFactory) : base(dataValueEditorFactory) { _ioHelper = ioHelper; - _editorConfigurationParser = editorConfigurationParser; _tagPropertyIndexValueFactory = tagPropertyIndexValueFactory; } @@ -62,7 +44,7 @@ public class TagsPropertyEditor : DataEditor DataValueEditorFactory.Create(Attribute!); protected override IConfigurationEditor CreateConfigurationEditor() => - new TagConfigurationEditor(_ioHelper, _editorConfigurationParser); + new TagConfigurationEditor(_ioHelper); internal class TagPropertyValueEditor : DataValueEditor, IDataValueTags { diff --git a/src/Umbraco.Infrastructure/PropertyEditors/TextAreaPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/TextAreaPropertyEditor.cs index 70046fa835..a5c8c8627d 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/TextAreaPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/TextAreaPropertyEditor.cs @@ -1,11 +1,8 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.Models; -using Umbraco.Cms.Core.Services; namespace Umbraco.Cms.Core.PropertyEditors; @@ -14,37 +11,19 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// [DataEditor( Constants.PropertyEditors.Aliases.TextArea, - EditorType.PropertyValue | EditorType.MacroParameter, - "Textarea", - "textarea", ValueType = ValueTypes.Text, - Icon = "icon-application-window-alt", ValueEditorIsReusable = true)] public class TextAreaPropertyEditor : DataEditor { - private readonly IEditorConfigurationParser _editorConfigurationParser; private readonly IIOHelper _ioHelper; - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] - public TextAreaPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IIOHelper ioHelper) - : this(dataValueEditorFactory, ioHelper, StaticServiceProvider.Instance.GetRequiredService()) - { - } - /// /// Initializes a new instance of the class. /// - public TextAreaPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IIOHelper ioHelper, - IEditorConfigurationParser editorConfigurationParser) + public TextAreaPropertyEditor(IDataValueEditorFactory dataValueEditorFactory, IIOHelper ioHelper) : base(dataValueEditorFactory) { _ioHelper = ioHelper; - _editorConfigurationParser = editorConfigurationParser; SupportsReadOnly = true; } @@ -54,5 +33,5 @@ public class TextAreaPropertyEditor : DataEditor /// protected override IConfigurationEditor CreateConfigurationEditor() => - new TextAreaConfigurationEditor(_ioHelper, _editorConfigurationParser); + new TextAreaConfigurationEditor(_ioHelper); } diff --git a/src/Umbraco.Infrastructure/PropertyEditors/TextboxPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/TextboxPropertyEditor.cs index fb5d9e68bc..734bd53932 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/TextboxPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/TextboxPropertyEditor.cs @@ -1,11 +1,8 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.Models; -using Umbraco.Cms.Core.Services; namespace Umbraco.Cms.Core.PropertyEditors; @@ -14,36 +11,18 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// [DataEditor( Constants.PropertyEditors.Aliases.TextBox, - EditorType.PropertyValue | EditorType.MacroParameter, - "Textbox", - "textbox", - Group = Constants.PropertyEditors.Groups.Common, ValueEditorIsReusable = true)] public class TextboxPropertyEditor : DataEditor { - private readonly IEditorConfigurationParser _editorConfigurationParser; private readonly IIOHelper _ioHelper; - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] - public TextboxPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IIOHelper ioHelper) - : this(dataValueEditorFactory, ioHelper, StaticServiceProvider.Instance.GetRequiredService()) - { - } - /// /// Initializes a new instance of the class. /// - public TextboxPropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IIOHelper ioHelper, - IEditorConfigurationParser editorConfigurationParser) + public TextboxPropertyEditor(IDataValueEditorFactory dataValueEditorFactory, IIOHelper ioHelper) : base(dataValueEditorFactory) { _ioHelper = ioHelper; - _editorConfigurationParser = editorConfigurationParser; SupportsReadOnly = true; } @@ -53,5 +32,5 @@ public class TextboxPropertyEditor : DataEditor /// protected override IConfigurationEditor CreateConfigurationEditor() => - new TextboxConfigurationEditor(_ioHelper, _editorConfigurationParser); + new TextboxConfigurationEditor(_ioHelper); } diff --git a/src/Umbraco.Infrastructure/PropertyEditors/TrueFalsePropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/TrueFalsePropertyEditor.cs index c9e7cf01ca..66d1af9c77 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/TrueFalsePropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/TrueFalsePropertyEditor.cs @@ -1,13 +1,10 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models.Editors; using Umbraco.Cms.Core.Serialization; -using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Strings; namespace Umbraco.Cms.Core.PropertyEditors; @@ -17,58 +14,29 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// [DataEditor( Constants.PropertyEditors.Aliases.Boolean, - EditorType.PropertyValue | EditorType.MacroParameter, - "Toggle", - "boolean", ValueType = ValueTypes.Integer, - Group = Constants.PropertyEditors.Groups.Common, - Icon = "icon-checkbox", ValueEditorIsReusable = true)] public class TrueFalsePropertyEditor : DataEditor { - private readonly IEditorConfigurationParser _editorConfigurationParser; - private readonly IIOHelper _ioHelper; - - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] - public TrueFalsePropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IIOHelper ioHelper) - : this(dataValueEditorFactory, ioHelper, StaticServiceProvider.Instance.GetRequiredService()) - { - } - /// /// Initializes a new instance of the class. /// - public TrueFalsePropertyEditor( - IDataValueEditorFactory dataValueEditorFactory, - IIOHelper ioHelper, - IEditorConfigurationParser editorConfigurationParser) + public TrueFalsePropertyEditor(IDataValueEditorFactory dataValueEditorFactory) : base(dataValueEditorFactory) - { - _ioHelper = ioHelper; - _editorConfigurationParser = editorConfigurationParser; - SupportsReadOnly = true; - } + => SupportsReadOnly = true; /// protected override IDataValueEditor CreateValueEditor() => DataValueEditorFactory.Create(Attribute!); - /// - protected override IConfigurationEditor CreateConfigurationEditor() => - new TrueFalseConfigurationEditor(_ioHelper, _editorConfigurationParser); - internal class TrueFalsePropertyValueEditor : DataValueEditor { public TrueFalsePropertyValueEditor( - ILocalizedTextService localizedTextService, IShortStringHelper shortStringHelper, IJsonSerializer jsonSerializer, IIOHelper ioHelper, DataEditorAttribute attribute) - : base(localizedTextService, shortStringHelper, jsonSerializer, ioHelper, attribute) + : base(shortStringHelper, jsonSerializer, ioHelper, attribute) { } diff --git a/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/GridValueConverter.cs b/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/GridValueConverter.cs deleted file mode 100644 index 41eb196ff1..0000000000 --- a/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/GridValueConverter.cs +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using Microsoft.Extensions.Logging; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using Umbraco.Cms.Core.Configuration.Grid; -using Umbraco.Cms.Core.Models.PublishedContent; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.PropertyEditors.ValueConverters; - -/// -/// This ensures that the grid config is merged in with the front-end value -/// -[DefaultPropertyValueConverter(typeof(JsonValueConverter))] // this shadows the JsonValueConverter -[Obsolete("The grid is obsolete, will be removed in V13")] -public class GridValueConverter : JsonValueConverter -{ - private readonly IGridConfig _config; - - public GridValueConverter(PropertyEditorCollection propertyEditors, IGridConfig config, ILogger logger) - : base(propertyEditors, logger) => - _config = config; - - public override bool IsConverter(IPublishedPropertyType propertyType) - => propertyType.EditorAlias.InvariantEquals(Constants.PropertyEditors.Aliases.Grid); - - public override Type GetPropertyValueType(IPublishedPropertyType propertyType) - => typeof(JToken); - - public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType) - => PropertyCacheLevel.Element; - - public override object? ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object? source, bool preview) - { - if (source == null) - { - return null; - } - - var sourceString = source.ToString()!; - - if (sourceString.DetectIsJson()) - { - try - { - JObject? obj = JsonConvert.DeserializeObject(sourceString); - - // so we have the grid json... we need to merge in the grid's configuration values with the values - // we've saved in the database so that when the front end gets this value, it is up-to-date. - JArray sections = GetArray(obj!, "sections"); - foreach (JObject? section in sections.Cast()) - { - JArray rows = GetArray(section, "rows"); - foreach (JObject? row in rows.Cast()) - { - JArray areas = GetArray(row, "areas"); - foreach (JObject? area in areas.Cast()) - { - JArray controls = GetArray(area, "controls"); - foreach (JObject? control in controls.Cast()) - { - JObject? editor = control.Value("editor"); - if (editor != null) - { - var alias = editor.Value("alias"); - if (alias.IsNullOrWhiteSpace() == false) - { - // find the alias in config - IGridEditorConfig? found = - _config.EditorsConfig.Editors.FirstOrDefault(x => x.Alias == alias); - if (found != null) - { - // add/replace the editor value with the one from config - var serialized = new JObject - { - ["name"] = found.Name, - ["alias"] = found.Alias, - ["view"] = found.View, - ["render"] = found.Render, - ["icon"] = found.Icon, - ["config"] = JObject.FromObject(found.Config), - }; - - control["editor"] = serialized; - } - } - } - } - } - } - } - - return obj; - } - catch (Exception ex) - { - StaticApplicationLogging.Logger.LogError(ex, "Could not parse the string '{JsonString}' to a json object", sourceString); - } - } - - // it's not json, just return the string - return sourceString; - } - - private JArray GetArray(JObject obj, string propertyName) - { - if (obj.TryGetValue(propertyName, out JToken? token)) - { - var asArray = token as JArray; - return asArray ?? new JArray(); - } - - return new JArray(); - } -} diff --git a/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/NestedContentManyValueConverter.cs b/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/NestedContentManyValueConverter.cs deleted file mode 100644 index 4b6ab30ded..0000000000 --- a/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/NestedContentManyValueConverter.cs +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using System.Collections; -using Microsoft.Extensions.DependencyInjection; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using Umbraco.Cms.Core.DeliveryApi; -using Umbraco.Cms.Core.Logging; -using Umbraco.Cms.Core.Models.DeliveryApi; -using Umbraco.Cms.Core.Models.PublishedContent; -using Umbraco.Cms.Core.PropertyEditors.DeliveryApi; -using Umbraco.Cms.Core.PublishedCache; -using Umbraco.Cms.Web.Common.DependencyInjection; - -namespace Umbraco.Cms.Core.PropertyEditors.ValueConverters; - -/// -/// -/// Provides an implementation for for nested -/// content. -/// -[DefaultPropertyValueConverter(typeof(JsonValueConverter))] -[Obsolete("Nested content is obsolete, will be removed in V13")] -public class NestedContentManyValueConverter : NestedContentValueConverterBase, IDeliveryApiPropertyValueConverter -{ - private readonly IProfilingLogger _proflog; - private readonly IApiElementBuilder _apiElementBuilder; - - [Obsolete("Use constructor that takes all parameters, scheduled for removal in V13")] - public NestedContentManyValueConverter( - IPublishedSnapshotAccessor publishedSnapshotAccessor, - IPublishedModelFactory publishedModelFactory, - IProfilingLogger proflog) - : this( - publishedSnapshotAccessor, - publishedModelFactory, - proflog, - StaticServiceProvider.Instance.GetRequiredService()) - { - } - - /// - /// Initializes a new instance of the class. - /// - public NestedContentManyValueConverter( - IPublishedSnapshotAccessor publishedSnapshotAccessor, - IPublishedModelFactory publishedModelFactory, - IProfilingLogger proflog, - IApiElementBuilder apiElementBuilder) - : base(publishedSnapshotAccessor, publishedModelFactory) - { - _proflog = proflog; - _apiElementBuilder = apiElementBuilder; - } - - /// - public override bool IsConverter(IPublishedPropertyType propertyType) - => IsNestedMany(propertyType); - - /// - public override Type GetPropertyValueType(IPublishedPropertyType propertyType) - { - NestedContentConfiguration.ContentType[]? contentTypes = - propertyType.DataType.ConfigurationAs()?.ContentTypes; - - return contentTypes?.Length == 1 - ? typeof(IEnumerable<>).MakeGenericType(ModelType.For(contentTypes[0].Alias)) - : typeof(IEnumerable); - } - - /// - public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType) - => PropertyCacheLevel.Element; - - /// - public override object? ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object? source, bool preview) - => source?.ToString(); - - /// - public override object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object? inter, bool preview) - { - using (!_proflog.IsEnabled(Core.Logging.LogLevel.Debug) ? null : _proflog.DebugDuration( - $"ConvertPropertyToNestedContent ({propertyType.DataType.Id})")) - { - NestedContentConfiguration? configuration = - propertyType.DataType.ConfigurationAs(); - NestedContentConfiguration.ContentType[]? contentTypes = configuration?.ContentTypes; - IList elements = contentTypes?.Length == 1 - ? PublishedModelFactory.CreateModelList(contentTypes[0].Alias)! - : new List(); - - var value = (string?)inter; - if (string.IsNullOrWhiteSpace(value)) - { - return elements; - } - - List? objects = JsonConvert.DeserializeObject>(value); - if (objects is null || objects.Count == 0) - { - return elements; - } - - foreach (JObject sourceObject in objects) - { - IPublishedElement? element = ConvertToElement(sourceObject, referenceCacheLevel, preview); - if (element != null) - { - elements.Add(element); - } - } - - return elements; - } - } - - public PropertyCacheLevel GetDeliveryApiPropertyCacheLevel(IPublishedPropertyType propertyType) => GetPropertyCacheLevel(propertyType); - - public Type GetDeliveryApiPropertyValueType(IPublishedPropertyType propertyType) => typeof(IEnumerable); - - public object? ConvertIntermediateToDeliveryApiObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object? inter, bool preview, bool expanding) - { - var converted = ConvertIntermediateToObject(owner, propertyType, referenceCacheLevel, inter, preview); - if (converted is not IEnumerable elements) - { - return null; - } - - return elements.Select(element => _apiElementBuilder.Build(element)); - } -} diff --git a/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/NestedContentSingleValueConverter.cs b/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/NestedContentSingleValueConverter.cs deleted file mode 100644 index 03ff098cbf..0000000000 --- a/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/NestedContentSingleValueConverter.cs +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using Microsoft.Extensions.DependencyInjection; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using Umbraco.Cms.Core.DeliveryApi; -using Umbraco.Cms.Core.Logging; -using Umbraco.Cms.Core.Models.DeliveryApi; -using Umbraco.Cms.Core.Models.PublishedContent; -using Umbraco.Cms.Core.PropertyEditors.DeliveryApi; -using Umbraco.Cms.Core.PublishedCache; -using Umbraco.Cms.Web.Common.DependencyInjection; - -namespace Umbraco.Cms.Core.PropertyEditors.ValueConverters; - -/// -/// -/// Provides an implementation for for nested -/// content. -/// -[DefaultPropertyValueConverter(typeof(JsonValueConverter))] -[Obsolete("Nested content is obsolete, will be removed in V13")] -public class NestedContentSingleValueConverter : NestedContentValueConverterBase, IDeliveryApiPropertyValueConverter -{ - private readonly IProfilingLogger _proflog; - private readonly IApiElementBuilder _apiElementBuilder; - - [Obsolete("Use constructor that takes all parameters, scheduled for removal in V13")] - public NestedContentSingleValueConverter( - IPublishedSnapshotAccessor publishedSnapshotAccessor, - IPublishedModelFactory publishedModelFactory, - IProfilingLogger proflog) - : this( - publishedSnapshotAccessor, - publishedModelFactory, - proflog, - StaticServiceProvider.Instance.GetRequiredService()) - { - } - - /// - /// Initializes a new instance of the class. - /// - public NestedContentSingleValueConverter( - IPublishedSnapshotAccessor publishedSnapshotAccessor, - IPublishedModelFactory publishedModelFactory, - IProfilingLogger proflog, - IApiElementBuilder apiElementBuilder) - : base(publishedSnapshotAccessor, publishedModelFactory) - { - _proflog = proflog; - _apiElementBuilder = apiElementBuilder; - } - - /// - public override bool IsConverter(IPublishedPropertyType propertyType) - => IsNestedSingle(propertyType); - - /// - public override Type GetPropertyValueType(IPublishedPropertyType propertyType) - { - NestedContentConfiguration.ContentType[]? contentTypes = - propertyType.DataType.ConfigurationAs()?.ContentTypes; - - return contentTypes?.Length == 1 - ? ModelType.For(contentTypes[0].Alias) - : typeof(IPublishedElement); - } - - /// - public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType) - => PropertyCacheLevel.Element; - - /// - public override object? ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object? source, bool preview) - => source?.ToString(); - - /// - public override object? ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object? inter, bool preview) - { - using (!_proflog.IsEnabled(Core.Logging.LogLevel.Debug) ? null : _proflog.DebugDuration( - $"ConvertPropertyToNestedContent ({propertyType.DataType.Id})")) - { - var value = (string?)inter; - if (string.IsNullOrWhiteSpace(value)) - { - return null; - } - - List? objects = JsonConvert.DeserializeObject>(value)!; - if (objects.Count == 0) - { - return null; - } - - // Only return the first (existing data might contain more than is currently configured) - return ConvertToElement(objects[0], referenceCacheLevel, preview); - } - } - - public PropertyCacheLevel GetDeliveryApiPropertyCacheLevel(IPublishedPropertyType propertyType) => GetPropertyCacheLevel(propertyType); - - public Type GetDeliveryApiPropertyValueType(IPublishedPropertyType propertyType) => typeof(IEnumerable); - - public object? ConvertIntermediateToDeliveryApiObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, object? inter, bool preview, bool expanding) - { - var converted = ConvertIntermediateToObject(owner, propertyType, referenceCacheLevel, inter, preview); - if (converted is not IPublishedElement element) - { - return Array.Empty(); - } - - return new [] { _apiElementBuilder.Build(element) }; - } -} diff --git a/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/NestedContentValueConverterBase.cs b/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/NestedContentValueConverterBase.cs deleted file mode 100644 index ec4c62d297..0000000000 --- a/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/NestedContentValueConverterBase.cs +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using Newtonsoft.Json.Linq; -using Umbraco.Cms.Core.Models.PublishedContent; -using Umbraco.Cms.Core.PublishedCache; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.PropertyEditors.ValueConverters; - -[Obsolete("Nested content is obsolete, will be removed in V13")] -public abstract class NestedContentValueConverterBase : PropertyValueConverterBase -{ - private readonly IPublishedSnapshotAccessor _publishedSnapshotAccessor; - - protected NestedContentValueConverterBase( - IPublishedSnapshotAccessor publishedSnapshotAccessor, - IPublishedModelFactory publishedModelFactory) - { - _publishedSnapshotAccessor = publishedSnapshotAccessor; - PublishedModelFactory = publishedModelFactory; - } - - protected IPublishedModelFactory PublishedModelFactory { get; } - - public static bool IsNested(IPublishedPropertyType publishedProperty) - => publishedProperty.EditorAlias.InvariantEquals(Constants.PropertyEditors.Aliases.NestedContent); - - public static bool IsNestedSingle(IPublishedPropertyType publishedProperty) - => IsNested(publishedProperty) && IsSingle(publishedProperty); - - private static bool IsSingle(IPublishedPropertyType publishedProperty) - { - NestedContentConfiguration? config = publishedProperty.DataType.ConfigurationAs(); - - return config is not null && config.MinItems == 1 && config.MaxItems == 1; - } - - public static bool IsNestedMany(IPublishedPropertyType publishedProperty) - => IsNested(publishedProperty) && !IsSingle(publishedProperty); - - protected IPublishedElement? ConvertToElement(JObject sourceObject, PropertyCacheLevel referenceCacheLevel, bool preview) - { - var elementTypeAlias = - sourceObject[NestedContentPropertyEditor.ContentTypeAliasPropertyKey]?.ToObject(); - if (string.IsNullOrEmpty(elementTypeAlias)) - { - return null; - } - - IPublishedSnapshot publishedSnapshot = _publishedSnapshotAccessor.GetRequiredPublishedSnapshot(); - - // Only convert element types - content types will cause an exception when PublishedModelFactory creates the model - IPublishedContentType? publishedContentType = publishedSnapshot.Content?.GetContentType(elementTypeAlias); - if (publishedContentType is null || publishedContentType.IsElement == false) - { - return null; - } - - Dictionary? propertyValues = sourceObject.ToObject>(); - if (propertyValues is null || !propertyValues.TryGetValue("key", out var keyo) || - !Guid.TryParse(keyo?.ToString(), out Guid key)) - { - key = Guid.Empty; - } - - IPublishedElement element = new PublishedElement(publishedContentType, key, propertyValues, preview, referenceCacheLevel, _publishedSnapshotAccessor); - element = PublishedModelFactory.CreateModel(element); - - return element; - } -} diff --git a/src/Umbraco.Infrastructure/PropertyEditors/ValueListConfigurationEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/ValueListConfigurationEditor.cs index 1e42fa31db..cd4e443d5f 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/ValueListConfigurationEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/ValueListConfigurationEditor.cs @@ -1,12 +1,8 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using Microsoft.Extensions.DependencyInjection; -using Newtonsoft.Json.Linq; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Services; -using Umbraco.Extensions; +using Umbraco.Cms.Core.Serialization; namespace Umbraco.Cms.Core.PropertyEditors; @@ -18,20 +14,10 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// public class ValueListConfigurationEditor : ConfigurationEditor { - // Scheduled for removal in v12 - [Obsolete("Please use constructor that takes an IEditorConfigurationParser instead")] - public ValueListConfigurationEditor(ILocalizedTextService textService, IIOHelper ioHelper) - : this(textService, ioHelper, StaticServiceProvider.Instance.GetRequiredService()) - { - } - - public ValueListConfigurationEditor(ILocalizedTextService textService, IIOHelper ioHelper, IEditorConfigurationParser editorConfigurationParser) - : base(ioHelper, editorConfigurationParser) + public ValueListConfigurationEditor(IIOHelper ioHelper, IConfigurationEditorJsonSerializer configurationEditorJsonSerializer) + : base(ioHelper) { ConfigurationField items = Fields.First(x => x.Key == "items"); - - // customize the items field - items.Name = textService.Localize("editdatatype", "addPrevalue"); - items.Validators.Add(new ValueListUniqueValueValidator()); + items.Validators.Add(new ValueListUniqueValueValidator(configurationEditorJsonSerializer)); } } diff --git a/src/Umbraco.Infrastructure/PropertyEditors/ValueListUniqueValueValidator.cs b/src/Umbraco.Infrastructure/PropertyEditors/ValueListUniqueValueValidator.cs index 31b4ea718a..f2c75d501f 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/ValueListUniqueValueValidator.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/ValueListUniqueValueValidator.cs @@ -2,7 +2,7 @@ // See LICENSE for more details. using System.ComponentModel.DataAnnotations; -using Newtonsoft.Json.Linq; +using Umbraco.Cms.Core.Serialization; using Umbraco.Extensions; namespace Umbraco.Cms.Core.PropertyEditors; @@ -12,30 +12,45 @@ namespace Umbraco.Cms.Core.PropertyEditors; /// public class ValueListUniqueValueValidator : IValueValidator { + private readonly IConfigurationEditorJsonSerializer _configurationEditorJsonSerializer; + + public ValueListUniqueValueValidator(IConfigurationEditorJsonSerializer configurationEditorJsonSerializer) + => _configurationEditorJsonSerializer = configurationEditorJsonSerializer; + public IEnumerable Validate(object? value, string? valueType, object? dataTypeConfiguration) { - // the value we get should be a JArray - // [ { "value": , "sortOrder": 1 }, { ... }, ... ] - if (!(value is JArray json)) + var stringValue = value?.ToString(); + if (stringValue.IsNullOrWhiteSpace()) { yield break; } - // we ensure that values are unique - // (those are not empty - empty values are removed when persisting anyways) - var groupedValues = json.OfType() - .Where(x => x["value"] != null) - .Select((x, index) => new { value = x["value"]?.ToString(), index }) - .Where(x => x.value.IsNullOrWhiteSpace() == false) - .GroupBy(x => x.value); - - foreach (var group in groupedValues.Where(x => x.Count() > 1)) + ValueListConfiguration.ValueListItem[]? items = null; + try { - yield return new ValidationResult($"The value \"{group.Last().value}\" must be unique", new[] - { - // use the index number as server field so it can be wired up to the view - "item_" + group.Last().index.ToInvariantString(), - }); + items = _configurationEditorJsonSerializer.Deserialize(stringValue); + } + catch + { + // swallow and report error below + } + + if (items is null) + { + yield return new ValidationResult($"The configuration value {stringValue} is not a valid value list configuration", new[] { "items" }); + yield break; + } + + var duplicateValues = items + .Select(item => item.Value) + .GroupBy(v => v) + .Where(group => group.Count() > 1) + .Select(group => group.First()) + .ToArray(); + + foreach (var duplicateValue in duplicateValues) + { + yield return new ValidationResult($"The value \"{duplicateValue}\" must be unique", new[] { "items" }); } } } diff --git a/src/Umbraco.Infrastructure/Services/ContentListViewServiceBase.cs b/src/Umbraco.Infrastructure/Services/ContentListViewServiceBase.cs index 9a0975a081..eb02083899 100644 --- a/src/Umbraco.Infrastructure/Services/ContentListViewServiceBase.cs +++ b/src/Umbraco.Infrastructure/Services/ContentListViewServiceBase.cs @@ -102,7 +102,7 @@ internal abstract class ContentListViewServiceBase p.Alias == orderBy && p.IsSystem == 0); + .Any(p => p.Alias == orderBy && p.IsSystem); var ordering = Ordering.By( orderBy, diff --git a/src/Umbraco.Infrastructure/Services/EditorConfigurationParser.cs b/src/Umbraco.Infrastructure/Services/EditorConfigurationParser.cs deleted file mode 100644 index b31b50c668..0000000000 --- a/src/Umbraco.Infrastructure/Services/EditorConfigurationParser.cs +++ /dev/null @@ -1,71 +0,0 @@ -using System.Reflection; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using Umbraco.Cms.Core; -using Umbraco.Cms.Core.PropertyEditors; -using Umbraco.Cms.Core.Services; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Infrastructure.Services; - -public class EditorConfigurationParser : IEditorConfigurationParser -{ - public TConfiguration? ParseFromConfigurationEditor(IDictionary? editorValues, IEnumerable fields) - { - // note - editorValue contains a mix of CLR types (string, int...) and JToken - // turning everything back into a JToken... might not be fastest but is simplest - // for now - var o = new JObject(); - - foreach (ConfigurationField field in fields) - { - // field only, JsonPropertyAttribute is ignored here - // only keep fields that have a non-null/empty value - // rest will fall back to default during ToObject() - if (editorValues is not null && editorValues.TryGetValue(field.Key, out var value) && value != null && - (!(value is string stringValue) || !string.IsNullOrWhiteSpace(stringValue))) - { - if (value is JToken jtoken) - { - // If it's a jtoken then set it - o[field.PropertyName!] = jtoken; - } - else if (field.PropertyType == typeof(bool) && value is string sBool) - { - // If it's a boolean property type but a string is found, try to do a conversion - Attempt converted = sBool.TryConvertTo(); - if (converted.Success) - { - o[field.PropertyName!] = converted.Result; - } - } - else - { - // Default behavior - o[field.PropertyName!] = JToken.FromObject(value); - } - } - } - - return o.ToObject(); - } - - public Dictionary ParseToConfigurationEditor(TConfiguration? configuration) - { - string FieldNamer(PropertyInfo property) - { - // try the field - ConfigurationFieldAttribute? field = property.GetCustomAttribute(); - if (field is not null) - { - return field.Key; - } - - // but the property may not be a field just an extra thing - JsonPropertyAttribute? json = property.GetCustomAttribute(); - return json?.PropertyName ?? property.Name; - } - - return ObjectJsonExtensions.ToObjectDictionary(configuration, FieldNamer); - } -} diff --git a/src/Umbraco.Infrastructure/Templates/HtmlMacroParameterParser.cs b/src/Umbraco.Infrastructure/Templates/HtmlMacroParameterParser.cs deleted file mode 100644 index 6c7445d2da..0000000000 --- a/src/Umbraco.Infrastructure/Templates/HtmlMacroParameterParser.cs +++ /dev/null @@ -1,171 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Newtonsoft.Json; -using Umbraco.Cms.Core; -using Umbraco.Cms.Core.Models; -using Umbraco.Cms.Core.Models.Editors; -using Umbraco.Cms.Core.PropertyEditors; -using Umbraco.Cms.Core.Services; -using Umbraco.Cms.Infrastructure.Macros; -using Umbraco.Cms.Web.Common.DependencyInjection; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Infrastructure.Templates; - -public sealed class HtmlMacroParameterParser : IHtmlMacroParameterParser -{ - private readonly ILogger _logger; - private readonly IMacroService _macroService; - private readonly ParameterEditorCollection _parameterEditors; - private readonly DataValueReferenceFactoryCollection _dataValueReferenceFactories; - - [Obsolete("Use the non-obsolete overload instead, scheduled for removal in v14")] - public HtmlMacroParameterParser(IMacroService macroService, ILogger logger, ParameterEditorCollection parameterEditors) - : this( - macroService, - logger, - parameterEditors, - StaticServiceProvider.Instance.GetRequiredService()) - { } - - public HtmlMacroParameterParser(IMacroService macroService, ILogger logger, ParameterEditorCollection parameterEditors, DataValueReferenceFactoryCollection dataValueReferenceFactories) - { - _macroService = macroService; - _logger = logger; - _parameterEditors = parameterEditors; - _dataValueReferenceFactories = dataValueReferenceFactories; - } - - /// - /// Parses out media UDIs from an HTML string based on embedded macro parameter values. - /// - /// HTML string - /// - public IEnumerable FindUmbracoEntityReferencesFromEmbeddedMacros(string text) - { - // There may be more than one macro with the same alias on the page so using a tuple - var foundMacros = new List>>(); - - // This legacy ParseMacros() already finds the macros within a Rich Text Editor using regexes - // It seems to lowercase the macro parameter alias - so making the dictionary case insensitive - MacroTagParser.ParseMacros( - text, - textblock => { }, - (macroAlias, macroAttributes) => foundMacros.Add(new Tuple>( - macroAlias, - new Dictionary(macroAttributes, StringComparer.OrdinalIgnoreCase)))); - - foreach (UmbracoEntityReference umbracoEntityReference in GetUmbracoEntityReferencesFromMacros(foundMacros)) - { - yield return umbracoEntityReference; - } - } - - /// - /// Parses out media UDIs from Macro Grid Control parameters. - /// - /// - /// - public IEnumerable FindUmbracoEntityReferencesFromGridControlMacros(IEnumerable macroGridControls) - { - var foundMacros = new List>>(); - - foreach (GridValue.GridControl macroGridControl in macroGridControls) - { - // Deserialise JSON of Macro Grid Control to a class - GridMacro? gridMacro = macroGridControl.Value?.ToObject(); - - // Collect any macro parameters that contain the media udi format - if (gridMacro is not null && gridMacro.MacroParameters is not null && gridMacro.MacroParameters.Any()) - { - foundMacros.Add(new Tuple>(gridMacro.MacroAlias, gridMacro.MacroParameters)); - } - } - - foreach (UmbracoEntityReference umbracoEntityReference in GetUmbracoEntityReferencesFromMacros(foundMacros)) - { - yield return umbracoEntityReference; - } - } - - private IEnumerable GetUmbracoEntityReferencesFromMacros( - List>> macros) - { - if (_macroService is not IMacroService macroWithAliasService) - { - yield break; - } - - IEnumerable uniqueMacroAliases = macros.Select(f => f.Item1).Distinct(); - - // TODO: Tracking Macro references - // Here we are finding the used macros' Udis (there should be a Related Macro relation type - but Relations don't accept 'Macro' as an option) - var foundMacroUmbracoEntityReferences = new List(); - - // Get all the macro configs in one hit for these unique macro aliases - this is now cached with a custom cache policy - IEnumerable macroConfigs = macroWithAliasService.GetAll(uniqueMacroAliases.WhereNotNull().ToArray()); - - foreach (Tuple> macro in macros) - { - IMacro? macroConfig = macroConfigs.FirstOrDefault(f => f.Alias == macro.Item1); - if (macroConfig is null) - { - continue; - } - - foundMacroUmbracoEntityReferences.Add(new UmbracoEntityReference(Udi.Create(Constants.UdiEntityType.Macro, macroConfig.Key))); - - // Only do this if the macros actually have parameters - if (macroConfig.Properties.Keys.Any(f => f != "macroAlias")) - { - foreach (UmbracoEntityReference umbracoEntityReference in GetUmbracoEntityReferencesFromMacroParameters(macro.Item2, macroConfig, _parameterEditors)) - { - yield return umbracoEntityReference; - } - } - } - } - - /// - /// Finds media UDIs in Macro Parameter Values by calling the GetReference method for all the Macro Parameter Editors - /// for a particular macro. - /// - /// The parameters for the macro a dictionary of key/value strings - /// - /// The macro configuration for this particular macro - contains the types of editors used for - /// each parameter - /// - /// - /// A list of all the registered parameter editors used in the Umbraco implmentation - to - /// look up the corresponding property editor for a macro parameter - /// - /// - private IEnumerable GetUmbracoEntityReferencesFromMacroParameters(Dictionary macroParameters, IMacro macroConfig, ParameterEditorCollection parameterEditors) - { - foreach (IMacroProperty parameter in macroConfig.Properties) - { - if (macroParameters.TryGetValue(parameter.Alias, out var parameterValue)) - { - var parameterEditorAlias = parameter.EditorAlias; - IDataEditor? parameterEditor = parameterEditors.FirstOrDefault(f => string.Equals(f.Alias, parameterEditorAlias, StringComparison.OrdinalIgnoreCase)); - if (parameterEditor is not null) - { - foreach (UmbracoEntityReference entityReference in _dataValueReferenceFactories.GetReferences(parameterEditor, parameterValue)) - { - yield return entityReference; - } - } - } - } - } - - // Poco class to deserialise the Json for a Macro Control - private class GridMacro - { - [JsonProperty("macroAlias")] - public string? MacroAlias { get; set; } - - [JsonProperty("macroParamsDictionary")] - public Dictionary? MacroParameters { get; set; } - } -} diff --git a/src/Umbraco.Infrastructure/Templates/IHtmlMacroParameterParser.cs b/src/Umbraco.Infrastructure/Templates/IHtmlMacroParameterParser.cs deleted file mode 100644 index 4d0a6bf849..0000000000 --- a/src/Umbraco.Infrastructure/Templates/IHtmlMacroParameterParser.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Umbraco.Cms.Core.Models; -using Umbraco.Cms.Core.Models.Editors; - -namespace Umbraco.Cms.Infrastructure.Templates; - -/// -/// Provides methods to parse referenced entities as Macro parameters. -/// -public interface IHtmlMacroParameterParser -{ - /// - /// Parses out media UDIs from an HTML string based on embedded macro parameter values. - /// - /// HTML string - /// - IEnumerable FindUmbracoEntityReferencesFromEmbeddedMacros(string text); - - /// - /// Parses out media UDIs from Macro Grid Control parameters. - /// - /// - /// - IEnumerable FindUmbracoEntityReferencesFromGridControlMacros( - IEnumerable macroGridControls); -} diff --git a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs index 3db625c530..acf83bb5bd 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs @@ -7,14 +7,12 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Microsoft.Extensions.Primitives; using Umbraco.Cms.Core; using Umbraco.Cms.Core.Cache; -using Umbraco.Cms.Core.Configuration.Grid; using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.Hosting; using Umbraco.Cms.Core.Manifest; @@ -48,7 +46,6 @@ public class BackOfficeController : UmbracoController private readonly BackOfficeServerVariables _backOfficeServerVariables; private readonly IBackOfficeTwoFactorOptions _backOfficeTwoFactorOptions; private readonly IBackOfficeExternalLoginProviders _externalLogins; - private readonly IGridConfig _gridConfig; private readonly IHostingEnvironment _hostingEnvironment; private readonly IHttpContextAccessor _httpContextAccessor; private readonly IJsonSerializer _jsonSerializer; @@ -79,7 +76,6 @@ public class BackOfficeController : UmbracoController IOptionsSnapshot globalSettings, IHostingEnvironment hostingEnvironment, ILocalizedTextService textService, - IGridConfig gridConfig, BackOfficeServerVariables backOfficeServerVariables, AppCaches appCaches, IBackOfficeSignInManager signInManager, @@ -99,7 +95,6 @@ public class BackOfficeController : UmbracoController _globalSettings = globalSettings.Value; _hostingEnvironment = hostingEnvironment; _textService = textService; - _gridConfig = gridConfig ?? throw new ArgumentNullException(nameof(gridConfig)); _backOfficeServerVariables = backOfficeServerVariables; _appCaches = appCaches; _signInManager = signInManager; @@ -323,11 +318,6 @@ public class BackOfficeController : UmbracoController return nestedDictionary; } - [Authorize(Policy = AuthorizationPolicies.BackOfficeAccess)] - [AngularJsonOnlyConfiguration] - [HttpGet] - public IEnumerable GetGridConfig() => _gridConfig.EditorsConfig.Editors; - /// /// Returns the JavaScript object representing the static server variables javascript object /// diff --git a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeServerVariables.cs b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeServerVariables.cs index c3ab60f059..b48261fe9b 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeServerVariables.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeServerVariables.cs @@ -347,7 +347,6 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers {"externalLoginsUrl", _linkGenerator.GetPathByAction(nameof(BackOfficeController.ExternalLogin), backOfficeControllerName, new { area = Constants.Web.Mvc.BackOfficeArea })}, {"externalLinkLoginsUrl", _linkGenerator.GetPathByAction(nameof(BackOfficeController.LinkLogin), backOfficeControllerName, new { area = Constants.Web.Mvc.BackOfficeArea })}, - {"gridConfig", _linkGenerator.GetPathByAction(nameof(BackOfficeController.GetGridConfig), backOfficeControllerName, new { area = Constants.Web.Mvc.BackOfficeArea })}, // TODO: This is ultra confusing! this same key is used for different things, when returning the full app when authenticated it is this URL but when not auth'd it's actually the ServerVariables address {"serverVarsJs", _linkGenerator.GetPathByAction(nameof(BackOfficeController.Application), backOfficeControllerName, new { area = Constants.Web.Mvc.BackOfficeArea })}, {"marketplaceUrl", GetMarketplaceUrl()}, @@ -415,10 +414,6 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers "macroRenderingApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl( controller => controller.GetMacroParameters(0)) }, - { - "macroApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl( - controller => controller.Create(string.Empty)) - }, { "authenticationApiBaseUrl", _linkGenerator.GetUmbracoApiServiceBaseUrl( controller => controller.PostLogin(new LoginModel())) diff --git a/src/Umbraco.Web.BackOffice/Controllers/ContentTypeController.cs b/src/Umbraco.Web.BackOffice/Controllers/ContentTypeController.cs index ab5bd640b4..bd98d41d9b 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/ContentTypeController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/ContentTypeController.cs @@ -363,7 +363,6 @@ public class ContentTypeController : ContentTypeControllerBase { Editor = dataTypeDiff.EditorAlias, Validation = new PropertyTypeValidation(), - View = editor?.GetValueEditor().View, Config = configuration != null ? editor?.GetConfigurationEditor().ToConfigurationEditor(configuration) : null diff --git a/src/Umbraco.Web.BackOffice/Controllers/DataTypeController.cs b/src/Umbraco.Web.BackOffice/Controllers/DataTypeController.cs index 9ab480ab18..117aa42f9a 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/DataTypeController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/DataTypeController.cs @@ -530,7 +530,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers } var grouped = dataTypes?.WhereNotNull() - .GroupBy(x => x.Group.IsNullOrWhiteSpace() ? "" : x.Group!.ToLower()) + .GroupBy(x => string.Empty) .ToDictionary(group => group.Key, group => group.OrderBy(d => d.Name).AsEnumerable()); return grouped; @@ -563,7 +563,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers } var grouped = Enumerable.ToDictionary(datatypes - .GroupBy(x => x.Group.IsNullOrWhiteSpace() ? "" : x.Group!.ToLower()), group => group.Key, group => group.OrderBy(d => d.Name).AsEnumerable()); + .GroupBy(x => string.Empty), group => group.Key, group => group.OrderBy(d => d.Name).AsEnumerable()); return grouped; } @@ -580,7 +580,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers public IEnumerable GetAllPropertyEditors() { return _propertyEditorCollection - .OrderBy(x => x.Name) + .OrderBy(x => x.Alias) .Select(_umbracoMapper.Map).WhereNotNull(); } #endregion diff --git a/src/Umbraco.Web.BackOffice/Controllers/MacrosController.cs b/src/Umbraco.Web.BackOffice/Controllers/MacrosController.cs deleted file mode 100644 index 799b97144d..0000000000 --- a/src/Umbraco.Web.BackOffice/Controllers/MacrosController.cs +++ /dev/null @@ -1,418 +0,0 @@ -using System.Globalization; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Logging; -using Umbraco.Cms.Core; -using Umbraco.Cms.Core.Hosting; -using Umbraco.Cms.Core.Mapping; -using Umbraco.Cms.Core.Models; -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Cms.Core.PropertyEditors; -using Umbraco.Cms.Core.Security; -using Umbraco.Cms.Core.Services; -using Umbraco.Cms.Core.Strings; -using Umbraco.Cms.Web.Common.Attributes; -using Umbraco.Cms.Web.Common.Authorization; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Web.BackOffice.Controllers; - -/// -/// The API controller used for editing dictionary items -/// -[PluginController(Constants.Web.Mvc.BackOfficeApiArea)] -[Authorize(Policy = AuthorizationPolicies.TreeAccessMacros)] -[ParameterSwapControllerActionSelector(nameof(GetById), "id", typeof(int), typeof(Guid), typeof(Udi))] -public class MacrosController : BackOfficeNotificationsController -{ - private readonly IBackOfficeSecurityAccessor _backofficeSecurityAccessor; - private readonly IHostingEnvironment _hostingEnvironment; - private readonly ILogger _logger; - private readonly IMacroService _macroService; - private readonly ParameterEditorCollection _parameterEditorCollection; - private readonly IShortStringHelper _shortStringHelper; - private readonly IUmbracoMapper _umbracoMapper; - - public MacrosController( - ParameterEditorCollection parameterEditorCollection, - IMacroService macroService, - IShortStringHelper shortStringHelper, - IBackOfficeSecurityAccessor backofficeSecurityAccessor, - ILogger logger, - IHostingEnvironment hostingEnvironment, - IUmbracoMapper umbracoMapper) - { - _parameterEditorCollection = parameterEditorCollection ?? - throw new ArgumentNullException(nameof(parameterEditorCollection)); - _macroService = macroService ?? throw new ArgumentNullException(nameof(macroService)); - _shortStringHelper = shortStringHelper ?? throw new ArgumentNullException(nameof(shortStringHelper)); - _backofficeSecurityAccessor = backofficeSecurityAccessor ?? - throw new ArgumentNullException(nameof(backofficeSecurityAccessor)); - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - _hostingEnvironment = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment)); - _umbracoMapper = umbracoMapper ?? throw new ArgumentNullException(nameof(umbracoMapper)); - } - - - /// - /// Creates a new macro - /// - /// - /// The name. - /// - /// - /// The id of the created macro - /// - [HttpPost] - public ActionResult Create(string name) - { - if (string.IsNullOrWhiteSpace(name)) - { - return ValidationProblem("Name can not be empty"); - } - - var alias = name.ToSafeAlias(_shortStringHelper); - - if (_macroService.GetByAlias(alias) != null) - { - return ValidationProblem("Macro with this alias already exists"); - } - - if (name == null || name.Length > 255) - { - return ValidationProblem("Name cannnot be more than 255 characters in length."); - } - - try - { - var macro = new Macro(_shortStringHelper) { Alias = alias, Name = name, MacroSource = string.Empty }; - - _macroService.Save(macro, _backofficeSecurityAccessor.BackOfficeSecurity?.CurrentUser?.Id ?? -1); - - return macro.Id; - } - catch (Exception exception) - { - const string errorMessage = "Error creating macro"; - _logger.LogError(exception, errorMessage); - return ValidationProblem(errorMessage); - } - } - - [HttpGet] - public ActionResult GetById(int id) - { - IMacro? macro = _macroService.GetById(id); - - if (macro == null) - { - return ValidationProblem($"Macro with id {id} does not exist"); - } - - MacroDisplay? macroDisplay = MapToDisplay(macro); - - return macroDisplay; - } - - [HttpGet] - public ActionResult GetById(Guid id) - { - IMacro? macro = _macroService.GetById(id); - - if (macro == null) - { - return ValidationProblem($"Macro with id {id} does not exist"); - } - - MacroDisplay? macroDisplay = MapToDisplay(macro); - - return macroDisplay; - } - - [HttpGet] - public ActionResult GetById(Udi id) - { - var guidUdi = id as GuidUdi; - if (guidUdi == null) - { - return ValidationProblem($"Macro with id {id} does not exist"); - } - - IMacro? macro = _macroService.GetById(guidUdi.Guid); - if (macro == null) - { - return ValidationProblem($"Macro with id {id} does not exist"); - } - - MacroDisplay? macroDisplay = MapToDisplay(macro); - - return macroDisplay; - } - - [HttpPost] - public IActionResult DeleteById(int id) - { - IMacro? macro = _macroService.GetById(id); - - if (macro == null) - { - return ValidationProblem($"Macro with id {id} does not exist"); - } - - _macroService.Delete(macro); - - return Ok(); - } - - [HttpPost] - public ActionResult Save(MacroDisplay macroDisplay) - { - if (macroDisplay == null) - { - return ValidationProblem("No macro data found in request"); - } - - if (macroDisplay.Name == null || macroDisplay.Name.Length > 255) - { - return ValidationProblem("Name cannnot be more than 255 characters in length."); - } - - IMacro? macro = macroDisplay.Id is null - ? null - : _macroService.GetById(int.Parse(macroDisplay.Id.ToString()!, CultureInfo.InvariantCulture)); - - if (macro == null) - { - return ValidationProblem($"Macro with id {macroDisplay.Id} does not exist"); - } - - if (macroDisplay.Alias != macro.Alias) - { - IMacro? macroByAlias = _macroService.GetByAlias(macroDisplay.Alias); - - if (macroByAlias != null) - { - return ValidationProblem("Macro with this alias already exists"); - } - } - - macro.Alias = macroDisplay.Alias; - macro.Name = macroDisplay.Name; - macro.CacheByMember = macroDisplay.CacheByUser; - macro.CacheByPage = macroDisplay.CacheByPage; - macro.CacheDuration = macroDisplay.CachePeriod; - macro.DontRender = !macroDisplay.RenderInEditor; - macro.UseInEditor = macroDisplay.UseInEditor; - macro.MacroSource = macroDisplay.View; - macro.Properties.ReplaceAll( - macroDisplay.Parameters.Select((x, i) => new MacroProperty(x.Key, x.Label, i, x.Editor))); - - try - { - _macroService.Save(macro, _backofficeSecurityAccessor.BackOfficeSecurity?.CurrentUser?.Id ?? -1); - - macroDisplay.Notifications.Clear(); - - macroDisplay.Notifications.Add(new BackOfficeNotification("Success", "Macro saved", NotificationStyle.Success)); - - return macroDisplay; - } - catch (Exception exception) - { - const string errorMessage = "Error creating macro"; - _logger.LogError(exception, errorMessage); - return ValidationProblem(errorMessage); - } - } - - /// - /// Gets a list of available macro partials - /// - /// - /// The . - /// - public IEnumerable GetPartialViews() - { - var views = new List(); - - views.AddRange(FindPartialViewsFiles()); - - return views; - } - - /// - /// Gets the available parameter editors - /// - /// - /// The . - /// - public ParameterEditorCollection GetParameterEditors() => _parameterEditorCollection; - - /// - /// Gets the available parameter editors grouped by their group. - /// - /// - /// The . - /// - public IDictionary> GetGroupedParameterEditors() - { - IDataEditor[] parameterEditors = _parameterEditorCollection.ToArray(); - - var grouped = parameterEditors - .GroupBy(x => x.Group.IsNullOrWhiteSpace() ? string.Empty : x.Group.ToLower()) - .OrderBy(x => x.Key) - .ToDictionary(group => group.Key, group => group.OrderBy(d => d.Name).AsEnumerable()); - - return grouped; - } - - /// - /// Get parameter editor by alias. - /// - /// - /// The . - /// - public IDataEditor? GetParameterEditorByAlias(string alias) - { - IDataEditor[] parameterEditors = _parameterEditorCollection.ToArray(); - - IDataEditor? parameterEditor = parameterEditors.FirstOrDefault(x => x.Alias.InvariantEquals(alias)); - - return parameterEditor; - } - - - /// - /// Finds all the macro partials - /// - /// - /// The . - /// - private IEnumerable FindPartialViewsFiles() - { - var files = new List(); - - files.AddRange(FindPartialViewFilesInViewsFolder()); - files.AddRange(FindPartialViewFilesInPluginFolders()); - - return files; - } - - /// - /// Finds all macro partials in the views folder - /// - /// - /// The . - /// - private IEnumerable FindPartialViewFilesInViewsFolder() - { - // TODO: This is inconsistent. We have FileSystems.MacroPartialsFileSystem but we basically don't use - // that at all except to render the tree. In the future we may want to use it. This also means that - // we are storing the virtual path of the macro like ~/Views/MacroPartials/Login.cshtml instead of the - // relative path which would work with the FileSystems.MacroPartialsFileSystem, but these are incompatible. - // At some point this should all be made consistent and probably just use FileSystems.MacroPartialsFileSystem. - - var partialsDir = _hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.MacroPartials); - - return FindPartialViewFilesInFolder( - partialsDir, - partialsDir, - Constants.SystemDirectories.MacroPartials); - } - - /// - /// Finds partial view files in app plugin folders. - /// - /// - /// - private IEnumerable FindPartialViewFilesInPluginFolders() - { - var files = new List(); - - var appPluginsFolder = - new DirectoryInfo(_hostingEnvironment.MapPathContentRoot(Constants.SystemDirectories.AppPlugins)); - - if (!appPluginsFolder.Exists) - { - return files; - } - - foreach (DirectoryInfo directory in appPluginsFolder.GetDirectories()) - { - DirectoryInfo[] viewsFolder = directory.GetDirectories("Views"); - if (viewsFolder.Any()) - { - DirectoryInfo[] macroPartials = viewsFolder.First().GetDirectories("MacroPartials"); - if (macroPartials.Any()) - { - files.AddRange(FindPartialViewFilesInFolder( - macroPartials.First().FullName, - macroPartials.First().FullName, - Constants.SystemDirectories.AppPlugins + "/" + directory.Name + "/Views/MacroPartials")); - } - } - } - - return files; - } - - /// - /// Finds all partial views in a folder and subfolders - /// - /// - /// The org path. - /// - /// - /// The path. - /// - /// - /// The prefix virtual path. - /// - /// - /// The . - /// - private IEnumerable FindPartialViewFilesInFolder(string orgPath, string path, string prefixVirtualPath) - { - var files = new List(); - var dirInfo = new DirectoryInfo(path); - - if (dirInfo.Exists) - { - foreach (DirectoryInfo dir in dirInfo.GetDirectories()) - { - files.AddRange(FindPartialViewFilesInFolder(orgPath, path + "/" + dir.Name, prefixVirtualPath)); - } - - FileInfo[] fileInfo = dirInfo.GetFiles("*.*"); - - files.AddRange( - fileInfo.Select(file => - prefixVirtualPath.TrimEnd(Constants.CharArrays.ForwardSlash) + "/" + - (path.Replace(orgPath, string.Empty).Trim(Constants.CharArrays.ForwardSlash) + "/" + file.Name) - .Trim(Constants.CharArrays.ForwardSlash))); - } - - return files; - } - - /// - /// Used to map an instance to a - /// - /// - /// - private MacroDisplay? MapToDisplay(IMacro macro) - { - MacroDisplay? display = _umbracoMapper.Map(macro); - - IEnumerable parameters = macro.Properties.Values - .OrderBy(x => x.SortOrder) - .Select(x => new MacroParameterDisplay { Editor = x.EditorAlias, Key = x.Alias, Label = x.Name, Id = x.Id }); - - if (display is not null) - { - display.Parameters = parameters; - } - - return display; - } -} diff --git a/src/Umbraco.Web.BackOffice/Trees/DataTypeTreeController.cs b/src/Umbraco.Web.BackOffice/Trees/DataTypeTreeController.cs index d0164afa06..4b7cc5f15c 100644 --- a/src/Umbraco.Web.BackOffice/Trees/DataTypeTreeController.cs +++ b/src/Umbraco.Web.BackOffice/Trees/DataTypeTreeController.cs @@ -94,7 +94,7 @@ public class DataTypeTreeController : TreeController, ISearchableTree { IDataType dataType = dataTypes[dt.Id]; TreeNode node = CreateTreeNode(dt.Id.ToInvariantString(), id, queryStrings, dt.Name, - dataType.Editor?.Icon, false); + icon: null, false); node.Path = dt.Path; return node; }) diff --git a/tests/Umbraco.TestData/UmbracoTestDataController.cs b/tests/Umbraco.TestData/UmbracoTestDataController.cs index 5743a746a8..5fe7e0e254 100644 --- a/tests/Umbraco.TestData/UmbracoTestDataController.cs +++ b/tests/Umbraco.TestData/UmbracoTestDataController.cs @@ -272,8 +272,6 @@ public class UmbracoTestDataController : SurfaceController { Name = "Review" }); - docType.AddPropertyType( - new PropertyType(_shortStringHelper, GetOrCreateMediaPicker(), "media") { Name = "Media" }); docType.AddPropertyType(new PropertyType(_shortStringHelper, GetOrCreateText(), "desc") { Name = "Description" }); Services.ContentTypeService.Save(docType); docType.AllowedContentTypes = new[] { new ContentTypeSort(docType.Key, 0, docType.Alias) }; @@ -284,9 +282,6 @@ public class UmbracoTestDataController : SurfaceController private IDataType GetOrCreateRichText() => GetOrCreateDataType(RichTextDataTypeName, Constants.PropertyEditors.Aliases.RichText); - private IDataType GetOrCreateMediaPicker() => - GetOrCreateDataType(MediaPickerDataTypeName, Constants.PropertyEditors.Aliases.MediaPicker); - private IDataType GetOrCreateText() => GetOrCreateDataType(TextDataTypeName, Constants.PropertyEditors.Aliases.TextBox); diff --git a/tests/Umbraco.Tests.Common/Builders/ContentBuilder.cs b/tests/Umbraco.Tests.Common/Builders/ContentBuilder.cs index 109885a2be..05cc4b80dd 100644 --- a/tests/Umbraco.Tests.Common/Builders/ContentBuilder.cs +++ b/tests/Umbraco.Tests.Common/Builders/ContentBuilder.cs @@ -454,7 +454,6 @@ public class ContentBuilder content.SetValue("ddl", "1234"); content.SetValue("chklist", "randomc"); content.SetValue("contentPicker", Udi.Create(Constants.UdiEntityType.Document, new Guid("74ECA1D4-934E-436A-A7C7-36CC16D4095C")).ToString()); - content.SetValue("mediaPicker", Udi.Create(Constants.UdiEntityType.Media, new Guid("44CB39C8-01E5-45EB-9CF8-E70AAF2D1691")).ToString()); content.SetValue("memberPicker", Udi.Create(Constants.UdiEntityType.Member, new Guid("9A50A448-59C0-4D42-8F93-4F1D55B0F47D")).ToString()); content.SetValue("multiUrlPicker", "[{\"name\":\"https://test.com\",\"url\":\"https://test.com\"}]"); content.SetValue("tags", "this,is,tags"); diff --git a/tests/Umbraco.Tests.Common/Builders/ContentTypeBuilder.cs b/tests/Umbraco.Tests.Common/Builders/ContentTypeBuilder.cs index 283b3df773..a5f323bdb1 100644 --- a/tests/Umbraco.Tests.Common/Builders/ContentTypeBuilder.cs +++ b/tests/Umbraco.Tests.Common/Builders/ContentTypeBuilder.cs @@ -501,14 +501,6 @@ public class ContentTypeBuilder .WithSortOrder(16) .Done() .AddPropertyType() - .WithAlias("mediaPicker") - .WithName("Media Picker") - .WithDataTypeId(1048) - .WithPropertyEditorAlias(Constants.PropertyEditors.Aliases.MediaPicker) - .WithValueStorageType(ValueStorageType.Integer) - .WithSortOrder(17) - .Done() - .AddPropertyType() .WithAlias("memberPicker") .WithName("Member Picker") .WithDataTypeId(1047) diff --git a/tests/Umbraco.Tests.Common/Builders/DataEditorBuilder.cs b/tests/Umbraco.Tests.Common/Builders/DataEditorBuilder.cs index 69e7d8df74..d29eea8bcf 100644 --- a/tests/Umbraco.Tests.Common/Builders/DataEditorBuilder.cs +++ b/tests/Umbraco.Tests.Common/Builders/DataEditorBuilder.cs @@ -65,7 +65,6 @@ public class DataEditorBuilder Mock.Of()) { Alias = alias, - Name = name, DefaultConfiguration = defaultConfiguration, ExplicitConfigurationEditor = explicitConfigurationEditor, ExplicitValueEditor = explicitValueEditor diff --git a/tests/Umbraco.Tests.Common/Builders/DataValueEditorBuilder.cs b/tests/Umbraco.Tests.Common/Builders/DataValueEditorBuilder.cs index 81f9b8f687..7c3cfd35da 100644 --- a/tests/Umbraco.Tests.Common/Builders/DataValueEditorBuilder.cs +++ b/tests/Umbraco.Tests.Common/Builders/DataValueEditorBuilder.cs @@ -50,8 +50,6 @@ public class DataValueEditorBuilder : ChildBuilderBase : ChildBuilderBase()) { ConfigurationObject = configuration, - View = view, - HideLabel = hideLabel, ValueType = valueType }; } diff --git a/tests/Umbraco.Tests.Common/TestHelpers/MockedValueEditors.cs b/tests/Umbraco.Tests.Common/TestHelpers/MockedValueEditors.cs index 38cfc5d3de..e309a5f232 100644 --- a/tests/Umbraco.Tests.Common/TestHelpers/MockedValueEditors.cs +++ b/tests/Umbraco.Tests.Common/TestHelpers/MockedValueEditors.cs @@ -4,7 +4,6 @@ using Moq; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.PropertyEditors; -using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Strings; using Umbraco.Cms.Infrastructure.Serialization; @@ -17,10 +16,9 @@ public class MockedValueEditors var valueType = ValueTypes.IsValue(name) ? name : ValueTypes.String; return new DataValueEditor( - Mock.Of(), Mock.Of(), new JsonNetSerializer(), Mock.Of(), - new DataEditorAttribute(name, name, name) { ValueType = valueType }); + new DataEditorAttribute(name) { ValueType = valueType }); } } diff --git a/tests/Umbraco.Tests.Integration/TestServerTest/Controllers/EnsureNotAmbiguousActionNameControllerTests.cs b/tests/Umbraco.Tests.Integration/TestServerTest/Controllers/EnsureNotAmbiguousActionNameControllerTests.cs index 518a4f58b4..d7b70f1376 100644 --- a/tests/Umbraco.Tests.Integration/TestServerTest/Controllers/EnsureNotAmbiguousActionNameControllerTests.cs +++ b/tests/Umbraco.Tests.Integration/TestServerTest/Controllers/EnsureNotAmbiguousActionNameControllerTests.cs @@ -78,10 +78,6 @@ public class EnsureNotAmbiguousActionNameControllerTests : UmbracoTestServerTest EnsureNotAmbiguousActionName(PrepareApiControllerUrl(x => x.GetIcon(string.Empty))); - EnsureNotAmbiguousActionName(PrepareApiControllerUrl(x => x.GetById(intId))); - EnsureNotAmbiguousActionName(PrepareApiControllerUrl(x => x.GetById(guidId))); - EnsureNotAmbiguousActionName(PrepareApiControllerUrl(x => x.GetById(udiId))); - EnsureNotAmbiguousActionName(PrepareApiControllerUrl(x => x.GetById(intId))); EnsureNotAmbiguousActionName(PrepareApiControllerUrl(x => x.GetById(guidId))); EnsureNotAmbiguousActionName(PrepareApiControllerUrl(x => x.GetById(udiId))); diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/ContentServiceTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/ContentServiceTests.cs index cb42dfd3b5..93022ee4a2 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/ContentServiceTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/ContentServiceTests.cs @@ -2707,9 +2707,6 @@ public class ContentServiceTests : UmbracoIntegrationTestWithContent Assert.That(sut.GetValue("contentPicker"), Is.EqualTo(Udi.Create(Constants.UdiEntityType.Document, new Guid("74ECA1D4-934E-436A-A7C7-36CC16D4095C")))); - Assert.That(sut.GetValue("mediaPicker"), - Is.EqualTo(Udi.Create(Constants.UdiEntityType.Media, - new Guid("44CB39C8-01E5-45EB-9CF8-E70AAF2D1691")))); Assert.That(sut.GetValue("memberPicker"), Is.EqualTo(Udi.Create(Constants.UdiEntityType.Member, new Guid("9A50A448-59C0-4D42-8F93-4F1D55B0F47D")))); diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Examine.Lucene/UmbracoExamine/IndexTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Examine.Lucene/UmbracoExamine/IndexTest.cs index 3f56bc4f0f..7e3d16379a 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Examine.Lucene/UmbracoExamine/IndexTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Examine.Lucene/UmbracoExamine/IndexTest.cs @@ -90,92 +90,6 @@ public class IndexTest : ExamineBaseTest } } - [Test] - [LongRunning] - public void GivenIndexingDocument_WhenGridPropertyData_ThenDataIndexedInSegregatedFields() - { - using (GetSynchronousContentIndex(false, out var index, out _, out var contentValueSetBuilder)) - { - index.CreateIndex(); - - var contentType = ContentTypeBuilder.CreateBasicContentType(); - contentType.AddPropertyType(new PropertyType(TestHelper.ShortStringHelper, "test", ValueStorageType.Ntext) - { - Alias = "grid", - Name = "Grid", - PropertyEditorAlias = Constants.PropertyEditors.Aliases.Grid - }); - var content = ContentBuilder.CreateBasicContent(contentType); - content.Id = 555; - content.Path = "-1,555"; - var gridVal = new GridValue - { - Name = "n1", - Sections = new List - { - new() - { - Grid = "g1", - Rows = new List - { - new() - { - Id = Guid.NewGuid(), - Name = "row1", - Areas = new List - { - new() - { - Grid = "g2", - Controls = new List - { - new() - { - Editor = new GridValue.GridEditor - { - Alias = "editor1", - View = "view1" - }, - Value = "value1" - }, - new() - { - Editor = new GridValue.GridEditor - { - Alias = "editor1", - View = "view1" - }, - Value = "value2" - } - } - } - } - } - } - } - } - }; - - var json = JsonConvert.SerializeObject(gridVal); - content.Properties["grid"].SetValue(json); - - var valueSet = contentValueSetBuilder.GetValueSets(content); - index.IndexItems(valueSet); - - var results = index.Searcher.CreateQuery().Id(555).Execute(); - Assert.AreEqual(1, results.TotalItemCount); - - var result = results.First(); - Assert.IsTrue(result.Values.ContainsKey("grid.row1")); - Assert.AreEqual("value1", result.AllValues["grid.row1"][0]); - Assert.AreEqual("value2", result.AllValues["grid.row1"][1]); - Assert.IsTrue(result.Values.ContainsKey("grid")); - Assert.AreEqual("value1 value2 ", result["grid"]); - Assert.IsTrue(result.Values.ContainsKey($"{UmbracoExamineFieldNames.RawFieldPrefix}grid")); - Assert.AreEqual(json, result[$"{UmbracoExamineFieldNames.RawFieldPrefix}grid"]); - } - } - [Test] [LongRunning] public void GivenEmptyIndex_WhenUsingWithContentAndMediaPopulators_ThenIndexPopulated() diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Packaging/PackageDataInstallationTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Packaging/PackageDataInstallationTests.cs index 6f90cd3a94..ac40f6d5a3 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Packaging/PackageDataInstallationTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Packaging/PackageDataInstallationTests.cs @@ -32,7 +32,7 @@ public class PackageDataInstallationTests : UmbracoIntegrationTestWithContent private IMacroService MacroService => GetRequiredService(); [HideFromTypeFinder] - [DataEditor("7e062c13-7c41-4ad9-b389-41d88aeef87c", "Editor1", "editor1")] + [DataEditor("7e062c13-7c41-4ad9-b389-41d88aeef87c")] public class Editor1 : DataEditor { public Editor1(IDataValueEditorFactory dataValueEditorFactory) @@ -42,7 +42,7 @@ public class PackageDataInstallationTests : UmbracoIntegrationTestWithContent } [HideFromTypeFinder] - [DataEditor("d15e1281-e456-4b24-aa86-1dda3e4299d5", "Editor2", "editor2")] + [DataEditor("d15e1281-e456-4b24-aa86-1dda3e4299d5")] public class Editor2 : DataEditor { public Editor2(IDataValueEditorFactory dataValueEditorFactory) diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DataTypeDefinitionRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DataTypeDefinitionRepositoryTest.cs index 1d29a8d833..ceacdd8091 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DataTypeDefinitionRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DataTypeDefinitionRepositoryTest.cs @@ -35,19 +35,17 @@ public class DataTypeDefinitionRepositoryTest : UmbracoIntegrationTest private IConfigurationEditorJsonSerializer ConfigurationEditorJsonSerializer => GetRequiredService(); - private IJsonSerializer JsonSerializer => GetRequiredService(); - [Test] public void Can_Find_Usages() { using (ScopeProvider.CreateScope()) { IDataType dataType1 = - new DataType(new RadioButtonsPropertyEditor(DataValueEditorFactory, IOHelper, LocalizedTextService), ConfigurationEditorJsonSerializer) + new DataType(new RadioButtonsPropertyEditor(DataValueEditorFactory, IOHelper, ConfigurationEditorJsonSerializer), ConfigurationEditorJsonSerializer) { Name = "dt1" }; DataTypeRepository.Save(dataType1); IDataType dataType2 = - new DataType(new RadioButtonsPropertyEditor(DataValueEditorFactory, IOHelper, LocalizedTextService), ConfigurationEditorJsonSerializer) + new DataType(new RadioButtonsPropertyEditor(DataValueEditorFactory, IOHelper, ConfigurationEditorJsonSerializer), ConfigurationEditorJsonSerializer) { Name = "dt2" }; DataTypeRepository.Save(dataType2); @@ -105,13 +103,13 @@ public class DataTypeDefinitionRepositoryTest : UmbracoIntegrationTest var dataType = (IDataType)new DataType( - new RadioButtonsPropertyEditor(DataValueEditorFactory, IOHelper, LocalizedTextService), ConfigurationEditorJsonSerializer, container2.Id) + new RadioButtonsPropertyEditor(DataValueEditorFactory, IOHelper, ConfigurationEditorJsonSerializer), ConfigurationEditorJsonSerializer, container2.Id) { Name = "dt1" }; DataTypeRepository.Save(dataType); // create a var dataType2 = - (IDataType)new DataType(new RadioButtonsPropertyEditor(DataValueEditorFactory, IOHelper, LocalizedTextService), ConfigurationEditorJsonSerializer, dataType.Id) + (IDataType)new DataType(new RadioButtonsPropertyEditor(DataValueEditorFactory, IOHelper, ConfigurationEditorJsonSerializer), ConfigurationEditorJsonSerializer, dataType.Id) { Name = "dt2" }; DataTypeRepository.Save(dataType2); @@ -169,7 +167,7 @@ public class DataTypeDefinitionRepositoryTest : UmbracoIntegrationTest DataTypeContainerRepository.Save(container); var dataTypeDefinition = - new DataType(new RadioButtonsPropertyEditor(DataValueEditorFactory, IOHelper, LocalizedTextService), ConfigurationEditorJsonSerializer, container.Id) + new DataType(new RadioButtonsPropertyEditor(DataValueEditorFactory, IOHelper, ConfigurationEditorJsonSerializer), ConfigurationEditorJsonSerializer, container.Id) { Name = "test" }; DataTypeRepository.Save(dataTypeDefinition); @@ -186,7 +184,7 @@ public class DataTypeDefinitionRepositoryTest : UmbracoIntegrationTest DataTypeContainerRepository.Save(container); IDataType dataType = - new DataType(new RadioButtonsPropertyEditor(DataValueEditorFactory, IOHelper, LocalizedTextService), ConfigurationEditorJsonSerializer, container.Id) + new DataType(new RadioButtonsPropertyEditor(DataValueEditorFactory, IOHelper, ConfigurationEditorJsonSerializer), ConfigurationEditorJsonSerializer, container.Id) { Name = "test" }; DataTypeRepository.Save(dataType); @@ -208,7 +206,7 @@ public class DataTypeDefinitionRepositoryTest : UmbracoIntegrationTest using (ScopeProvider.CreateScope()) { IDataType dataType = - new DataType(new RadioButtonsPropertyEditor(DataValueEditorFactory, IOHelper, LocalizedTextService), ConfigurationEditorJsonSerializer) + new DataType(new RadioButtonsPropertyEditor(DataValueEditorFactory, IOHelper, ConfigurationEditorJsonSerializer), ConfigurationEditorJsonSerializer) { Name = "test" }; DataTypeRepository.Save(dataType); @@ -252,7 +250,7 @@ public class DataTypeDefinitionRepositoryTest : UmbracoIntegrationTest Assert.That(dataTypeDefinitions, Is.Not.Null); Assert.That(dataTypeDefinitions.Any(), Is.True); Assert.That(dataTypeDefinitions.Any(x => x == null), Is.False); - Assert.That(dataTypeDefinitions.Length, Is.EqualTo(37)); + Assert.That(dataTypeDefinitions.Length, Is.EqualTo(35)); } } diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/DataTypeContainerServiceTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/DataTypeContainerServiceTests.cs index f05daf58df..02e3b82912 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/DataTypeContainerServiceTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/DataTypeContainerServiceTests.cs @@ -26,8 +26,6 @@ public class DataTypeContainerServiceTests : UmbracoIntegrationTest private IConfigurationEditorJsonSerializer ConfigurationEditorJsonSerializer => GetRequiredService(); - private IEditorConfigurationParser EditorConfigurationParser => GetRequiredService(); - [Test] public async Task Can_Create_Container_At_Root() { @@ -187,7 +185,7 @@ public class DataTypeContainerServiceTests : UmbracoIntegrationTest EntityContainer container = (await DataTypeContainerService.CreateAsync(null,"Root Container", null, Constants.Security.SuperUserKey)).Result; IDataType dataType = - new DataType(new TextboxPropertyEditor(DataValueEditorFactory, IOHelper, EditorConfigurationParser), ConfigurationEditorJsonSerializer) + new DataType(new TextboxPropertyEditor(DataValueEditorFactory, IOHelper), ConfigurationEditorJsonSerializer) { Name = Guid.NewGuid().ToString(), DatabaseType = ValueStorageType.Nvarchar, diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/DataTypeServiceTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/DataTypeServiceTests.cs index 829fae5e2c..bb916cf41c 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/DataTypeServiceTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/DataTypeServiceTests.cs @@ -35,8 +35,6 @@ public class DataTypeServiceTests : UmbracoIntegrationTest private IConfigurationEditorJsonSerializer ConfigurationEditorJsonSerializer => GetRequiredService(); - private IEditorConfigurationParser EditorConfigurationParser => GetRequiredService(); - [Test] public async Task Can_Create_New_DataTypeDefinition() { @@ -85,7 +83,7 @@ public class DataTypeServiceTests : UmbracoIntegrationTest async Task CreateTextBoxDataType() { IDataType dataType = - new DataType(new TextboxPropertyEditor(DataValueEditorFactory, IOHelper, EditorConfigurationParser), ConfigurationEditorJsonSerializer) + new DataType(new TextboxPropertyEditor(DataValueEditorFactory, IOHelper), ConfigurationEditorJsonSerializer) { Name = Guid.NewGuid().ToString(), DatabaseType = ValueStorageType.Nvarchar diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/EntityXmlSerializerTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/EntityXmlSerializerTests.cs index bf0c5705b6..d6a0fd2a5a 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/EntityXmlSerializerTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/EntityXmlSerializerTests.cs @@ -176,14 +176,12 @@ public class EntityXmlSerializerTests : UmbracoIntegrationTest scheme, loggerFactory.CreateLogger(), ShortStringHelper, - Services, - Options.Create(new ContentSettings())); + Services); var ignored = new FileUploadPropertyEditor( DataValueEditorFactory, mediaFileManager, Mock.Of>(x => x.CurrentValue == contentSettings), - TextService, Services.GetRequiredService(), ContentService, IOHelper); diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/ValueEditorCacheTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/ValueEditorCacheTests.cs index 3e1be18450..0c23b8f447 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/ValueEditorCacheTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Cache/ValueEditorCacheTests.cs @@ -107,14 +107,8 @@ public class ValueEditorCacheTests public string Alias { get; } - public EditorType Type { get; } - public string Name { get; } - public string Icon { get; } - - public string Group { get; } - public bool IsDeprecated { get; } public IDataValueEditor GetValueEditor() diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/TypeLoaderTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/TypeLoaderTests.cs index cafaf8b4da..69f90158ff 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/TypeLoaderTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/TypeLoaderTests.cs @@ -173,7 +173,7 @@ public class TypeLoaderTests public void GetDataEditors() { var types = _typeLoader.GetDataEditors(); - Assert.AreEqual(48, types.Count()); + Assert.AreEqual(36, types.Count()); } /// diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/DeliveryApi/MediaPickerValueConverterTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/DeliveryApi/MediaPickerValueConverterTests.cs deleted file mode 100644 index e569f94931..0000000000 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/DeliveryApi/MediaPickerValueConverterTests.cs +++ /dev/null @@ -1,103 +0,0 @@ -using Moq; -using NUnit.Framework; -using Umbraco.Cms.Core; -using Umbraco.Cms.Core.DeliveryApi; -using Umbraco.Cms.Core.Models.DeliveryApi; -using Umbraco.Cms.Core.Models.PublishedContent; -using Umbraco.Cms.Core.PropertyEditors; -using Umbraco.Cms.Core.PropertyEditors.ValueConverters; - -namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.DeliveryApi; - -[TestFixture] -public class MediaPickerValueConverterTests : PropertyValueConverterTests -{ - [Test] - public void MediaPickerValueConverter_InSingleMode_HasMultipleContentAsDeliveryApiType() - { - var publishedPropertyType = SetupMediaPropertyType(false); - var valueConverter = CreateMediaPickerValueConverter(); - - Assert.AreEqual(typeof(IEnumerable), valueConverter.GetDeliveryApiPropertyValueType(publishedPropertyType)); - } - - [Test] - public void MediaPickerValueConverter_InSingleMode_ConvertsValueToDeliveryApiContent() - { - var publishedPropertyType = SetupMediaPropertyType(false); - var valueConverter = CreateMediaPickerValueConverter(); - - var inter = new[] {new GuidUdi(Constants.UdiEntityType.MediaType, PublishedMedia.Key)}; - - var result = valueConverter.ConvertIntermediateToDeliveryApiObject(Mock.Of(), publishedPropertyType, PropertyCacheLevel.Element, inter, false, false) as IEnumerable; - - Assert.NotNull(result); - Assert.AreEqual(1, result.Count()); - Assert.AreEqual("The media", result.First().Name); - Assert.AreEqual(PublishedMedia.Key, result.First().Id); - Assert.AreEqual("the-media-url", result.First().Url); - Assert.AreEqual("TheMediaType", result.First().MediaType); - } - - [Test] - public void MediaPickerValueConverter_InMultiMode_HasMultipleContentAsDeliveryApiType() - { - var publishedPropertyType = SetupMediaPropertyType(true); - var valueConverter = CreateMediaPickerValueConverter(); - - Assert.AreEqual(typeof(IEnumerable), valueConverter.GetDeliveryApiPropertyValueType(publishedPropertyType)); - } - - [Test] - public void MediaPickerValueConverter_InMultiMode_ConvertsValuesToDeliveryApiContent() - { - var publishedPropertyType = SetupMediaPropertyType(true); - var valueConverter = CreateMediaPickerValueConverter(); - - var otherMediaKey = Guid.NewGuid(); - var otherMedia = SetupPublishedContent("The other media", otherMediaKey, PublishedItemType.Media, PublishedMediaType); - PublishedUrlProviderMock - .Setup(p => p.GetMediaUrl(otherMedia.Object, It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) - .Returns("the-other-media-url"); - PublishedMediaCacheMock - .Setup(pcc => pcc.GetById(otherMediaKey)) - .Returns(otherMedia.Object); - - var inter = new[] { new GuidUdi(Constants.UdiEntityType.MediaType, PublishedMedia.Key), new GuidUdi(Constants.UdiEntityType.MediaType, otherMediaKey) }; - - var result = valueConverter.ConvertIntermediateToDeliveryApiObject(Mock.Of(), publishedPropertyType, PropertyCacheLevel.Element, inter, false, false) as IEnumerable; - - Assert.NotNull(result); - Assert.AreEqual(2, result.Count()); - - Assert.AreEqual("The media", result.First().Name); - Assert.AreEqual(PublishedMedia.Key, result.First().Id); - Assert.AreEqual("the-media-url", result.First().Url); - Assert.AreEqual("TheMediaType", result.First().MediaType); - - Assert.AreEqual("The other media", result.Last().Name); - Assert.AreEqual(otherMediaKey, result.Last().Id); - Assert.AreEqual("the-other-media-url", result.Last().Url); - Assert.AreEqual("TheMediaType", result.Last().MediaType); - } - - private IPublishedPropertyType SetupMediaPropertyType(bool multiSelect) - { - var publishedDataType = new PublishedDataType(123, "test", new Lazy(() => - new MediaPickerConfiguration {Multiple = multiSelect} - )); - var publishedPropertyType = new Mock(); - publishedPropertyType.SetupGet(p => p.DataType).Returns(publishedDataType); - - return publishedPropertyType.Object; - } - - private MediaPickerValueConverter CreateMediaPickerValueConverter() => new( - PublishedSnapshotAccessor, - Mock.Of(), - new ApiMediaBuilder( - new ApiContentNameProvider(), - new ApiMediaUrlProvider(PublishedUrlProvider), - Mock.Of(), - CreateOutputExpansionStrategyAccessor())); -} diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/DeliveryApi/NestedContentValueConverterTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/DeliveryApi/NestedContentValueConverterTests.cs deleted file mode 100644 index aa31842bea..0000000000 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/DeliveryApi/NestedContentValueConverterTests.cs +++ /dev/null @@ -1,153 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using Microsoft.Extensions.Logging; -using Moq; -using NUnit.Framework; -using Umbraco.Cms.Core.DeliveryApi; -using Umbraco.Cms.Core.Logging; -using Umbraco.Cms.Core.Models.DeliveryApi; -using Umbraco.Cms.Core.Models.PublishedContent; -using Umbraco.Cms.Core.PropertyEditors; -using Umbraco.Cms.Core.PropertyEditors.ValueConverters; - -namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.DeliveryApi; - -[TestFixture] -public class NestedContentValueConverterTests : PropertyValueConverterTests -{ - private IPublishedModelFactory _publishedModelFactory; - private IApiElementBuilder _apiElementBuilder; - private NestedContentSingleValueConverter _nestedContentSingleValueConverter; - private NestedContentManyValueConverter _nestedContentManyValueConverter; - private IPublishedPropertyType _publishedPropertyType; - - [SetUp] - public void SetupThis() - { - var publishedModelFactoryMock = new Mock(); - publishedModelFactoryMock - .Setup(m => m.CreateModel(It.IsAny())) - .Returns((IPublishedElement element) => element); - _publishedModelFactory = publishedModelFactoryMock.Object; - - _apiElementBuilder = new ApiElementBuilder(CreateOutputExpansionStrategyAccessor()); - - var profilingLogger = new ProfilingLogger(Mock.Of>(), Mock.Of()); - - var publishedDataType = new PublishedDataType(123, "test", new Lazy(() => new NestedContentConfiguration { MaxItems = 1 })); - var publishedPropertyType = new Mock(); - publishedPropertyType.SetupGet(p => p.DataType).Returns(publishedDataType); - publishedPropertyType.SetupGet(p => p.Alias).Returns("prop1"); - publishedPropertyType.SetupGet(p => p.CacheLevel).Returns(PropertyCacheLevel.Element); - publishedPropertyType.SetupGet(p => p.DeliveryApiCacheLevel).Returns(PropertyCacheLevel.Element); - publishedPropertyType - .Setup(p => p.ConvertSourceToInter(It.IsAny(), It.IsAny(), It.IsAny())) - .Returns((IPublishedElement owner, object? source, bool preview) => source); - publishedPropertyType - .Setup(p => p.ConvertInterToDeliveryApiObject(It.IsAny(), PropertyCacheLevel.Element, It.IsAny(), It.IsAny(), It.IsAny())) - .Returns((IPublishedElement owner, PropertyCacheLevel referenceCacheLevel, object? inter, bool preview, bool expanding) => inter?.ToString()); - _publishedPropertyType = publishedPropertyType.Object; - - var publishedContentType = new Mock(); - publishedContentType.SetupGet(c => c.IsElement).Returns(true); - publishedContentType.SetupGet(c => c.Alias).Returns("contentType1"); - publishedContentType.SetupGet(c => c.PropertyTypes).Returns(new[] { publishedPropertyType.Object }); - - PublishedContentCacheMock - .Setup(m => m.GetContentType("contentType1")) - .Returns(publishedContentType.Object); - - _nestedContentSingleValueConverter = new NestedContentSingleValueConverter(PublishedSnapshotAccessor, _publishedModelFactory, profilingLogger, _apiElementBuilder); - _nestedContentManyValueConverter = new NestedContentManyValueConverter(PublishedSnapshotAccessor, _publishedModelFactory, profilingLogger, _apiElementBuilder); - } - - [Test] - public void NestedContentSingleValueConverter_HasMultipleElementsAsDeliveryApiType() - => Assert.AreEqual(typeof(IEnumerable), _nestedContentSingleValueConverter.GetDeliveryApiPropertyValueType(Mock.Of())); - - [Test] - public void NestedContentSingleValueConverter_WithOneItem_ConvertsItemToListOfElements() - { - var nestedContentValue = "[{\"ncContentTypeAlias\": \"contentType1\",\"key\": \"1E68FB92-727A-4473-B10C-FA108ADCF16F\",\"prop1\": \"Hello, world\"}]"; - var result = _nestedContentSingleValueConverter.ConvertIntermediateToDeliveryApiObject(Mock.Of(), _publishedPropertyType, PropertyCacheLevel.Element, nestedContentValue, false, false) as IEnumerable; - - Assert.IsNotNull(result); - Assert.AreEqual(1, result.Count()); - Assert.AreEqual("contentType1", result.First().ContentType); - Assert.AreEqual(Guid.Parse("1E68FB92-727A-4473-B10C-FA108ADCF16F"), result.First().Id); - Assert.AreEqual(1, result.First().Properties.Count); - Assert.AreEqual("Hello, world", result.First().Properties["prop1"]); - } - - [Test] - public void NestedContentSingleValueConverter_WithMultipleItems_ConvertsFirstItemToListOfElements() - { - var nestedContentValue = "[{\"ncContentTypeAlias\": \"contentType1\",\"key\": \"1E68FB92-727A-4473-B10C-FA108ADCF16F\",\"prop1\": \"Hello, world\"},{\"ncContentTypeAlias\": \"contentType1\",\"key\": \"40F59DD9-7E9F-4053-BD32-89FB086D18C9\",\"prop1\": \"One more\"}]"; - var result = _nestedContentSingleValueConverter.ConvertIntermediateToDeliveryApiObject(Mock.Of(), _publishedPropertyType, PropertyCacheLevel.Element, nestedContentValue, false, false) as IEnumerable; - - Assert.IsNotNull(result); - Assert.AreEqual(1, result.Count()); - Assert.AreEqual("contentType1", result.First().ContentType); - Assert.AreEqual(Guid.Parse("1E68FB92-727A-4473-B10C-FA108ADCF16F"), result.First().Id); - Assert.AreEqual(1, result.First().Properties.Count); - Assert.AreEqual("Hello, world", result.First().Properties["prop1"]); - } - - [Test] - public void NestedContentSingleValueConverter_WithNoData_ReturnsEmptyArray() - { - var result = _nestedContentSingleValueConverter.ConvertIntermediateToDeliveryApiObject(Mock.Of(), _publishedPropertyType, PropertyCacheLevel.Element, null, false, false) as IEnumerable; - - Assert.IsNotNull(result); - Assert.IsEmpty(result); - } - - [Test] - public void NestedContentManyValueConverter_HasMultipleElementsAsDeliveryApiType() - => Assert.AreEqual(typeof(IEnumerable), _nestedContentManyValueConverter.GetDeliveryApiPropertyValueType(Mock.Of())); - - - [Test] - public void NestedContentManyValueConverter_WithOneItem_ConvertsItemToListOfElements() - { - var nestedContentValue = "[{\"ncContentTypeAlias\": \"contentType1\",\"key\": \"1E68FB92-727A-4473-B10C-FA108ADCF16F\",\"prop1\": \"Hello, world\"}]"; - var result = _nestedContentManyValueConverter.ConvertIntermediateToDeliveryApiObject(Mock.Of(), _publishedPropertyType, PropertyCacheLevel.Element, nestedContentValue, false, false) as IEnumerable; - - Assert.IsNotNull(result); - Assert.AreEqual(1, result.Count()); - - Assert.AreEqual("contentType1", result.First().ContentType); - Assert.AreEqual(Guid.Parse("1E68FB92-727A-4473-B10C-FA108ADCF16F"), result.First().Id); - Assert.AreEqual(1, result.First().Properties.Count); - Assert.AreEqual("Hello, world", result.First().Properties["prop1"]); - } - - [Test] - public void NestedContentManyValueConverter_WithMultipleItems_ConvertsAllItemsToElements() - { - var nestedContentValue = "[{\"ncContentTypeAlias\": \"contentType1\",\"key\": \"1E68FB92-727A-4473-B10C-FA108ADCF16F\",\"prop1\": \"Hello, world\"},{\"ncContentTypeAlias\": \"contentType1\",\"key\": \"40F59DD9-7E9F-4053-BD32-89FB086D18C9\",\"prop1\": \"One more\"}]"; - var result = _nestedContentManyValueConverter.ConvertIntermediateToDeliveryApiObject(Mock.Of(), _publishedPropertyType, PropertyCacheLevel.Element, nestedContentValue, false, false) as IEnumerable; - - Assert.IsNotNull(result); - Assert.AreEqual(2, result.Count()); - - Assert.AreEqual("contentType1", result.First().ContentType); - Assert.AreEqual(Guid.Parse("1E68FB92-727A-4473-B10C-FA108ADCF16F"), result.First().Id); - Assert.AreEqual(1, result.First().Properties.Count); - Assert.AreEqual("Hello, world", result.First().Properties["prop1"]); - - Assert.AreEqual("contentType1", result.Last().ContentType); - Assert.AreEqual(Guid.Parse("40F59DD9-7E9F-4053-BD32-89FB086D18C9"), result.Last().Id); - Assert.AreEqual(1, result.Last().Properties.Count); - Assert.AreEqual("One more", result.Last().Properties["prop1"]); - } - - [Test] - public void NestedContentManyValueConverter_WithNoData_ReturnsEmptyArray() - { - var result = _nestedContentManyValueConverter.ConvertIntermediateToDeliveryApiObject(Mock.Of(), _publishedPropertyType, PropertyCacheLevel.Element, null, false, false) as IEnumerable; - - Assert.IsNotNull(result); - Assert.IsEmpty(result); - } -} diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/DeliveryApi/OutputExpansionStrategyTestBase.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/DeliveryApi/OutputExpansionStrategyTestBase.cs index f08ea5545e..44ea797058 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/DeliveryApi/OutputExpansionStrategyTestBase.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/DeliveryApi/OutputExpansionStrategyTestBase.cs @@ -383,8 +383,11 @@ public abstract class OutputExpansionStrategyTestBase : PropertyValueConverterTe internal PublishedElementPropertyBase CreateMediaPickerProperty(IPublishedElement parent, Guid pickedMediaKey, string propertyTypeAlias, IApiMediaBuilder mediaBuilder) { - MediaPickerValueConverter mediaPickerValueConverter = new MediaPickerValueConverter(PublishedSnapshotAccessor, Mock.Of(), mediaBuilder); - var mediaPickerPropertyType = SetupPublishedPropertyType(mediaPickerValueConverter, propertyTypeAlias, Constants.PropertyEditors.Aliases.MediaPicker, new MediaPickerConfiguration()); + var publishedValueFallback = Mock.Of(); + var apiMediaWithCropsBuilder = new ApiMediaWithCropsBuilder(mediaBuilder, publishedValueFallback); + + MediaPickerWithCropsValueConverter mediaPickerValueConverter = new MediaPickerWithCropsValueConverter(PublishedSnapshotAccessor, PublishedUrlProvider, publishedValueFallback, new JsonNetSerializer(), apiMediaWithCropsBuilder); + var mediaPickerPropertyType = SetupPublishedPropertyType(mediaPickerValueConverter, propertyTypeAlias, Constants.PropertyEditors.Aliases.MediaPicker3, new MediaPicker3Configuration()); return new PublishedElementPropertyBase(mediaPickerPropertyType, parent, false, PropertyCacheLevel.None, new GuidUdi(Constants.UdiEntityType.Media, pickedMediaKey).ToString()); } diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Manifest/LegacyManifestParserTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Manifest/LegacyManifestParserTests.cs index 10c69d3125..219d74c00a 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Manifest/LegacyManifestParserTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Manifest/LegacyManifestParserTests.cs @@ -53,41 +53,6 @@ public class LegacyManifestParserTests private LegacyManifestParser _parser; private IIOHelper _ioHelper; - [Test] - public void DelimitedValueValidator() - { - const string json = @"{'propertyEditors': [ - { - alias: 'Test.Test2', - name: 'Test 2', - isParameterEditor: true, - defaultConfig: { key1: 'some default val' }, - editor: { - view: '~/App_Plugins/MyPackage/PropertyEditors/MyEditor.html', - valueType: 'int', - validation: { - delimited: { - delimiter: ',', - pattern: '^[a-zA-Z]*$' - } - } - } - } -]}"; - - var manifest = _parser.ParseManifest(json); - - Assert.AreEqual(1, manifest.ParameterEditors.Length); - Assert.AreEqual(1, manifest.ParameterEditors[0].GetValueEditor().Validators.Count); - - Assert.IsTrue(manifest.ParameterEditors[0].GetValueEditor().Validators[0] is DelimitedValueValidator); - var validator = manifest.ParameterEditors[0].GetValueEditor().Validators[0] as DelimitedValueValidator; - - Assert.IsNotNull(validator.Configuration); - Assert.AreEqual(",", validator.Configuration.Delimiter); - Assert.AreEqual("^[a-zA-Z]*$", validator.Configuration.Pattern); - } - [Test] public void CanParseComments() { @@ -172,221 +137,6 @@ javascript: ['~/test.js',/*** some note about stuff asd09823-4**09234*/ '~/test2 Assert.AreEqual(2, manifest.Stylesheets.Length); } - [Test] - public void CanParseManifest_PropertyEditors() - { - const string json = @"{'propertyEditors': [ - { - alias: 'Test.Test1', - name: 'Test 1', - editor: { - view: '~/App_Plugins/MyPackage/PropertyEditors/MyEditor.html', - valueType: 'int', - hideLabel: true, - validation: { - 'required': true, - 'Regex': '\\d*' - } - }, - prevalues: { - fields: [ - { - label: 'Some config 1', - key: 'key1', - view: '~/App_Plugins/MyPackage/PropertyEditors/Views/pre-val1.html', - validation: { - required: true - } - }, - { - label: 'Some config 2', - key: 'key2', - view: '~/App_Plugins/MyPackage/PropertyEditors/Views/pre-val2.html' - } - ] - } - }, - { - alias: 'Test.Test2', - name: 'Test 2', - isParameterEditor: true, - defaultConfig: { key1: 'some default val' }, - editor: { - view: '~/App_Plugins/MyPackage/PropertyEditors/MyEditor.html', - valueType: 'int', - validation: { - required : true, - regex : '\\d*' - } - } - } -]}"; - - var manifest = _parser.ParseManifest(json); - Assert.AreEqual(2, manifest.PropertyEditors.Length); - - var editor = manifest.PropertyEditors[1]; - Assert.IsTrue((editor.Type & EditorType.MacroParameter) > 0); - Assert.IsNotEmpty(editor.DefaultConfiguration); - Assert.AreEqual("some default val", editor.DefaultConfiguration["key1"]); - - editor = manifest.PropertyEditors[0]; - Assert.AreEqual("Test.Test1", editor.Alias); - Assert.AreEqual("Test 1", editor.Name); - Assert.IsFalse((editor.Type & EditorType.MacroParameter) > 0); - - var valueEditor = editor.GetValueEditor(); - Assert.AreEqual(_ioHelper.ResolveUrl("/App_Plugins/MyPackage/PropertyEditors/MyEditor.html"), valueEditor.View); - Assert.AreEqual("int", valueEditor.ValueType); - Assert.IsTrue(valueEditor.HideLabel); - - // these two don't make much sense here - //// valueEditor.RegexValidator; - //// valueEditor.RequiredValidator; - - var validators = valueEditor.Validators; - Assert.AreEqual(2, validators.Count); - var validator = validators[0]; - var v1 = validator as RequiredValidator; - Assert.IsNotNull(v1); - Assert.AreEqual("Required", v1.ValidationName); - validator = validators[1]; - var v2 = validator as RegexValidator; - Assert.IsNotNull(v2); - Assert.AreEqual("Regex", v2.ValidationName); - Assert.AreEqual("\\d*", v2.Configuration); - - // this is not part of the manifest - var preValues = editor.GetConfigurationEditor().DefaultConfiguration; - Assert.IsEmpty(preValues); - - var preValueEditor = editor.GetConfigurationEditor(); - Assert.IsNotNull(preValueEditor); - Assert.IsNotNull(preValueEditor.Fields); - Assert.AreEqual(2, preValueEditor.Fields.Count); - - var f = preValueEditor.Fields[0]; - Assert.AreEqual("key1", f.Key); - Assert.AreEqual("Some config 1", f.Name); - Assert.AreEqual(_ioHelper.ResolveUrl("/App_Plugins/MyPackage/PropertyEditors/Views/pre-val1.html"), f.View); - var fvalidators = f.Validators; - Assert.IsNotNull(fvalidators); - Assert.AreEqual(1, fvalidators.Count); - var fv = fvalidators[0] as RequiredValidator; - Assert.IsNotNull(fv); - Assert.AreEqual("Required", fv.ValidationName); - - f = preValueEditor.Fields[1]; - Assert.AreEqual("key2", f.Key); - Assert.AreEqual("Some config 2", f.Name); - Assert.AreEqual(_ioHelper.ResolveUrl("/App_Plugins/MyPackage/PropertyEditors/Views/pre-val2.html"), f.View); - fvalidators = f.Validators; - Assert.IsNotNull(fvalidators); - Assert.AreEqual(0, fvalidators.Count); - } - - [Test] - public void CanParseManifest_ParameterEditors() - { - const string json = @"{'parameterEditors': [ - { - alias: 'parameter1', - name: 'My Parameter', - view: '~/App_Plugins/MyPackage/PropertyEditors/MyEditor.html' - }, - { - alias: 'parameter2', - name: 'Another parameter', - config: { key1: 'some config val' }, - view: '~/App_Plugins/MyPackage/PropertyEditors/CsvEditor.html' - }, - { - alias: 'parameter3', - name: 'Yet another parameter' - } -]}"; - - var manifest = _parser.ParseManifest(json); - Assert.AreEqual(3, manifest.ParameterEditors.Length); - - Assert.IsTrue(manifest.ParameterEditors.All(x => (x.Type & EditorType.MacroParameter) > 0)); - - var editor = manifest.ParameterEditors[1]; - Assert.AreEqual("parameter2", editor.Alias); - Assert.AreEqual("Another parameter", editor.Name); - - var config = editor.DefaultConfiguration; - Assert.AreEqual(1, config.Count); - Assert.IsTrue(config.ContainsKey("key1")); - Assert.AreEqual("some config val", config["key1"]); - - var valueEditor = editor.GetValueEditor(); - Assert.AreEqual(_ioHelper.ResolveUrl("/App_Plugins/MyPackage/PropertyEditors/CsvEditor.html"), valueEditor.View); - - editor = manifest.ParameterEditors[2]; - Assert.Throws(() => - { - var valueEditor = editor.GetValueEditor(); - }); - } - - [Test] - public void CanParseManifest_GridEditors() - { - const string json = @"{ - 'javascript': [ ], - 'css': [ ], - 'gridEditors': [ - { - 'name': 'Small Hero', - 'alias': 'small-hero', - 'view': '~/App_Plugins/MyPlugin/small-hero/editortemplate.html', - 'render': '~/Views/Partials/Grid/Editors/SmallHero.cshtml', - 'icon': 'icon-presentation', - 'config': { - 'image': { - 'size': { - 'width': 1200, - 'height': 185 - } - }, - 'link': { - 'maxNumberOfItems': 1, - 'minNumberOfItems': 0 - } - } - }, - { - 'name': 'Document Links By Category', - 'alias': 'document-links-by-category', - 'view': '~/App_Plugins/MyPlugin/document-links-by-category/editortemplate.html', - 'render': '~/Views/Partials/Grid/Editors/DocumentLinksByCategory.cshtml', - 'icon': 'icon-umb-members' - } - ] -}"; - var manifest = _parser.ParseManifest(json); - Assert.AreEqual(2, manifest.GridEditors.Length); - - var editor = manifest.GridEditors[0]; - Assert.AreEqual("small-hero", editor.Alias); - Assert.AreEqual("Small Hero", editor.Name); - Assert.AreEqual(_ioHelper.ResolveUrl("/App_Plugins/MyPlugin/small-hero/editortemplate.html"), editor.View); - Assert.AreEqual(_ioHelper.ResolveUrl("/Views/Partials/Grid/Editors/SmallHero.cshtml"), editor.Render); - Assert.AreEqual("icon-presentation", editor.Icon); - - var config = editor.Config; - Assert.AreEqual(2, config.Count); - Assert.IsTrue(config.ContainsKey("image")); - var c = config["image"]; - Assert.IsInstanceOf(c); // TODO: is this what we want? - Assert.IsTrue(config.ContainsKey("link")); - c = config["link"]; - Assert.IsInstanceOf(c); // TODO: is this what we want? - - // TODO: should we resolveUrl in configs? - } - [Test] public void CanParseManifest_ContentApps() { @@ -521,45 +271,4 @@ javascript: ['~/test.js',/*** some note about stuff asd09823-4**09234*/ '~/test2 var manifest = _parser.ParseManifest(json); Assert.IsTrue(manifest.ParameterEditors.FirstOrDefault().SupportsReadOnly); } - - [Test] - public void CanParseManifest_PropertyEditors_SupportsReadOnly() - { - const string json = @"{'propertyEditors': [ - { - alias: 'Test.Test1', - name: 'Test 1', - supportsReadOnly: true, - editor: { - view: '~/App_Plugins/MyPackage/PropertyEditors/MyEditor.html', - valueType: 'int', - hideLabel: true, - validation: { - 'required': true, - 'Regex': '\\d*' - } - }, - prevalues: { - fields: [ - { - label: 'Some config 1', - key: 'key1', - view: '~/App_Plugins/MyPackage/PropertyEditors/Views/pre-val1.html', - validation: { - required: true - } - }, - { - label: 'Some config 2', - key: 'key2', - view: '~/App_Plugins/MyPackage/PropertyEditors/Views/pre-val2.html' - } - ] - } - }]}"; - - - var manifest = _parser.ParseManifest(json); - Assert.IsTrue(manifest.PropertyEditors.FirstOrDefault().SupportsReadOnly); - } } diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Models/VariationTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Models/VariationTests.cs index e4698b9a39..ecaaa1b61e 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Models/VariationTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Models/VariationTests.cs @@ -624,9 +624,8 @@ public class VariationTests { var ioHelper = Mock.Of(); var dataTypeService = Mock.Of(); - var editorConfigurationParser = Mock.Of(); - var attribute = new DataEditorAttribute("a", "a", "a"); + var attribute = new DataEditorAttribute("a"); var dataValueEditorFactory = Mock.Of(x => x.Create(It.IsAny()) == new TextOnlyValueEditor( attribute, @@ -636,8 +635,7 @@ public class VariationTests var textBoxEditor = new TextboxPropertyEditor( dataValueEditorFactory, - ioHelper, - editorConfigurationParser); + ioHelper); var serializer = new ConfigurationEditorJsonSerializer(); diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/ColorListValidatorTest.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/ColorListValidatorTest.cs index fb16320bfe..c6e8fd5cf3 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/ColorListValidatorTest.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/ColorListValidatorTest.cs @@ -1,15 +1,10 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using System.Linq; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Abstractions; -using Moq; -using Newtonsoft.Json.Linq; +using System.Text.Json.Nodes; using NUnit.Framework; -using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.PropertyEditors; -using Umbraco.Cms.Core.Services; +using Umbraco.Cms.Core.Serialization; using Umbraco.Cms.Infrastructure.Serialization; namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.PropertyEditors; @@ -17,51 +12,46 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.PropertyEditors; [TestFixture] public class ColorListValidatorTest { - private readonly ILoggerFactory _loggerFactory = NullLoggerFactory.Instance; - - private ColorPickerPropertyEditor ColorPickerPropertyEditor => new( - Mock.Of(), - Mock.Of(), - new JsonNetSerializer(), - Mock.Of()); + private IConfigurationEditorJsonSerializer ConfigurationEditorJsonSerializer() + => new SystemTextConfigurationEditorJsonSerializer(); [Test] - public void Only_Tests_On_JArray() + public void Expects_Array_Of_ColorPickerItems_Not_Single_String() { - var validator = new ColorPickerConfigurationEditor.ColorListValidator(); + var validator = new ColorPickerConfigurationEditor.ColorListValidator(ConfigurationEditorJsonSerializer()); var result = validator.Validate( "hello", null, - ColorPickerPropertyEditor); - Assert.AreEqual(0, result.Count()); + null); + Assert.AreEqual(1, result.Count()); } [Test] - public void Only_Tests_On_JArray_Of_Item_JObject() + public void Expects_Array_Of_ColorPickerItems_Not_Array_Of_String() { - var validator = new ColorPickerConfigurationEditor.ColorListValidator(); + var validator = new ColorPickerConfigurationEditor.ColorListValidator(ConfigurationEditorJsonSerializer()); var result = validator.Validate( - new JArray("hello", "world"), + new JsonArray("hello", "world"), null, - ColorPickerPropertyEditor); - Assert.AreEqual(0, result.Count()); + null); + Assert.AreEqual(1, result.Count()); } [Test] public void Validates_Color_Vals() { - var validator = new ColorPickerConfigurationEditor.ColorListValidator(); + var validator = new ColorPickerConfigurationEditor.ColorListValidator(ConfigurationEditorJsonSerializer()); var result = validator.Validate( - new JArray( - JObject.FromObject(new { value = "CC0000" }), - JObject.FromObject(new { value = "zxcvzxcvxzcv" }), - JObject.FromObject(new { value = "ABC" }), - JObject.FromObject(new { value = "1234567" })), + new JsonArray( + JsonNode.Parse("""{"value": "CC0000", "label": "One"}"""), + JsonNode.Parse("""{"value": "zxcvzxcvxzcv", "label": "Two"}"""), + JsonNode.Parse("""{"value": "ABC", "label": "Three"}"""), + JsonNode.Parse("""{"value": "1234567", "label": "Four"}""")), null, - ColorPickerPropertyEditor); + null); Assert.AreEqual(2, result.Count()); } } diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/DataValueEditorReuseTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/DataValueEditorReuseTests.cs index d7758ce05b..31c1e82c77 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/DataValueEditorReuseTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/DataValueEditorReuseTests.cs @@ -25,7 +25,7 @@ public class DataValueEditorReuseTests _dataValueEditorFactoryMock .Setup(m => m.Create(It.IsAny())) .Returns(() => new TextOnlyValueEditor( - new DataEditorAttribute("a", "b", "c"), + new DataEditorAttribute("a"), Mock.Of(), Mock.Of(), Mock.Of())); @@ -37,7 +37,7 @@ public class DataValueEditorReuseTests .Setup(m => m.Create(It.IsAny(), It.IsAny>())) .Returns(() => new BlockListPropertyEditorBase.BlockListEditorPropertyValueEditor( - new DataEditorAttribute("a", "b", "c"), + new DataEditorAttribute("a"), new BlockListEditorDataConverter(Mock.Of()), _propertyEditorCollection, _dataValueReferenceFactories, @@ -56,8 +56,7 @@ public class DataValueEditorReuseTests { var textboxPropertyEditor = new TextboxPropertyEditor( _dataValueEditorFactoryMock.Object, - Mock.Of(), - Mock.Of()); + Mock.Of()); // textbox is set to reuse its data value editor when created *without* configuration var dataValueEditor1 = textboxPropertyEditor.GetValueEditor(); @@ -75,8 +74,7 @@ public class DataValueEditorReuseTests { var textboxPropertyEditor = new TextboxPropertyEditor( _dataValueEditorFactoryMock.Object, - Mock.Of(), - Mock.Of()); + Mock.Of()); // no matter what, a property editor should never reuse its data value editor when created *with* configuration var dataValueEditor1 = textboxPropertyEditor.GetValueEditor("config"); @@ -98,7 +96,6 @@ public class DataValueEditorReuseTests _dataValueEditorFactoryMock.Object, _propertyEditorCollection, Mock.Of(), - Mock.Of(), Mock.Of(), Mock.Of()); @@ -120,7 +117,6 @@ public class DataValueEditorReuseTests _dataValueEditorFactoryMock.Object, _propertyEditorCollection, Mock.Of(), - Mock.Of(), Mock.Of(), Mock.Of()); diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/DataValueReferenceFactoryCollectionTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/DataValueReferenceFactoryCollectionTests.cs index 38fc5125dc..69b35b4399 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/DataValueReferenceFactoryCollectionTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/DataValueReferenceFactoryCollectionTests.cs @@ -8,9 +8,11 @@ using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models.Editors; using Umbraco.Cms.Core.PropertyEditors; +using Umbraco.Cms.Core.Security; using Umbraco.Cms.Core.Serialization; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Strings; +using Umbraco.Cms.Infrastructure.Scoping; using Umbraco.Cms.Infrastructure.Serialization; using Umbraco.Extensions; using static Umbraco.Cms.Core.Models.Property; @@ -21,21 +23,24 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.PropertyEditors; public class DataValueReferenceFactoryCollectionTests { private IDataValueEditorFactory DataValueEditorFactory { get; } = Mock.Of( - x => x.Create(It.IsAny()) + x => x.Create(It.IsAny()) == - new MediaPickerPropertyEditor.MediaPickerPropertyValueEditor( - Mock.Of(), + new MediaPicker3PropertyEditor.MediaPicker3PropertyValueEditor( Mock.Of(), Mock.Of(), Mock.Of(), - new DataEditorAttribute("a", "a", "a"))); + new DataEditorAttribute("a"), + Mock.Of(), + Mock.Of(), + Mock.Of(), + Mock.Of(), + Mock.Of(), + Mock.Of())); private IIOHelper IOHelper { get; } = Mock.Of(); private IShortStringHelper ShortStringHelper { get; } = Mock.Of(); - private IEditorConfigurationParser EditorConfigurationParser { get; } = Mock.Of(); - [Test] public void GetAllReferences_All_Variants_With_IDataValueReferenceFactory() { @@ -44,8 +49,7 @@ public class DataValueReferenceFactoryCollectionTests // label does not implement IDataValueReference var labelEditor = new LabelPropertyEditor( DataValueEditorFactory, - IOHelper, - EditorConfigurationParser); + IOHelper); var propertyEditors = new PropertyEditorCollection(new DataEditorCollection(() => labelEditor.Yield())); var trackedUdi1 = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString(); var trackedUdi2 = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString(); @@ -87,10 +91,9 @@ public class DataValueReferenceFactoryCollectionTests var collection = new DataValueReferenceFactoryCollection(() => Enumerable.Empty()); // mediaPicker does implement IDataValueReference - var mediaPicker = new MediaPickerPropertyEditor( + var mediaPicker = new MediaPicker3PropertyEditor( DataValueEditorFactory, - IOHelper, - EditorConfigurationParser); + IOHelper); var propertyEditors = new PropertyEditorCollection(new DataEditorCollection(() => mediaPicker.Yield())); var trackedUdi1 = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString(); var trackedUdi2 = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString(); @@ -132,10 +135,9 @@ public class DataValueReferenceFactoryCollectionTests var collection = new DataValueReferenceFactoryCollection(() => Enumerable.Empty()); // mediaPicker does implement IDataValueReference - var mediaPicker = new MediaPickerPropertyEditor( + var mediaPicker = new MediaPicker3PropertyEditor( DataValueEditorFactory, - IOHelper, - EditorConfigurationParser); + IOHelper); var propertyEditors = new PropertyEditorCollection(new DataEditorCollection(() => mediaPicker.Yield())); var trackedUdi1 = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString(); var trackedUdi2 = Udi.Create(Constants.UdiEntityType.Media, Guid.NewGuid()).ToString(); @@ -188,7 +190,7 @@ public class DataValueReferenceFactoryCollectionTests { var collection = new DataValueReferenceFactoryCollection(() => new TestDataValueReferenceFactory().Yield()); - var labelPropertyEditor = new LabelPropertyEditor(DataValueEditorFactory, IOHelper, EditorConfigurationParser); + var labelPropertyEditor = new LabelPropertyEditor(DataValueEditorFactory, IOHelper); var propertyEditors = new PropertyEditorCollection(new DataEditorCollection(() => labelPropertyEditor.Yield())); var serializer = new ConfigurationEditorJsonSerializer(); diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/DecimalValueEditorTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/DecimalValueEditorTests.cs index 5acd0c0286..18254d923e 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/DecimalValueEditorTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/DecimalValueEditorTests.cs @@ -87,11 +87,10 @@ public class DecimalValueEditorTests private static DecimalPropertyEditor.DecimalPropertyValueEditor CreateValueEditor() { var valueEditor = new DecimalPropertyEditor.DecimalPropertyValueEditor( - Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), - new DataEditorAttribute("alias", "name", "view")); + new DataEditorAttribute("alias")); return valueEditor; } -} \ No newline at end of file +} diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/EnsureUniqueValuesValidatorTest.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/EnsureUniqueValuesValidatorTest.cs index 5afcf793de..75a8b94dfa 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/EnsureUniqueValuesValidatorTest.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/EnsureUniqueValuesValidatorTest.cs @@ -1,15 +1,10 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using System.Linq; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Abstractions; -using Moq; -using Newtonsoft.Json.Linq; +using System.Text.Json.Nodes; using NUnit.Framework; -using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.PropertyEditors; -using Umbraco.Cms.Core.Services; +using Umbraco.Cms.Core.Serialization; using Umbraco.Cms.Infrastructure.Serialization; namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.PropertyEditors; @@ -17,83 +12,73 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.PropertyEditors; [TestFixture] public class EnsureUniqueValuesValidatorTest { - private readonly ILoggerFactory _loggerFactory = NullLoggerFactory.Instance; - - private ColorPickerPropertyEditor ColorPickerPropertyEditor => new( - Mock.Of(), - Mock.Of(), - new JsonNetSerializer(), - Mock.Of()); + private IConfigurationEditorJsonSerializer ConfigurationEditorJsonSerializer() + => new SystemTextConfigurationEditorJsonSerializer(); [Test] - public void Only_Tests_On_JArray() + public void Expects_Array_Of_ValueListItems_Not_Single_String() { - var validator = new ValueListUniqueValueValidator(); - var result = - validator.Validate( - "hello", - null, - new ColorPickerPropertyEditor( - Mock.Of(), - Mock.Of(), - new JsonNetSerializer(), - Mock.Of())); - Assert.AreEqual(0, result.Count()); + var validator = new ValueListUniqueValueValidator(ConfigurationEditorJsonSerializer()); + var result = validator.Validate( + "hello", + null, + null); + Assert.AreEqual(1, result.Count()); } [Test] - public void Only_Tests_On_JArray_Of_Item_JObject() + public void Expects_Array_Of_ValueListItems_Not_Array_Of_String() { - var validator = new ValueListUniqueValueValidator(); + var validator = new ValueListUniqueValueValidator(ConfigurationEditorJsonSerializer()); var result = validator.Validate( - new JArray("hello", "world"), + new JsonArray("hello", "world"), null, - ColorPickerPropertyEditor); - Assert.AreEqual(0, result.Count()); + null); + Assert.AreEqual(1, result.Count()); } [Test] public void Allows_Unique_Values() { - var validator = new ValueListUniqueValueValidator(); + var validator = new ValueListUniqueValueValidator(ConfigurationEditorJsonSerializer()); var result = validator.Validate( - new JArray( - JObject.FromObject(new { value = "hello" }), - JObject.FromObject(new { value = "world" })), + new JsonArray( + JsonNode.Parse("""{"value": "hello"}"""), + JsonNode.Parse("""{"value": "world"}""")), null, - ColorPickerPropertyEditor); + null); Assert.AreEqual(0, result.Count()); } [Test] public void Does_Not_Allow_Multiple_Values() { - var validator = new ValueListUniqueValueValidator(); + var validator = new ValueListUniqueValueValidator(ConfigurationEditorJsonSerializer()); var result = validator.Validate( - new JArray( - JObject.FromObject(new { value = "hello" }), - JObject.FromObject(new { value = "hello" })), + new JsonArray( + JsonNode.Parse("""{"value": "hello"}"""), + JsonNode.Parse("""{"value": "hello"}""")), null, - ColorPickerPropertyEditor); + null); Assert.AreEqual(1, result.Count()); } [Test] public void Validates_Multiple_Duplicate_Values() { - var validator = new ValueListUniqueValueValidator(); + var validator = new ValueListUniqueValueValidator(ConfigurationEditorJsonSerializer()); var result = validator.Validate( - new JArray( - JObject.FromObject(new { value = "hello" }), - JObject.FromObject(new { value = "hello" }), - JObject.FromObject(new { value = "world" }), - JObject.FromObject(new { value = "world" })), + new JsonArray( + JsonNode.Parse("""{"value": "hello"}"""), + JsonNode.Parse("""{"value": "hello"}"""), + JsonNode.Parse("""{"value": "world"}"""), + JsonNode.Parse("""{"value": "world"}""")), null, - ColorPickerPropertyEditor); + null); Assert.AreEqual(2, result.Count()); } } diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/MultiNodeTreePickerTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/MultiNodeTreePickerTests.cs index a45d8d2c73..e551c66af5 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/MultiNodeTreePickerTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/MultiNodeTreePickerTests.cs @@ -204,11 +204,10 @@ public class MultiNodeTreePickerTests private static MultiNodeTreePickerPropertyEditor.MultiNodeTreePickerPropertyValueEditor CreateValueEditor() { var valueEditor = new MultiNodeTreePickerPropertyEditor.MultiNodeTreePickerPropertyValueEditor( - Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), - new DataEditorAttribute("alias", "name", "view")); + new DataEditorAttribute("alias")); return valueEditor; } } diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/MultiValuePropertyEditorTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/MultiValuePropertyEditorTests.cs index eaf8661041..c31ddb88bc 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/MultiValuePropertyEditorTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/MultiValuePropertyEditorTests.cs @@ -33,9 +33,7 @@ public class MultiValuePropertyEditorTests var serializer = new ConfigurationEditorJsonSerializer(); var checkBoxListPropertyEditor = new CheckBoxListPropertyEditor( dataValueEditorFactoryMock.Object, - Mock.Of(), - Mock.Of(), - Mock.Of()); + Mock.Of(), serializer); var dataType = new DataType(checkBoxListPropertyEditor, serializer) { Id = 1, @@ -46,9 +44,9 @@ public class MultiValuePropertyEditorTests { Items = new List { - new() { Id = 4567, Value = "Value 1" }, - new() { Id = 1234, Value = "Value 2" }, - new() { Id = 8910, Value = "Value 3" }, + new() { Value = "Value 1" }, + new() { Value = "Value 2" }, + new() { Value = "Value 3" }, }, }, serializer); @@ -68,7 +66,7 @@ public class MultiValuePropertyEditorTests Mock.Of(), Mock.Of(), Mock.Of(), - new DataEditorAttribute(Constants.PropertyEditors.Aliases.TextBox, "Test Textbox", "textbox")); + new DataEditorAttribute(Constants.PropertyEditors.Aliases.TextBox)); dataValueEditorFactoryMock .Setup(x => x.Create(It.IsAny())) .Returns(multipleValueEditor); @@ -91,9 +89,7 @@ public class MultiValuePropertyEditorTests var serializer = new ConfigurationEditorJsonSerializer(); var checkBoxListPropertyEditor = new CheckBoxListPropertyEditor( dataValueEditorFactoryMock.Object, - Mock.Of(), - Mock.Of(), - Mock.Of()); + Mock.Of(), serializer); var dataType = new DataType(checkBoxListPropertyEditor, serializer) { Id = 1, @@ -104,9 +100,9 @@ public class MultiValuePropertyEditorTests { Items = new List { - new() { Id = 4567, Value = "Value 1" }, - new() { Id = 1234, Value = "Value 2" }, - new() { Id = 8910, Value = "Value 3" }, + new() { Value = "Value 1" }, + new() { Value = "Value 2" }, + new() { Value = "Value 3" }, }, }, serializer); @@ -126,7 +122,7 @@ public class MultiValuePropertyEditorTests Mock.Of(), Mock.Of(), Mock.Of(), - new DataEditorAttribute(Constants.PropertyEditors.Aliases.TextBox, "Test Textbox", "textbox")); + new DataEditorAttribute(Constants.PropertyEditors.Aliases.TextBox)); dataValueEditorFactoryMock .Setup(x => x.Create(It.IsAny())) .Returns(multipleValueEditor); @@ -147,9 +143,7 @@ public class MultiValuePropertyEditorTests var serializer = new ConfigurationEditorJsonSerializer(); var checkBoxListPropertyEditor = new CheckBoxListPropertyEditor( dataValueEditorFactoryMock.Object, - Mock.Of(), - Mock.Of(), - Mock.Of()); + Mock.Of(), serializer); var dataType = new DataType(checkBoxListPropertyEditor, serializer) { Id = 1, @@ -160,9 +154,9 @@ public class MultiValuePropertyEditorTests { Items = new List { - new() { Id = 1, Value = "Item 1" }, - new() { Id = 2, Value = "Item 2" }, - new() { Id = 3, Value = "Item 3" }, + new() { Value = "Item 1" }, + new() { Value = "Item 2" }, + new() { Value = "Item 3" }, }, }, serializer); @@ -173,11 +167,8 @@ public class MultiValuePropertyEditorTests Assert.NotNull(result); Assert.AreEqual(3, result.Items.Count); - Assert.AreEqual(1, result.Items[0].Id); Assert.AreEqual("Item 1", result.Items[0].Value); - Assert.AreEqual(2, result.Items[1].Id); Assert.AreEqual("Item 2", result.Items[1].Value); - Assert.AreEqual(3, result.Items[2].Id); Assert.AreEqual("Item 3", result.Items[2].Value); } } diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/MultipleTextStringValueEditorTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/MultipleTextStringValueEditorTests.cs index b78a6a41af..94452a2ec4 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/MultipleTextStringValueEditorTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/MultipleTextStringValueEditorTests.cs @@ -133,7 +133,7 @@ public class MultipleTextStringValueEditorTests Mock.Of(), Mock.Of(), Mock.Of(), - new DataEditorAttribute("alias", "name", "view")); + new DataEditorAttribute("alias")); return valueEditor; } } diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/NestedContentPropertyComponentTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/NestedContentPropertyComponentTests.cs deleted file mode 100644 index bf994155b4..0000000000 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/NestedContentPropertyComponentTests.cs +++ /dev/null @@ -1,430 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using NUnit.Framework; -using Umbraco.Cms.Core.PropertyEditors; - -namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.PropertyEditors; - -[TestFixture] -public class NestedContentPropertyComponentTests -{ - private static void AreEqualJson(string expected, string actual) => - Assert.AreEqual(JToken.Parse(expected), JToken.Parse(actual)); - - [Test] - public void Invalid_Json() - { - var component = new NestedContentPropertyHandler(); - - Assert.DoesNotThrow(() => component.CreateNestedContentKeys("this is not json", true)); - } - - [Test] - public void No_Nesting() - { - Guid[] guids = { Guid.NewGuid(), Guid.NewGuid() }; - var guidCounter = 0; - - Guid GuidFactory() - { - return guids[guidCounter++]; - } - - var json = @"[ - {""key"":""04a6dba8-813c-4144-8aca-86a3f24ebf08"",""name"":""Item 1"",""ncContentTypeAlias"":""nested"",""text"":""woot""}, - {""key"":""d8e214d8-c5a5-4b45-9b51-4050dd47f5fa"",""name"":""Item 2"",""ncContentTypeAlias"":""nested"",""text"":""zoot""} - ]"; - var expected = json - .Replace("04a6dba8-813c-4144-8aca-86a3f24ebf08", guids[0].ToString()) - .Replace("d8e214d8-c5a5-4b45-9b51-4050dd47f5fa", guids[1].ToString()); - - var component = new NestedContentPropertyHandler(); - var actual = component.CreateNestedContentKeys(json, false, GuidFactory); - - AreEqualJson(expected, actual); - } - - [Test] - public void One_Level_Nesting_Unescaped() - { - Guid[] guids = { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() }; - var guidCounter = 0; - - Guid GuidFactory() - { - return guids[guidCounter++]; - } - - var json = @"[{ - ""key"": ""04a6dba8-813c-4144-8aca-86a3f24ebf08"", - ""name"": ""Item 1"", - ""ncContentTypeAlias"": ""text"", - ""text"": ""woot"" - }, { - ""key"": ""d8e214d8-c5a5-4b45-9b51-4050dd47f5fa"", - ""name"": ""Item 2"", - ""ncContentTypeAlias"": ""list"", - ""text"": ""zoot"", - ""subItems"": [{ - ""key"": ""dccf550c-3a05-469e-95e1-a8f560f788c2"", - ""name"": ""Item 1"", - ""ncContentTypeAlias"": ""text"", - ""text"": ""woot"" - }, { - ""key"": ""fbde4288-8382-4e13-8933-ed9c160de050"", - ""name"": ""Item 2"", - ""ncContentTypeAlias"": ""text"", - ""text"": ""zoot"" - }] - }]"; - - var expected = json - .Replace("04a6dba8-813c-4144-8aca-86a3f24ebf08", guids[0].ToString()) - .Replace("d8e214d8-c5a5-4b45-9b51-4050dd47f5fa", guids[1].ToString()) - .Replace("dccf550c-3a05-469e-95e1-a8f560f788c2", guids[2].ToString()) - .Replace("fbde4288-8382-4e13-8933-ed9c160de050", guids[3].ToString()); - - var component = new NestedContentPropertyHandler(); - var actual = component.CreateNestedContentKeys(json, false, GuidFactory); - - AreEqualJson(expected, actual); - } - - [Test] - public void One_Level_Nesting_Escaped() - { - Guid[] guids = { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() }; - var guidCounter = 0; - - Guid GuidFactory() - { - return guids[guidCounter++]; - } - - // we need to ensure the escaped json is consistent with how it will be re-escaped after parsing - // and this is how to do that, the result will also include quotes around it. - var subJsonEscaped = JsonConvert.ToString(JToken.Parse(@" - [{ - ""key"": ""dccf550c-3a05-469e-95e1-a8f560f788c2"", - ""name"": ""Item 1"", - ""ncContentTypeAlias"": ""text"", - ""text"": ""woot"" - }, { - ""key"": ""fbde4288-8382-4e13-8933-ed9c160de050"", - ""name"": ""Item 2"", - ""ncContentTypeAlias"": ""text"", - ""text"": ""zoot"" - } - ]").ToString(Formatting.None)); - - var json = @"[{ - ""key"": ""04a6dba8-813c-4144-8aca-86a3f24ebf08"", - ""name"": ""Item 1"", - ""ncContentTypeAlias"": ""text"", - ""text"": ""woot"" - }, { - ""key"": ""d8e214d8-c5a5-4b45-9b51-4050dd47f5fa"", - ""name"": ""Item 2"", - ""ncContentTypeAlias"": ""list"", - ""text"": ""zoot"", - ""subItems"":" + subJsonEscaped + @" - } - ]"; - - var expected = json - .Replace("04a6dba8-813c-4144-8aca-86a3f24ebf08", guids[0].ToString()) - .Replace("d8e214d8-c5a5-4b45-9b51-4050dd47f5fa", guids[1].ToString()) - .Replace("dccf550c-3a05-469e-95e1-a8f560f788c2", guids[2].ToString()) - .Replace("fbde4288-8382-4e13-8933-ed9c160de050", guids[3].ToString()); - - var component = new NestedContentPropertyHandler(); - var actual = component.CreateNestedContentKeys(json, false, GuidFactory); - - AreEqualJson(expected, actual); - } - - [Test] - public void Nested_In_Complex_Editor_Escaped() - { - Guid[] guids = { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() }; - var guidCounter = 0; - - Guid GuidFactory() - { - return guids[guidCounter++]; - } - - // we need to ensure the escaped json is consistent with how it will be re-escaped after parsing - // and this is how to do that, the result will also include quotes around it. - var subJsonEscaped = JsonConvert.ToString(JToken.Parse(@"[{ - ""key"": ""dccf550c-3a05-469e-95e1-a8f560f788c2"", - ""name"": ""Item 1"", - ""ncContentTypeAlias"": ""text"", - ""text"": ""woot"" - }, { - ""key"": ""fbde4288-8382-4e13-8933-ed9c160de050"", - ""name"": ""Item 2"", - ""ncContentTypeAlias"": ""text"", - ""text"": ""zoot"" - } - ]").ToString(Formatting.None)); - - // Complex editor such as the grid - var complexEditorJsonEscaped = @"{ - ""name"": ""1 column layout"", - ""sections"": [ - { - ""grid"": ""12"", - ""rows"": [ - { - ""name"": ""Article"", - ""id"": ""b4f6f651-0de3-ef46-e66a-464f4aaa9c57"", - ""areas"": [ - { - ""grid"": ""4"", - ""controls"": [ - { - ""value"": ""I am quote"", - ""editor"": { - ""alias"": ""quote"", - ""view"": ""textstring"" - }, - ""styles"": null, - ""config"": null - }], - ""styles"": null, - ""config"": null - }, - { - ""grid"": ""8"", - ""controls"": [ - { - ""value"": ""Header"", - ""editor"": { - ""alias"": ""headline"", - ""view"": ""textstring"" - }, - ""styles"": null, - ""config"": null - }, - { - ""value"": " + subJsonEscaped + @", - ""editor"": { - ""alias"": ""madeUpNestedContent"", - ""view"": ""madeUpNestedContentInGrid"" - }, - ""styles"": null, - ""config"": null - }], - ""styles"": null, - ""config"": null - }], - ""styles"": null, - ""config"": null - }] - }] -}"; - - var json = @"[{ - ""key"": ""04a6dba8-813c-4144-8aca-86a3f24ebf08"", - ""name"": ""Item 1"", - ""ncContentTypeAlias"": ""text"", - ""text"": ""woot"" - }, { - ""key"": ""d8e214d8-c5a5-4b45-9b51-4050dd47f5fa"", - ""name"": ""Item 2"", - ""ncContentTypeAlias"": ""list"", - ""text"": ""zoot"", - ""subItems"":" + complexEditorJsonEscaped + @" - } -]"; - - var expected = json - .Replace("04a6dba8-813c-4144-8aca-86a3f24ebf08", guids[0].ToString()) - .Replace("d8e214d8-c5a5-4b45-9b51-4050dd47f5fa", guids[1].ToString()) - .Replace("dccf550c-3a05-469e-95e1-a8f560f788c2", guids[2].ToString()) - .Replace("fbde4288-8382-4e13-8933-ed9c160de050", guids[3].ToString()); - - var component = new NestedContentPropertyHandler(); - var actual = component.CreateNestedContentKeys(json, false, GuidFactory); - - AreEqualJson(expected, actual); - } - - [Test] - public void No_Nesting_Generates_Keys_For_Missing_Items() - { - Guid[] guids = { Guid.NewGuid() }; - var guidCounter = 0; - - Guid GuidFactory() - { - return guids[guidCounter++]; - } - - var json = @"[ - {""key"":""04a6dba8-813c-4144-8aca-86a3f24ebf08"",""name"":""Item 1 my key wont change"",""ncContentTypeAlias"":""nested"",""text"":""woot""}, - {""name"":""Item 2 was copied and has no key prop"",""ncContentTypeAlias"":""nested"",""text"":""zoot""} -]"; - - var component = new NestedContentPropertyHandler(); - var result = component.CreateNestedContentKeys(json, true, GuidFactory); - - // Ensure the new GUID is put in a key into the JSON - Assert.IsTrue(result.Contains(guids[0].ToString())); - - // Ensure that the original key is NOT changed/modified & still exists - Assert.IsTrue(result.Contains("04a6dba8-813c-4144-8aca-86a3f24ebf08")); - } - - [Test] - public void One_Level_Nesting_Escaped_Generates_Keys_For_Missing_Items() - { - Guid[] guids = { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() }; - var guidCounter = 0; - - Guid GuidFactory() - { - return guids[guidCounter++]; - } - - // we need to ensure the escaped json is consistent with how it will be re-escaped after parsing - // and this is how to do that, the result will also include quotes around it. - var subJsonEscaped = JsonConvert.ToString(JToken.Parse(@"[{ - ""name"": ""Item 1"", - ""ncContentTypeAlias"": ""text"", - ""text"": ""woot"" - }, { - ""name"": ""Nested Item 2 was copied and has no key"", - ""ncContentTypeAlias"": ""text"", - ""text"": ""zoot"" - } - ]").ToString(Formatting.None)); - - var json = @"[{ - ""name"": ""Item 1 was copied and has no key"", - ""ncContentTypeAlias"": ""text"", - ""text"": ""woot"" - }, { - ""key"": ""d8e214d8-c5a5-4b45-9b51-4050dd47f5fa"", - ""name"": ""Item 2"", - ""ncContentTypeAlias"": ""list"", - ""text"": ""zoot"", - ""subItems"":" + subJsonEscaped + @" - } -]"; - - var component = new NestedContentPropertyHandler(); - var result = component.CreateNestedContentKeys(json, true, GuidFactory); - - // Ensure the new GUID is put in a key into the JSON for each item - Assert.IsTrue(result.Contains(guids[0].ToString())); - Assert.IsTrue(result.Contains(guids[1].ToString())); - Assert.IsTrue(result.Contains(guids[2].ToString())); - } - - [Test] - public void Nested_In_Complex_Editor_Escaped_Generates_Keys_For_Missing_Items() - { - Guid[] guids = { Guid.NewGuid(), Guid.NewGuid() }; - var guidCounter = 0; - - Guid GuidFactory() - { - return guids[guidCounter++]; - } - - // we need to ensure the escaped json is consistent with how it will be re-escaped after parsing - // and this is how to do that, the result will also include quotes around it. - var subJsonEscaped = JsonConvert.ToString(JToken.Parse(@"[{ - ""key"": ""dccf550c-3a05-469e-95e1-a8f560f788c2"", - ""name"": ""Item 1"", - ""ncContentTypeAlias"": ""text"", - ""text"": ""woot"" - }, { - ""name"": ""Nested Item 2 was copied and has no key"", - ""ncContentTypeAlias"": ""text"", - ""text"": ""zoot"" - } - ]").ToString(Formatting.None)); - - // Complex editor such as the grid - var complexEditorJsonEscaped = @"{ - ""name"": ""1 column layout"", - ""sections"": [ - { - ""grid"": ""12"", - ""rows"": [ - { - ""name"": ""Article"", - ""id"": ""b4f6f651-0de3-ef46-e66a-464f4aaa9c57"", - ""areas"": [ - { - ""grid"": ""4"", - ""controls"": [ - { - ""value"": ""I am quote"", - ""editor"": { - ""alias"": ""quote"", - ""view"": ""textstring"" - }, - ""styles"": null, - ""config"": null - }], - ""styles"": null, - ""config"": null - }, - { - ""grid"": ""8"", - ""controls"": [ - { - ""value"": ""Header"", - ""editor"": { - ""alias"": ""headline"", - ""view"": ""textstring"" - }, - ""styles"": null, - ""config"": null - }, - { - ""value"": " + subJsonEscaped + @", - ""editor"": { - ""alias"": ""madeUpNestedContent"", - ""view"": ""madeUpNestedContentInGrid"" - }, - ""styles"": null, - ""config"": null - }], - ""styles"": null, - ""config"": null - }], - ""styles"": null, - ""config"": null - }] - }] -}"; - - var json = @"[{ - ""key"": ""04a6dba8-813c-4144-8aca-86a3f24ebf08"", - ""name"": ""Item 1"", - ""ncContentTypeAlias"": ""text"", - ""text"": ""woot"" - }, { - ""name"": ""Item 2 was copied and has no key"", - ""ncContentTypeAlias"": ""list"", - ""text"": ""zoot"", - ""subItems"":" + complexEditorJsonEscaped + @" - } -]"; - - var component = new NestedContentPropertyHandler(); - var result = component.CreateNestedContentKeys(json, true, GuidFactory); - - // Ensure the new GUID is put in a key into the JSON for each item - Assert.IsTrue(result.Contains(guids[0].ToString())); - Assert.IsTrue(result.Contains(guids[1].ToString())); - } -} diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/NumericValueEditorTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/NumericValueEditorTests.cs index 99cf8fd6ec..683be6dce2 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/NumericValueEditorTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/NumericValueEditorTests.cs @@ -87,11 +87,10 @@ public class NumericValueEditorTests private static IntegerPropertyEditor.IntegerPropertyValueEditor CreateValueEditor() { var valueEditor = new IntegerPropertyEditor.IntegerPropertyValueEditor( - Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), - new DataEditorAttribute("alias", "name", "view")); + new DataEditorAttribute("alias")); return valueEditor; } } diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/PropertyEditorValueTypeConverterTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/PropertyEditorValueTypeConverterTests.cs index fb4bc40ea0..9ad49dfc61 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/PropertyEditorValueTypeConverterTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/PropertyEditorValueTypeConverterTests.cs @@ -212,7 +212,7 @@ public class PropertyEditorValueTypeConverterTests private static PropertyEditorCollection ValueTypePropertyEditorCollection(string valueType) { var valueEditor = Mock.Of(x => x.ValueType == valueType); - var dataEditor = Mock.Of(x => x.GetValueEditor() == valueEditor && x.Alias == "My.Custom.Alias" && x.Type == EditorType.PropertyValue); + var dataEditor = Mock.Of(x => x.GetValueEditor() == valueEditor && x.Alias == "My.Custom.Alias"); var propertyEditors = new PropertyEditorCollection(new DataEditorCollection(() => new[] { dataEditor })); return propertyEditors; } diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/SliderValueEditorTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/SliderValueEditorTests.cs index ee57961276..0850422598 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/SliderValueEditorTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/SliderValueEditorTests.cs @@ -122,11 +122,10 @@ public class SliderValueEditorTests private static SliderPropertyEditor.SliderPropertyValueEditor CreateValueEditor() { var valueEditor = new SliderPropertyEditor.SliderPropertyValueEditor( - Mock.Of(), Mock.Of(), new SystemTextJsonSerializer(), Mock.Of(), - new DataEditorAttribute("alias", "name", "view")); + new DataEditorAttribute("alias")); return valueEditor; } } diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/TrueFalsePropertyValueEditorTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/TrueFalsePropertyValueEditorTests.cs index 5776a1f927..b64d4b2cf4 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/TrueFalsePropertyValueEditorTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/TrueFalsePropertyValueEditorTests.cs @@ -51,7 +51,7 @@ public class TrueFalsePropertyValueEditorTests { foreach (var (value, expected) in _valuesAndExpectedResults) { - // FromEditor returns 1 or 0, not true or false + // FromEditor returns 1 or 0, not true or false var actuallyExpected = expected ? 1 : 0; var fromEditor = FromEditor(value); Assert.AreEqual(actuallyExpected, fromEditor, message: $"Failed for: {value}"); @@ -98,11 +98,10 @@ public class TrueFalsePropertyValueEditorTests private static TrueFalsePropertyEditor.TrueFalsePropertyValueEditor CreateValueEditor() { var valueEditor = new TrueFalsePropertyEditor.TrueFalsePropertyValueEditor( - Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), - new DataEditorAttribute("alias", "name", "view")); + new DataEditorAttribute("alias")); return valueEditor; } } diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Published/NestedContentTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Published/NestedContentTests.cs deleted file mode 100644 index c8e9df4a6d..0000000000 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Published/NestedContentTests.cs +++ /dev/null @@ -1,302 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using System.Collections.Generic; -using System.Linq; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Abstractions; -using Moq; -using NUnit.Framework; -using Umbraco.Cms.Core.DeliveryApi; -using Umbraco.Cms.Core.Models.DeliveryApi; -using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Logging; -using Umbraco.Cms.Core.Models; -using Umbraco.Cms.Core.Models.PublishedContent; -using Umbraco.Cms.Core.PropertyEditors; -using Umbraco.Cms.Core.PropertyEditors.ValueConverters; -using Umbraco.Cms.Core.PublishedCache; -using Umbraco.Cms.Core.PublishedCache.Internal; -using Umbraco.Cms.Core.Services; -using Umbraco.Cms.Infrastructure.Serialization; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Published; - -[TestFixture] -public class NestedContentTests -{ - private (IPublishedContentType, IPublishedContentType) CreateContentTypes() - { - var logger = Mock.Of>(); - var loggerFactory = NullLoggerFactory.Instance; - var profiler = Mock.Of(); - var proflog = new ProfilingLogger(logger, profiler); - var localizationService = Mock.Of(); - - PropertyEditorCollection editors = null; - var editor = new NestedContentPropertyEditor( - Mock.Of(), - Mock.Of(), - Mock.Of(), - Mock.Of()); - editors = new PropertyEditorCollection(new DataEditorCollection(() => new DataEditor[] { editor })); - - var serializer = new ConfigurationEditorJsonSerializer(); - - var dataType1 = new DataType(editor, serializer) - { - Id = 1 - }; - dataType1.ConfigurationData = dataType1.Editor!.GetConfigurationEditor() - .FromConfigurationObject( - new NestedContentConfiguration - { - MinItems = 1, - MaxItems = 1, - ContentTypes = new[] { new NestedContentConfiguration.ContentType { Alias = "contentN1" } }, - }, - serializer); - var configuration = dataType1.ConfigurationObject as NestedContentConfiguration; - Assert.NotNull(configuration); - Assert.AreEqual(1, configuration.MinItems); - Assert.AreEqual(1, configuration.MaxItems); - Assert.AreEqual(1, configuration.ContentTypes!.Length); - Assert.AreEqual("contentN1", configuration.ContentTypes.First().Alias); - - var dataType2 = new DataType(editor, serializer) - { - Id = 2 - }; - dataType2.ConfigurationData = dataType2.Editor!.GetConfigurationEditor() - .FromConfigurationObject( - new NestedContentConfiguration - { - MinItems = 1, - MaxItems = 99, - ContentTypes = new[] { new NestedContentConfiguration.ContentType { Alias = "contentN1" } }, - }, - serializer); - configuration = dataType2.ConfigurationObject as NestedContentConfiguration; - Assert.NotNull(configuration); - Assert.AreEqual(1, configuration.MinItems); - Assert.AreEqual(99, configuration.MaxItems); - Assert.AreEqual(1, configuration.ContentTypes!.Length); - Assert.AreEqual("contentN1", configuration.ContentTypes.First().Alias); - - var dataType3 = - new DataType( - new TextboxPropertyEditor(Mock.Of(), Mock.Of(), Mock.Of()), serializer) - { Id = 3 }; - - // mocked dataservice returns nested content preValues - var dataTypeServiceMock = new Mock(); - dataTypeServiceMock.Setup(x => x.GetAll()).Returns(new[] { dataType1, dataType2, dataType3 }); - - var publishedModelFactory = new Mock(); - - // mocked model factory returns model type - var modelTypes = new Dictionary { { "contentN1", typeof(TestElementModel) } }; - publishedModelFactory - .Setup(x => x.MapModelType(It.IsAny())) - .Returns((Type type) => ModelType.Map(type, modelTypes)); - - // mocked model factory creates models - publishedModelFactory - .Setup(x => x.CreateModel(It.IsAny())) - .Returns((IPublishedElement element) => - { - if (element.ContentType.Alias.InvariantEquals("contentN1")) - { - return new TestElementModel(element, Mock.Of()); - } - - return element; - }); - - // mocked model factory creates model lists - publishedModelFactory - .Setup(x => x.CreateModelList(It.IsAny())) - .Returns((string alias) => - alias == "contentN1" - ? new List() - : new List()); - - var contentCache = new Mock(); - var publishedSnapshot = new Mock(); - - // mocked published snapshot returns a content cache - publishedSnapshot - .Setup(x => x.Content) - .Returns(contentCache.Object); - - var publishedSnapshotAccessor = new Mock(); - - // mocked published snapshot accessor returns a facade - var localPublishedSnapshot = publishedSnapshot.Object; - publishedSnapshotAccessor - .Setup(x => x.TryGetPublishedSnapshot(out localPublishedSnapshot)) - .Returns(true); - - var converters = new PropertyValueConverterCollection(() => new IPropertyValueConverter[] - { - new NestedContentSingleValueConverter(publishedSnapshotAccessor.Object, publishedModelFactory.Object, proflog, Mock.Of()), - new NestedContentManyValueConverter(publishedSnapshotAccessor.Object, publishedModelFactory.Object, proflog, Mock.Of()), - }); - - var factory = - new PublishedContentTypeFactory(publishedModelFactory.Object, converters, dataTypeServiceMock.Object); - - IEnumerable CreatePropertyTypes1(IPublishedContentType contentType) - { - yield return factory.CreatePropertyType(contentType, "property1", 1); - } - - IEnumerable CreatePropertyTypes2(IPublishedContentType contentType) - { - yield return factory.CreatePropertyType(contentType, "property2", 2); - } - - IEnumerable CreatePropertyTypesN1(IPublishedContentType contentType) - { - yield return factory.CreatePropertyType(contentType, "propertyN1", 3); - } - - var contentType1 = factory.CreateContentType(Guid.NewGuid(), 1, "content1", CreatePropertyTypes1); - var contentType2 = factory.CreateContentType(Guid.NewGuid(), 2, "content2", CreatePropertyTypes2); - var contentTypeN1 = - factory.CreateContentType(Guid.NewGuid(), 2, "contentN1", CreatePropertyTypesN1, isElement: true); - - // mocked content cache returns content types - contentCache - .Setup(x => x.GetContentType(It.IsAny())) - .Returns((string alias) => - { - if (alias.InvariantEquals("contentN1")) - { - return contentTypeN1; - } - - return null; - }); - - return (contentType1, contentType2); - } - - [Test] - public void SingleNestedTest() - { - var (contentType1, _) = CreateContentTypes(); - - // nested single converter returns the proper value clr type TestModel, and cache level - Assert.AreEqual(typeof(TestElementModel), contentType1.GetPropertyType("property1").ClrType); - Assert.AreEqual(PropertyCacheLevel.Element, contentType1.GetPropertyType("property1").CacheLevel); - - var key = Guid.NewGuid(); - var keyA = Guid.NewGuid(); - var content = new InternalPublishedContent(contentType1) - { - Key = key, - Properties = new[] - { - new TestPublishedProperty( - contentType1.GetPropertyType("property1"), $@"[ - {{ ""key"": ""{keyA}"", ""propertyN1"": ""foo"", ""ncContentTypeAlias"": ""contentN1"" }} - ]"), - }, - }; - var value = content.Value(Mock.Of(), "property1"); - - // nested single converter returns proper TestModel value - Assert.IsInstanceOf(value); - var valueM = (TestElementModel)value; - Assert.AreEqual("foo", valueM.PropValue); - Assert.AreEqual(keyA, valueM.Key); - } - - [Test] - public void ManyNestedTest() - { - var (_, contentType2) = CreateContentTypes(); - - // nested many converter returns the proper value clr type IEnumerable, and cache level - Assert.AreEqual(typeof(IEnumerable), contentType2.GetPropertyType("property2").ClrType); - Assert.AreEqual(PropertyCacheLevel.Element, contentType2.GetPropertyType("property2").CacheLevel); - - var key = Guid.NewGuid(); - var keyA = Guid.NewGuid(); - var keyB = Guid.NewGuid(); - var content = new InternalPublishedContent(contentType2) - { - Key = key, - Properties = new[] - { - new TestPublishedProperty(contentType2.GetPropertyType("property2"), $@"[ - {{ ""key"": ""{keyA}"", ""propertyN1"": ""foo"", ""ncContentTypeAlias"": ""contentN1"" }}, - {{ ""key"": ""{keyB}"", ""propertyN1"": ""bar"", ""ncContentTypeAlias"": ""contentN1"" }} - ]"), - }, - }; - var value = content.Value(Mock.Of(), "property2"); - - // nested many converter returns proper IEnumerable value - Assert.IsInstanceOf>(value); - Assert.IsInstanceOf>(value); - var valueM = ((IEnumerable)value).ToArray(); - Assert.AreEqual("foo", valueM[0].PropValue); - Assert.AreEqual(keyA, valueM[0].Key); - Assert.AreEqual("bar", valueM[1].PropValue); - Assert.AreEqual(keyB, valueM[1].Key); - } - - public class TestElementModel : PublishedElementModel - { - public TestElementModel(IPublishedElement content, IPublishedValueFallback fallback) - : base(content, fallback) - { - } - - public string PropValue => this.Value(Mock.Of(), "propertyN1"); - } - - public class TestPublishedProperty : PublishedPropertyBase - { - private readonly bool _hasValue; - private readonly bool _preview; - private readonly object _sourceValue; - private IPublishedElement _owner; - - public TestPublishedProperty(IPublishedPropertyType propertyType, object source) - : base(propertyType, PropertyCacheLevel.Element) // initial reference cache level always is .Content - { - _sourceValue = source; - _hasValue = source != null && (!(source is string ssource) || !string.IsNullOrWhiteSpace(ssource)); - } - - public TestPublishedProperty(IPublishedPropertyType propertyType, IPublishedElement element, bool preview, PropertyCacheLevel referenceCacheLevel, object source) - : base(propertyType, referenceCacheLevel) - { - _sourceValue = source; - _hasValue = source != null && (!(source is string ssource) || !string.IsNullOrWhiteSpace(ssource)); - _owner = element; - _preview = preview; - } - - private object InterValue => PropertyType.ConvertSourceToInter(null, _sourceValue, false); - - internal void SetOwner(IPublishedElement owner) => _owner = owner; - - public override bool HasValue(string culture = null, string? segment = null) => _hasValue; - - public override object GetSourceValue(string culture = null, string? segment = null) => _sourceValue; - - public override object GetValue(string culture = null, string? segment = null) => - PropertyType.ConvertInterToObject(_owner, ReferenceCacheLevel, InterValue, _preview); - - public override object GetXPathValue(string culture = null, string? segment = null) => - throw new InvalidOperationException("This method won't be implemented."); - - public override object GetDeliveryApiValue(bool expanding, string culture = null, string segment = null) => - PropertyType.ConvertInterToDeliveryApiObject(_owner, ReferenceCacheLevel, InterValue, _preview, false); - } -} diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Services/PropertyValidationServiceTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Services/PropertyValidationServiceTests.cs index 24961deaf9..0900965319 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Services/PropertyValidationServiceTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Services/PropertyValidationServiceTests.cs @@ -33,11 +33,10 @@ public class PropertyValidationServiceTests // new data editor that returns a TextOnlyValueEditor which will do the validation for the properties var dataEditor = Mock.Of( - x => x.Type == EditorType.PropertyValue - && x.Alias == Constants.PropertyEditors.Aliases.TextBox); + x => x.Alias == Constants.PropertyEditors.Aliases.TextBox); Mock.Get(dataEditor).Setup(x => x.GetValueEditor(It.IsAny())) .Returns(new CustomTextOnlyValueEditor( - new DataEditorAttribute(Constants.PropertyEditors.Aliases.TextBox, "Test Textbox", "textbox"), + new DataEditorAttribute(Constants.PropertyEditors.Aliases.TextBox), Mock.Of(), new JsonNetSerializer(), Mock.Of())); diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/DataTypeBuilderTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/DataTypeBuilderTests.cs index 4e09407467..95f07553f0 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/DataTypeBuilderTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Tests.Common/Builders/DataTypeBuilderTests.cs @@ -17,7 +17,6 @@ public class DataTypeBuilderTests // Arrange const int testId = 3123; const string testEditorAlias = "testAlias"; - const string testEditorName = "Test Name"; var builder = new DataTypeBuilder(); @@ -26,7 +25,6 @@ public class DataTypeBuilderTests .WithId(testId) .AddEditor() .WithAlias(testEditorAlias) - .WithName(testEditorName) .WithDefaultConfiguration(new Dictionary { { "value1", "value1" }, { "value2", "value2" } }) .Done() .Build(); @@ -34,7 +32,6 @@ public class DataTypeBuilderTests // Assert Assert.AreEqual(testId, dataType.Id); Assert.AreEqual(testEditorAlias, dataType.Editor.Alias); - Assert.AreEqual(testEditorName, dataType.Editor.Name); Assert.AreEqual(2, dataType.Editor.DefaultConfiguration.Count); Assert.AreEqual("value1", dataType.Editor.DefaultConfiguration["value1"]); } diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Tests.UnitTests.csproj b/tests/Umbraco.Tests.UnitTests/Umbraco.Tests.UnitTests.csproj index 58a409dde2..7ca99984f9 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Tests.UnitTests.csproj +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Tests.UnitTests.csproj @@ -16,4 +16,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/MemberControllerUnitTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/MemberControllerUnitTests.cs index d3745452d2..91c21f7625 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/MemberControllerUnitTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Web.BackOffice/Controllers/MemberControllerUnitTests.cs @@ -549,10 +549,9 @@ public class MemberControllerUnitTests var mockPasswordConfig = new Mock>(); mockPasswordConfig.Setup(x => x.Value).Returns(() => new MemberPasswordConfigurationSettings()); var dataEditor = Mock.Of( - x => x.Type == EditorType.PropertyValue - && x.Alias == Constants.PropertyEditors.Aliases.Label); + x => x.Alias == Constants.PropertyEditors.Aliases.Label); Mock.Get(dataEditor).Setup(x => x.GetValueEditor()).Returns(new TextOnlyValueEditor( - new DataEditorAttribute(Constants.PropertyEditors.Aliases.TextBox, "Test Textbox", "textbox"), + new DataEditorAttribute(Constants.PropertyEditors.Aliases.TextBox), Mock.Of(), Mock.Of(), Mock.Of())); diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Web.Common/AngularIntegration/ContentModelSerializationTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Web.Common/AngularIntegration/ContentModelSerializationTests.cs index 95853847e3..8bfc48daa8 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Web.Common/AngularIntegration/ContentModelSerializationTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Web.Common/AngularIntegration/ContentModelSerializationTests.cs @@ -32,8 +32,6 @@ public class ContentModelSerializationTests Value = "value" + propertyIndex, Config = new Dictionary { { propertyIndex.ToInvariantString(), "value" } }, Description = "Description " + propertyIndex, - View = "~/Views/View" + propertyIndex, - HideLabel = false, }); } @@ -73,7 +71,6 @@ public class ContentModelSerializationTests Assert.AreEqual("value" + prop, jsonTabs[tab]["properties"][prop]["value"].ToString()); Assert.AreEqual("{\"" + prop + "\":\"value\"}", jsonTabs[tab]["properties"][prop]["config"].ToString(Formatting.None)); Assert.AreEqual("Description " + prop, jsonTabs[tab]["properties"][prop]["description"].ToString()); - Assert.AreEqual(false, jsonTabs[tab]["properties"][prop]["hideLabel"].Value()); } } }