+
+
+ Reference fields are shown as a column in the content list when referenced by another content. When no reference field is defined, the first field is used.
+
+
+
`
})
@@ -88,6 +103,9 @@ export class FieldFormCommonComponent implements OnInit {
this.editForm.setControl('isListField',
new FormControl(this.field.properties.isListField));
+ this.editForm.setControl('isReferenceField',
+ new FormControl(this.field.properties.isReferenceField));
+
this.editForm.setControl('editorUrl',
new FormControl(this.field.properties.editorUrl));
diff --git a/src/Squidex/app/shared/services/schemas.service.ts b/src/Squidex/app/shared/services/schemas.service.ts
index 79b0e9778..2439b6bd0 100644
--- a/src/Squidex/app/shared/services/schemas.service.ts
+++ b/src/Squidex/app/shared/services/schemas.service.ts
@@ -82,6 +82,7 @@ export class SchemaDto {
export class SchemaDetailsDto extends SchemaDto {
public listFields: RootFieldDto[];
public listFieldsEditable: RootFieldDto[];
+ public referenceFields: RootFieldDto[];
constructor(links: ResourceLinks, id: string, name: string, category: string,
properties: SchemaPropertiesDto,
@@ -99,19 +100,24 @@ export class SchemaDetailsDto extends SchemaDto {
super(links, id, name, category, properties, isSingleton, isPublished, created, createdBy, lastModified, lastModifiedBy, version);
if (fields) {
- let listFields = this.fields.filter(x => x.properties.isListField && x.properties.isContentField);
+ this.listFields = this.getField(x => x.properties.isListField);
+ this.listFieldsEditable = this.listFields.filter(x => x.isInlineEditable);
- if (listFields.length === 0 && this.fields.length > 0) {
- listFields = [this.fields[0]];
- }
+ this.referenceFields = this.getField(x => x.properties.isReferenceField);
+ }
+ }
- if (listFields.length === 0) {
- listFields = NONE_FIELDS;
- }
+ private getField(predicate: (field: RootFieldDto) => boolean) {
+ let fields = this.fields.filter(x => predicate(x) && x.properties.isContentField);
- this.listFields = listFields;
- this.listFieldsEditable = listFields.filter(x => x.isInlineEditable);
+ if (fields.length === 0 && this.fields.length > 0) {
+ fields = [this.fields[0]];
+ }
+ if (fields.length === 0) {
+ fields = NONE_FIELDS;
}
+
+ return fields;
}
public export(): any {
diff --git a/src/Squidex/app/shared/services/schemas.types.ts b/src/Squidex/app/shared/services/schemas.types.ts
index c9df2017c..cb5059939 100644
--- a/src/Squidex/app/shared/services/schemas.types.ts
+++ b/src/Squidex/app/shared/services/schemas.types.ts
@@ -141,6 +141,7 @@ export abstract class FieldPropertiesDto {
public readonly placeholder?: string;
public readonly isRequired: boolean = false;
public readonly isListField: boolean = false;
+ public readonly isReferenceField: boolean = false;
constructor(public readonly editor: string,
props?: Partial
diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/GuardSchemaFieldTests.cs b/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/GuardSchemaFieldTests.cs
index 8eacb18b6..1458a3c05 100644
--- a/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/GuardSchemaFieldTests.cs
+++ b/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/GuardSchemaFieldTests.cs
@@ -261,6 +261,15 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards
new ValidationError("UI field cannot be a list field.", "Properties.IsListField"));
}
+ [Fact]
+ public void CanUpdate_should_throw_exception_if_marking_a_ui_field_as_reference_field()
+ {
+ var command = new UpdateField { FieldId = 4, Properties = new UIFieldProperties { IsReferenceField = true } };
+
+ ValidationAssert.Throws(() => GuardSchemaField.CanUpdate(schema_0, command),
+ new ValidationError("UI field cannot be a reference field.", "Properties.IsReferenceField"));
+ }
+
[Fact]
public void CanUpdate_should_throw_exception_if_properties_null()
{
diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/GuardSchemaTests.cs b/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/GuardSchemaTests.cs
index dae464709..42b65cdd7 100644
--- a/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/GuardSchemaTests.cs
+++ b/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/GuardSchemaTests.cs
@@ -354,7 +354,8 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards
Name = "field1",
Properties = new UIFieldProperties
{
- IsListField = true
+ IsListField = true,
+ IsReferenceField = true,
},
IsHidden = true,
IsDisabled = true,
@@ -367,6 +368,8 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards
await ValidationAssert.ThrowsAsync(() => GuardSchema.CanCreate(command, appProvider),
new ValidationError("UI field cannot be a list field.",
"Fields[1].Properties.IsListField"),
+ new ValidationError("UI field cannot be a reference field.",
+ "Fields[1].Properties.IsReferenceField"),
new ValidationError("UI field cannot be hidden.",
"Fields[1].IsHidden"),
new ValidationError("UI field cannot be disabled.",