Merge branch 'v10/feature/nullable-reference-types-in-Umbraco-Core' into v10/feature/nullable-reference-types-in-Umbraco-Infrastructure
This commit is contained in:
@@ -133,7 +133,7 @@ namespace Umbraco.Cms.Core
|
||||
/// </summary>
|
||||
/// <param name="a"></param>
|
||||
/// <returns></returns>
|
||||
public static implicit operator bool?(Attempt<TResult> a)
|
||||
public static implicit operator bool(Attempt<TResult> a)
|
||||
{
|
||||
return a.Success;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,20 @@ namespace Umbraco.Extensions
|
||||
{
|
||||
public static class ServiceCollectionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds a service of type <typeparamref name="TService"/> with an implementation type of <typeparamref name="TImplementing"/> to the specified <see cref="IServiceCollection"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Removes all previous registrations for the type <typeparamref name="TService"/>.
|
||||
/// </remarks>
|
||||
public static void AddUnique<TService, TImplementing>(
|
||||
this IServiceCollection services)
|
||||
where TService : class
|
||||
where TImplementing : class, TService
|
||||
{
|
||||
AddUnique<TService, TImplementing>(services, ServiceLifetime.Singleton);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a service of type <typeparamref name="TService"/> with an implementation type of <typeparamref name="TImplementing"/> to the specified <see cref="IServiceCollection"/>.
|
||||
/// </summary>
|
||||
@@ -15,7 +29,7 @@ namespace Umbraco.Extensions
|
||||
/// </remarks>
|
||||
public static void AddUnique<TService, TImplementing>(
|
||||
this IServiceCollection services,
|
||||
ServiceLifetime lifetime = ServiceLifetime.Singleton)
|
||||
ServiceLifetime lifetime)
|
||||
where TService : class
|
||||
where TImplementing : class, TService
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Umbraco.Cms.Core.Models.ContentEditing
|
||||
public class PropertyTypeValidation
|
||||
{
|
||||
[DataMember(Name = "mandatory")]
|
||||
public bool? Mandatory { get; set; }
|
||||
public bool Mandatory { get; set; }
|
||||
|
||||
[DataMember(Name = "mandatoryMessage")]
|
||||
public string? MandatoryMessage { get; set; }
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace Umbraco.Cms.Core.Models
|
||||
/// <summary>
|
||||
/// Gets of sets a value indicating whether a value for this property type is required.
|
||||
/// </summary>
|
||||
bool? Mandatory { get; set; }
|
||||
bool Mandatory { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the label of this property type should be displayed on top.
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace Umbraco.Cms.Core.Models.Mapping
|
||||
{
|
||||
base.Map(originalProp, dest, context);
|
||||
|
||||
var config = DataTypeService.GetDataType(originalProp.PropertyType?.DataTypeId).Configuration;
|
||||
var config = originalProp.PropertyType is null ? null : DataTypeService.GetDataType(originalProp.PropertyType.DataTypeId).Configuration;
|
||||
|
||||
// TODO: IDataValueEditor configuration - general issue
|
||||
// GetValueEditor() returns a non-configured IDataValueEditor
|
||||
@@ -48,7 +48,7 @@ namespace Umbraco.Cms.Core.Models.Mapping
|
||||
dest.LabelOnTop = originalProp.PropertyType?.LabelOnTop;
|
||||
|
||||
//add the validation information
|
||||
dest.Validation.Mandatory = originalProp.PropertyType?.Mandatory;
|
||||
dest.Validation.Mandatory = originalProp.PropertyType?.Mandatory ?? false;
|
||||
dest.Validation.MandatoryMessage = originalProp.PropertyType?.MandatoryMessage;
|
||||
dest.Validation.Pattern = originalProp.PropertyType?.ValidationRegExp;
|
||||
dest.Validation.PatternMessage = originalProp.PropertyType?.ValidationRegExpMessage;
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Umbraco.Cms.Core.Models.Mapping
|
||||
dest.ValidationRegExpMessage = property.PropertyType?.ValidationRegExpMessage;
|
||||
dest.Description = property.PropertyType?.Description;
|
||||
dest.Label = property.PropertyType?.Name;
|
||||
dest.DataType = DataTypeService.GetDataType(property.PropertyType?.DataTypeId);
|
||||
dest.DataType = property.PropertyType is null ? null : DataTypeService.GetDataType(property.PropertyType.DataTypeId);
|
||||
dest.LabelOnTop = property.PropertyType?.LabelOnTop;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -317,7 +317,7 @@ namespace Umbraco.Cms.Core.Models.Mapping
|
||||
target.Name = source.Label;
|
||||
target.DataTypeId = source.DataTypeId;
|
||||
target.DataTypeKey = source.DataTypeKey;
|
||||
target.Mandatory = source.Validation?.Mandatory;
|
||||
target.Mandatory = source.Validation?.Mandatory ?? false;
|
||||
target.MandatoryMessage = source.Validation?.MandatoryMessage;
|
||||
target.ValidationRegExp = source.Validation?.Pattern;
|
||||
target.ValidationRegExpMessage = source.Validation?.PatternMessage;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -25,7 +25,7 @@ namespace Umbraco.Extensions
|
||||
var tagAttribute = editor?.GetTagAttribute();
|
||||
if (tagAttribute == null) return null;
|
||||
|
||||
var configurationObject = dataTypeService.GetDataType(property.PropertyType?.DataTypeId).Configuration;
|
||||
var configurationObject = property.PropertyType is null ? null : dataTypeService.GetDataType(property.PropertyType.DataTypeId).Configuration;
|
||||
var configuration = ConfigurationEditor.ConfigurationAs<TagConfiguration>(configurationObject);
|
||||
|
||||
if (configuration?.Delimiter == default && configuration?.Delimiter is not null)
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Umbraco.Cms.Core.Models
|
||||
private Lazy<int>? _propertyGroupId;
|
||||
private string _propertyEditorAlias;
|
||||
private ValueStorageType _valueStorageType;
|
||||
private bool? _mandatory;
|
||||
private bool _mandatory;
|
||||
private string? _mandatoryMessage;
|
||||
private int _sortOrder;
|
||||
private string? _validationRegExp;
|
||||
@@ -179,7 +179,7 @@ namespace Umbraco.Cms.Core.Models
|
||||
|
||||
/// <inheritdoc />
|
||||
[DataMember]
|
||||
public bool? Mandatory
|
||||
public bool Mandatory
|
||||
{
|
||||
get => _mandatory;
|
||||
set => SetPropertyValueAndDetectChanges(value, ref _mandatory, nameof(Mandatory));
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace Umbraco.Cms.Core.Services
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the <see cref="IDataType"/></param>
|
||||
/// <returns><see cref="IDataType"/></returns>
|
||||
IDataType GetDataType(int? id);
|
||||
IDataType GetDataType(int id);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="IDataType"/> by its unique guid Id
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace Umbraco.Cms.Core.Services
|
||||
var editor = _propertyEditors[propertyType.PropertyEditorAlias];
|
||||
if (editor == null) throw new InvalidOperationException("No property editor found by alias " + propertyType.PropertyEditorAlias);
|
||||
|
||||
return ValidatePropertyValue(editor, dataType, postedValue, propertyType.Mandatory ?? false, propertyType.ValidationRegExp, propertyType.MandatoryMessage, propertyType.ValidationRegExpMessage);
|
||||
return ValidatePropertyValue(editor, dataType, postedValue, propertyType.Mandatory, propertyType.ValidationRegExp, propertyType.MandatoryMessage, propertyType.ValidationRegExpMessage);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -192,7 +192,7 @@ namespace Umbraco.Cms.Core.Services
|
||||
}
|
||||
var configuration = _dataTypeService.GetDataType(propertyType.DataTypeId).Configuration;
|
||||
var valueEditor = editor.GetValueEditor(configuration);
|
||||
return !valueEditor.Validate(value, propertyType.Mandatory ?? false, propertyType.ValidationRegExp).Any();
|
||||
return !valueEditor.Validate(value, propertyType.Mandatory, propertyType.ValidationRegExp).Any();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Factories
|
||||
ContentTypeId = contentTypeId,
|
||||
DataTypeId = propertyType.DataTypeId,
|
||||
Description = propertyType.Description,
|
||||
Mandatory = propertyType.Mandatory ?? false,
|
||||
Mandatory = propertyType.Mandatory,
|
||||
MandatoryMessage = propertyType.MandatoryMessage,
|
||||
Name = propertyType.Name,
|
||||
SortOrder = propertyType.SortOrder,
|
||||
|
||||
@@ -269,15 +269,11 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
/// </summary>
|
||||
/// <param name="id">Id of the <see cref="IDataType"/></param>
|
||||
/// <returns><see cref="IDataType"/></returns>
|
||||
public IDataType GetDataType(int? id)
|
||||
public IDataType GetDataType(int id)
|
||||
{
|
||||
if (id is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
{
|
||||
var dataType = _dataTypeRepository.Get(id.Value);
|
||||
var dataType = _dataTypeRepository.Get(id);
|
||||
ConvertMissingEditorOfDataTypeToLabel(dataType);
|
||||
return dataType;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user