EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
create handler: pass link, set-parent create handler
Yuri Kuznetsov76ca781790e8
diff --git a/application/Espo/Modules/Crm/Resources/metadata/clientDefs/Contact.json b/application/Espo/Modules/Crm/Resources/metadata/clientDefs/Contact.jsonindex 72f0bdf762..8604803a33 100644--- a/application/Espo/Modules/Crm/Resources/metadata/clientDefs/Contact.json+++ b/application/Espo/Modules/Crm/Resources/metadata/clientDefs/Contact.json@@ -82,6 +82,12 @@"rowActionsView": "crm:views/record/row-actions/relationship-target","layout": "listForTarget","view": "crm:views/record/panels/target-lists"+ },+ "meetings": {+ "createHandler": "handlers/create-related/set-parent"+ },+ "calls": {+ "createHandler": "handlers/create-related/set-parent"}},"boolFilterList": [diff --git a/application/Espo/Modules/Crm/Resources/metadata/clientDefs/Lead.json b/application/Espo/Modules/Crm/Resources/metadata/clientDefs/Lead.jsonindex 29ceadf096..b3f88c1e67 100644--- a/application/Espo/Modules/Crm/Resources/metadata/clientDefs/Lead.json+++ b/application/Espo/Modules/Crm/Resources/metadata/clientDefs/Lead.json@@ -101,6 +101,12 @@"rowActionsView": "crm:views/record/row-actions/relationship-target","layout": "listForTarget","view": "crm:views/record/panels/target-lists"+ },+ "meetings": {+ "createHandler": "handlers/create-related/set-parent"+ },+ "calls": {+ "createHandler": "handlers/create-related/set-parent"}},"filterList": [diff --git a/client/src/handlers/create-related.js b/client/src/handlers/create-related.jsindex 5c141aadd4..48bb5fcdcf 100644--- a/client/src/handlers/create-related.js+++ b/client/src/handlers/create-related.js@@ -46,9 +46,10 @@ class CreateRelatedHandler {** @abstract* @param {module:model} model A model.+ * @param {string} link A link name. As of v9.2.0.* @return {Promise<Object.<string, *>>} Attributes.*/- getAttributes(model) {+ getAttributes(model, link) {return Promise.resolve({});}}diff --git a/client/src/handlers/create-related/set-parent.js b/client/src/handlers/create-related/set-parent.jsnew file mode 100644index 0000000000..7e38d27cf3--- /dev/null+++ b/client/src/handlers/create-related/set-parent.js@@ -0,0 +1,65 @@+/************************************************************************+ * This file is part of EspoCRM.+ *+ * EspoCRM – Open Source CRM application.+ * Copyright (C) 2014-2025 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko+ * Website: https://www.espocrm.com+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as published by+ * the Free Software Foundation, either version 3 of the License, or+ * (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ * The interactive user interfaces in modified source and object code versions+ * of this program must display Appropriate Legal Notices, as required under+ * Section 5 of the GNU Affero General Public License version 3.+ *+ * In accordance with Section 7(b) of the GNU Affero General Public License version 3,+ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word.+ ************************************************************************/++import CreateRelatedHandler from 'handlers/create-related';+import {inject} from 'di';+import ModelFactory from 'model-factory';++export default class SetParentHandler extends CreateRelatedHandler {++ /**+ * @private+ * @type {ModelFactory}+ */+ @inject(ModelFactory)+ modelFactory++ async getAttributes(model, link) {+ const entityType = model.getLinkParam(link, 'entity');++ if (!entityType) {+ return {};+ }++ const seed = await this.modelFactory.create(entityType);++ /** @type {string[]} */+ const parentEntityTypeList = seed.getFieldParam('parent', 'entityList') ?? [];++ if (!parentEntityTypeList.includes(model.entityType)) {+ return {};+ }++ return {+ parentId: model.id,+ parentName: model.attributes.name,+ parentType: model.entityType,+ }+ }+}+diff --git a/client/src/helpers/record/create-related.js b/client/src/helpers/record/create-related.jsindex 037a8d6e1f..d3f510d9f0 100644--- a/client/src/helpers/record/create-related.js+++ b/client/src/helpers/record/create-related.js@@ -73,10 +73,10 @@ class CreateRelatedHelper {if (handler) {const Handler = await Espo.loader.requirePromise(handler);- /** @type {{getAttributes: function(import('model').default): Promise<Record>}} */+ /** @type {import('handlers/create-related').default} */const handlerObj = new Handler(this.view.getHelper());- const additionalAttributes = await handlerObj.getAttributes(model);+ const additionalAttributes = await handlerObj.getAttributes(model, link);attributes = {...attributes, ...additionalAttributes};}diff --git a/client/src/views/fields/link-multiple.js b/client/src/views/fields/link-multiple.jsindex d13b057ff4..df1ab09afa 100644--- a/client/src/views/fields/link-multiple.js+++ b/client/src/views/fields/link-multiple.js@@ -1144,8 +1144,8 @@ class LinkMultipleFieldView extends BaseFieldView {return new Promise(resolve => {Espo.loader.requirePromise(this.panelDefs.createHandler).then(Handler => new Handler(this.getHelper()))- .then(handler => {- handler.getAttributes(this.model)+ .then(/** import('handlers/create-related').default */handler => {+ handler.getAttributes(this.model, this.name).then(additionalAttributes => {resolve({...attributes,diff --git a/client/src/views/fields/link.js b/client/src/views/fields/link.jsindex 4c0605ceed..036d38e1d9 100644--- a/client/src/views/fields/link.js+++ b/client/src/views/fields/link.js@@ -1131,8 +1131,8 @@ class LinkFieldView extends BaseFieldView {return new Promise(resolve => {Espo.loader.requirePromise(this.panelDefs.createHandler).then(Handler => new Handler(this.getHelper()))- .then(handler => {- handler.getAttributes(this.model)+ .then(/** import('handlers/create-related').default */handler => {+ handler.getAttributes(this.model, this.name).then(additionalAttributes => {resolve({...attributes,