Skip to content

EspoCRM – Open Source CRM Application

Lead capture pipeline select

Yurii8e92d6c0e4e7
diff --git a/application/Espo/Classes/FieldValidators/LeadCapture/Pipeline/Valid.php b/application/Espo/Classes/FieldValidators/LeadCapture/Pipeline/Valid.php
new file mode 100644
index 0000000000..1e79f6e427
--- /dev/null
+++ b/application/Espo/Classes/FieldValidators/LeadCapture/Pipeline/Valid.php
@@ -0,0 +1,58 @@
+<?php
+/************************************************************************
+ * This file is part of EspoCRM.
+ *
+ * EspoCRM – Open Source CRM application.
+ * Copyright (C) 2014-2026 EspoCRM, Inc.
+ * 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.
+ ************************************************************************/
+
+namespace Espo\Classes\FieldValidators\LeadCapture\Pipeline;
+
+use Espo\Entities\LeadCapture;
+use Espo\Core\FieldValidation\Validator;
+use Espo\Core\FieldValidation\Validator\Data;
+use Espo\Core\FieldValidation\Validator\Failure;
+use Espo\Modules\Crm\Entities\Lead;
+use Espo\ORM\Entity;
+
+/**
+ * @implements Validator<LeadCapture>
+ */
+class Valid implements Validator
+{
+ public function validate(Entity $entity, string $field, Data $data): ?Failure
+ {
+ $pipeline = $entity->getPipeline();
+
+ if (!$pipeline) {
+ return null;
+ }
+
+ if ($pipeline->getTargetEntityType() !== Lead::ENTITY_TYPE) {
+ return Failure::create();
+ }
+
+ return null;
+ }
+}
diff --git a/application/Espo/Classes/Record/LeadCapture/InputFilter.php b/application/Espo/Classes/Record/LeadCapture/InputFilter.php
new file mode 100644
index 0000000000..8b937814ef
--- /dev/null
+++ b/application/Espo/Classes/Record/LeadCapture/InputFilter.php
@@ -0,0 +1,54 @@
+<?php
+/************************************************************************
+ * This file is part of EspoCRM.
+ *
+ * EspoCRM – Open Source CRM application.
+ * Copyright (C) 2014-2026 EspoCRM, Inc.
+ * 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.
+ ************************************************************************/
+
+namespace Espo\Classes\Record\LeadCapture;
+
+use Espo\Core\Name\Field;
+use Espo\Core\Record\Input\Data;
+use Espo\Core\Record\Input\Filter;
+use Espo\Modules\Crm\Entities\Lead;
+use Espo\Tools\Pipeline\MetadataProvider;
+
+/**
+ * @noinspection PhpUnused
+ */
+class InputFilter implements Filter
+{
+ public function __construct(
+ private MetadataProvider $metadataProvider,
+ ) {}
+
+ public function filter(Data $data): void
+ {
+ if (!$this->metadataProvider->isEnabled(Lead::ENTITY_TYPE)) {
+ $data->clear(Field::PIPELINE . 'Id');
+ $data->clear(Field::PIPELINE . 'Name');
+ }
+ }
+}
diff --git a/application/Espo/Entities/LeadCapture.php b/application/Espo/Entities/LeadCapture.php
index 830c7a0b2d..945ab7cf6e 100644
--- a/application/Espo/Entities/LeadCapture.php
+++ b/application/Espo/Entities/LeadCapture.php
@@ -236,4 +236,10 @@ class LeadCapture extends Entity
{
return $this->get('formTheme');
}
+
+ public function getPipeline(): ?Pipeline
+ {
+ /** @var ?Pipeline */
+ return $this->relations->getOne(Field::PIPELINE);
+ }
}
diff --git a/application/Espo/Modules/Crm/Resources/i18n/en_US/Lead.json b/application/Espo/Modules/Crm/Resources/i18n/en_US/Lead.json
index 9fc40beb6e..6460f0a978 100644
--- a/application/Espo/Modules/Crm/Resources/i18n/en_US/Lead.json
+++ b/application/Espo/Modules/Crm/Resources/i18n/en_US/Lead.json
@@ -31,7 +31,8 @@
"opportunityAmountCurrency": "Opportunity Amount Currency",
"acceptanceStatusMeetings": "Acceptance Status (Meetings)",
"acceptanceStatusCalls": "Acceptance Status (Calls)",
- "originalEmail": "Original Email"
+ "originalEmail": "Original Email",
+ "pipeline": "Pipeline"
},
"links": {
"targetLists": "Target Lists",
@@ -41,7 +42,8 @@
"createdContact": "Contact",
"createdOpportunity": "Opportunity",
"cases": "Cases",
- "documents": "Documents"
+ "documents": "Documents",
+ "pipeline": "Pipeline"
},
"options": {
"status": {
diff --git a/application/Espo/Resources/layouts/LeadCapture/detail.json b/application/Espo/Resources/layouts/LeadCapture/detail.json
index 26f3228ca1..637f177ca1 100644
--- a/application/Espo/Resources/layouts/LeadCapture/detail.json
+++ b/application/Espo/Resources/layouts/LeadCapture/detail.json
@@ -5,7 +5,8 @@
[{"name": "subscribeToTargetList", "inlineEditDisabled": true}, {"name": "campaign"}],
[{"name": "subscribeContactToTargetList"}, {"name": "targetList"}],
[{"name": "targetTeam"}, {"name": "leadSource"}],
- [{"name": "duplicateCheck"}, {"name": "phoneNumberCountry"}]
+ [{"name": "duplicateCheck"}, {"name": "phoneNumberCountry"}],
+ [{"name": "pipeline"}, false]
]
},
{
diff --git a/application/Espo/Resources/metadata/clientDefs/LeadCapture.json b/application/Espo/Resources/metadata/clientDefs/LeadCapture.json
index ece82f4efb..16654fbe7c 100644
--- a/application/Espo/Resources/metadata/clientDefs/LeadCapture.json
+++ b/application/Espo/Resources/metadata/clientDefs/LeadCapture.json
@@ -5,6 +5,14 @@
"detail": "views/lead-capture/record/detail",
"list": "views/lead-capture/record/list"
},
+ "viewSetupHandlers": {
+ "record/detail": [
+ "handlers/lead-capture/record-detail-view-setup"
+ ],
+ "record/edit": [
+ "handlers/lead-capture/record-detail-view-setup"
+ ]
+ },
"sidePanels": {
"detail": [
{
@@ -29,6 +37,9 @@
"layout": "listForLeadCapture",
"select": false,
"create": false
+ },
+ "pipeline": {
+ "selectHandler": "handlers/lead-capture/pipeline-select-handler"
}
}
}
diff --git a/application/Espo/Resources/metadata/entityDefs/LeadCapture.json b/application/Espo/Resources/metadata/entityDefs/LeadCapture.json
index 664eb5237c..13efa40d3d 100644
--- a/application/Espo/Resources/metadata/entityDefs/LeadCapture.json
+++ b/application/Espo/Resources/metadata/entityDefs/LeadCapture.json
@@ -118,6 +118,13 @@
"default": "Web Site",
"audited": true
},
+ "pipeline": {
+ "type": "link",
+ "validatorClassNameList": [
+ "Espo\\Classes\\FieldValidators\\LeadCapture\\Pipeline\\Valid"
+ ],
+ "autocompleteOnEmpty": true
+ },
"apiKey": {
"type": "varchar",
"maxLength": 36,
@@ -268,6 +275,10 @@
"type": "hasMany",
"entity": "LeadCaptureLogRecord",
"foreign": "leadCapture"
+ },
+ "pipeline": {
+ "type": "belongsTo",
+ "entity": "Pipeline"
}
},
"collection": {
diff --git a/application/Espo/Resources/metadata/recordDefs/LeadCapture.json b/application/Espo/Resources/metadata/recordDefs/LeadCapture.json
index a20f9f0994..0a9ece96b2 100644
--- a/application/Espo/Resources/metadata/recordDefs/LeadCapture.json
+++ b/application/Espo/Resources/metadata/recordDefs/LeadCapture.json
@@ -13,5 +13,11 @@
"beforeCreateHookClassNameList": [
"Espo\\Classes\\RecordHooks\\LeadCapture\\BeforeCreate"
],
+ "createInputFilterClassNameList": [
+ "Espo\\Classes\\Record\\LeadCapture\\InputFilter"
+ ],
+ "updateInputFilterClassNameList": [
+ "Espo\\Classes\\Record\\LeadCapture\\InputFilter"
+ ],
"loadAdditionalFieldsAfterUpdate": true
}
diff --git a/application/Espo/Tools/LeadCapture/CaptureService.php b/application/Espo/Tools/LeadCapture/CaptureService.php
index 51d67688a4..d2de2c1f25 100644
--- a/application/Espo/Tools/LeadCapture/CaptureService.php
+++ b/application/Espo/Tools/LeadCapture/CaptureService.php
@@ -61,6 +61,7 @@ use Espo\Modules\Crm\Entities\Contact;
use Espo\Modules\Crm\Entities\Lead;
use Espo\Tools\LeadCapture\Jobs\OptInConfirmation;
use Espo\Tools\Captcha\Checker as CaptchaChecker;
+use Espo\Tools\Pipeline\MetadataProvider as PipelineMetadataProvider;
use stdClass;
use DateTime;
@@ -78,6 +79,7 @@ class CaptureService
private PhoneNumberSanitizer $phoneNumberSanitizer,
private ServiceContainer $serviceContainer,
private CaptchaChecker $captchaChecker,
+ private PipelineMetadataProvider $pipelineMetadataProvider,
) {}
/**
@@ -504,6 +506,8 @@ class CaptureService
$lead->setSource($leadCapture->getLeadSource());
}
+ $this->setPipeline($leadCapture, $lead);
+
if ($leadCapture->getCampaignId()) {
$lead->setCampaign(Link::create($leadCapture->getCampaignId()));
}
@@ -770,4 +774,28 @@ class CaptureService
return $leadCapture;
}
+
+ private function setPipeline(LeadCapture $leadCapture, Lead $lead): void
+ {
+ if (
+ !$this->pipelineMetadataProvider->isEnabled(Lead::ENTITY_TYPE) ||
+ !$leadCapture->getPipeline()
+ ) {
+ return;
+ }
+
+ $pipeline = $leadCapture->getPipeline();
+
+ $lead->set(Field::PIPELINE . 'Id', $pipeline->getId());
+ $lead->set(Field::PIPELINE . 'Name', $pipeline->getName());
+
+ $firstStage = $pipeline->getStages()[0] ?? null;
+
+ if (!$firstStage) {
+ return;
+ }
+
+ $lead->set(Field::PIPELINE_STAGE . 'Id', $firstStage->getId());
+ $lead->set(Field::PIPELINE_STAGE . 'Name', $firstStage->getName());
+ }
}
diff --git a/client/src/handlers/lead-capture/pipeline-select-handler.js b/client/src/handlers/lead-capture/pipeline-select-handler.js
new file mode 100644
index 0000000000..e91fc4cf2d
--- /dev/null
+++ b/client/src/handlers/lead-capture/pipeline-select-handler.js
@@ -0,0 +1,45 @@
+/************************************************************************
+ * This file is part of EspoCRM.
+ *
+ * EspoCRM – Open Source CRM application.
+ * Copyright (C) 2014-2026 EspoCRM, Inc.
+ * 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 SelectRelatedHandler from 'handlers/select-related';
+
+// noinspection JSUnusedGlobalSymbols
+export default class extends SelectRelatedHandler {
+
+ async getFilters(model) {
+ return {
+ advanced: {
+ entityType: {
+ type: 'in',
+ attribute: 'entityType',
+ value: ['Lead'],
+ },
+ },
+ };
+ }
+}
diff --git a/client/src/handlers/lead-capture/record-detail-view-setup.js b/client/src/handlers/lead-capture/record-detail-view-setup.js
new file mode 100644
index 0000000000..8020066564
--- /dev/null
+++ b/client/src/handlers/lead-capture/record-detail-view-setup.js
@@ -0,0 +1,53 @@
+/************************************************************************
+ * This file is part of EspoCRM.
+ *
+ * EspoCRM – Open Source CRM application.
+ * Copyright (C) 2014-2026 EspoCRM, Inc.
+ * 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 {inject} from 'di';
+import Metadata from 'metadata';
+
+export default class LeadCaptureRecordDetailViewSetupHandler {
+
+ /**
+ * @private
+ * @type {Metadata}
+ */
+ @inject(Metadata)
+ metadata
+
+ /**
+ * @param {import('views/record/detail').default} view
+ */
+ constructor(view) {
+ this.view = view;
+ }
+
+ process() {
+ if (!this.metadata.get(`scopes.Lead.pipelines`)) {
+ this.view.hideField('pipeline', true);
+ }
+ }
+}