mirror of https://github.com/Squidex/squidex.git
11 changed files with 222 additions and 55 deletions
@ -0,0 +1,35 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System; |
||||
|
using Squidex.Infrastructure; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Core.Schemas |
||||
|
{ |
||||
|
[TypeName("ArrayField")] |
||||
|
public sealed class ArrayFieldProperties : FieldProperties |
||||
|
{ |
||||
|
public int? MinItems { get; set; } |
||||
|
|
||||
|
public int? MaxItems { get; set; } |
||||
|
|
||||
|
public override T Accept<T>(IFieldPropertiesVisitor<T> visitor) |
||||
|
{ |
||||
|
throw new NotImplementedException(); |
||||
|
} |
||||
|
|
||||
|
public override T Accept<T>(IFieldVisitor<T> visitor, IField field) |
||||
|
{ |
||||
|
throw new NotImplementedException(); |
||||
|
} |
||||
|
|
||||
|
public override Field CreateField(long id, string name, Partitioning partitioning) |
||||
|
{ |
||||
|
throw new NotImplementedException(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Core.Schemas |
||||
|
{ |
||||
|
public interface IArrayField : IField<ArrayFieldProperties> |
||||
|
{ |
||||
|
IReadOnlyCollection<IField> Fields { get; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,50 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Threading.Tasks; |
||||
|
using Newtonsoft.Json.Linq; |
||||
|
using Squidex.Domain.Apps.Core.Schemas; |
||||
|
using Squidex.Infrastructure.Json; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Core.ValidateContent.Validators |
||||
|
{ |
||||
|
public sealed class FieldValidator : IValidator |
||||
|
{ |
||||
|
private readonly IEnumerable<IValidator> validators; |
||||
|
private readonly IField field; |
||||
|
|
||||
|
public FieldValidator(IEnumerable<IValidator> validators, IField field) |
||||
|
{ |
||||
|
this.validators = validators; |
||||
|
this.field = field; |
||||
|
} |
||||
|
|
||||
|
public async Task ValidateAsync(object value, ValidationContext context, Action<string> addError) |
||||
|
{ |
||||
|
try |
||||
|
{ |
||||
|
object typedValue = null; |
||||
|
|
||||
|
if (value is JToken jToken) |
||||
|
{ |
||||
|
typedValue = jToken.IsNull() ? null : JsonValueConverter.ConvertValue(field, jToken); |
||||
|
} |
||||
|
|
||||
|
foreach (var validator in ValidatorsFactory.CreateValidators(field)) |
||||
|
{ |
||||
|
await validator.ValidateAsync(typedValue, context, addError); |
||||
|
} |
||||
|
} |
||||
|
catch |
||||
|
{ |
||||
|
addError("<FIELD> is not a valid value."); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue