EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
foreign enum option reference
Yuri Kuznetsov0e1cb6fd477e
diff --git a/client/src/views/fields/enum.js b/client/src/views/fields/enum.jsindex a3698fe6a3..3c3ec117a9 100644--- a/client/src/views/fields/enum.js+++ b/client/src/views/fields/enum.js@@ -175,7 +175,7 @@ class EnumFieldView extends BaseFieldView {this.styleMap = this.params.style || this.model.getFieldParam(this.name, 'style') || {};let optionsPath = this.params.optionsPath;- /** @type {?string} */+ /** @type {string|null} */const optionsReference = this.params.optionsReference;if (!optionsPath && optionsReference) {diff --git a/client/src/views/fields/foreign-array.js b/client/src/views/fields/foreign-array.jsindex 6bb3009d00..e830c39efe 100644--- a/client/src/views/fields/foreign-array.js+++ b/client/src/views/fields/foreign-array.js@@ -27,49 +27,14 @@************************************************************************/import ArrayFieldView from 'views/fields/array';+import ForeignEnumFieldView from 'views/fields/foreign-enum';class ForeignArrayFieldView extends ArrayFieldView {type = 'foreign'setupOptions() {- this.params.options = [];-- const field = this.params.field;- const link = this.params.link;-- if (!field || !link) {- return;- }-- const scope = this.getMetadata().get(['entityDefs', this.model.entityType, 'links', link, 'entity']);-- if (!scope) {- return;- }-- let {- optionsPath,- translation,- options,- isSorted,- displayAsLabel,- style,- } = this.getMetadata()- .get(['entityDefs', scope, 'fields', field]);-- options = optionsPath ? this.getMetadata().get(optionsPath) : options;-- this.params.options = Espo.Utils.clone(options) || [];- this.params.translation = translation;- this.params.isSorted = isSorted || false;- this.params.displayAsLabel = displayAsLabel || false;- this.styleMap = style || {};-- this.translatedOptions = Object.fromEntries(- this.params.options- .map(item => [item, this.getLanguage().translateOption(item, field, scope)])- );+ ForeignEnumFieldView.prototype.setupOptions.call(this);}}diff --git a/client/src/views/fields/foreign-enum.js b/client/src/views/fields/foreign-enum.jsindex 30ee119f49..741c0a800c 100644--- a/client/src/views/fields/foreign-enum.js+++ b/client/src/views/fields/foreign-enum.js@@ -42,13 +42,25 @@ class ForeignEnumFieldView extends EnumFieldView {return;}- const scope = this.getMetadata().get(['entityDefs', this.model.entityType, 'links', link, 'entity']);+ const entityType = this.getMetadata().get(`entityDefs.${this.model.entityType}.links.${link}.entity`);- if (!scope) {+ if (!entityType) {return;}- const fieldDefs = this.getMetadata().get(['entityDefs', scope, 'fields', field]);+ /**+ * @type {{+ * optionsPath?: string|null,+ * optionsReference?: string|null,+ * translation?: string|null,+ * options?: string[],+ * isSorted?: boolean,+ * displayAsLabel?: boolean,+ * style?: Record,+ * labelType?: string,+ * }}+ */+ const fieldDefs = this.getMetadata().get(`entityDefs.${entityType}.fields.${field}`);if (!fieldDefs) {return;@@ -56,6 +68,7 @@ class ForeignEnumFieldView extends EnumFieldView {let {optionsPath,+ optionsReference,translation,options,isSorted,@@ -64,19 +77,29 @@ class ForeignEnumFieldView extends EnumFieldView {labelType,} = fieldDefs;- options = optionsPath ? this.getMetadata().get(optionsPath) : options;+ if (!optionsPath && optionsReference) {+ const [refEntityType, refField] = optionsReference.split('.');- this.params.options = Espo.Utils.clone(options) || [];+ optionsPath = `entityDefs.${refEntityType}.fields.${refField}.options`;++ style = this.getMetadata().get(`entityDefs.${refEntityType}.fields.${refField}.style`) ?? {};+ }++ if (optionsPath) {+ options = this.getMetadata().get(optionsPath);+ }++ this.params.options = Espo.Utils.clone(options) ?? [];this.params.translation = translation;- this.params.isSorted = isSorted || false;- this.params.displayAsLabel = displayAsLabel || false;+ this.params.isSorted = isSorted ?? false;+ this.params.displayAsLabel = displayAsLabel ?? false;this.params.labelType = labelType;- this.styleMap = style || {};+ this.styleMap = style ?? {};++ const pairs = this.params.options+ .map(item => [item, this.getLanguage().translateOption(item, field, entityType)])- this.translatedOptions = Object.fromEntries(- this.params.options- .map(item => [item, this.getLanguage().translateOption(item, field, scope)])- );+ this.translatedOptions = Object.fromEntries(pairs);}}