EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
Scope Parent link paremeter
Yuriiac201012c9b3
diff --git a/application/Espo/Core/Name/Field.php b/application/Espo/Core/Name/Field.phpindex fe98be7005..c073600332 100644--- a/application/Espo/Core/Name/Field.php+++ b/application/Espo/Core/Name/Field.php@@ -51,6 +51,11 @@ class Fieldpublic const VERSION_NUMBER = 'versionNumber';public const string IS_LOCKED = 'isLocked';+ /**+ * @since 10.0.0+ */+ public const string ACCOUNT = 'account';+/*** @since 10.0.0*/diff --git a/application/Espo/Tools/Object/MetadataProvider.php b/application/Espo/Tools/Object/MetadataProvider.phpindex 7daeb9db25..fba3439de3 100644--- a/application/Espo/Tools/Object/MetadataProvider.php+++ b/application/Espo/Tools/Object/MetadataProvider.php@@ -29,6 +29,7 @@namespace Espo\Tools\Object;+use Espo\Core\Name\Field;use Espo\Core\Utils\Metadata;use Espo\Modules\Crm\Entities\Account;use Espo\ORM\Defs;@@ -39,8 +40,6 @@ use Espo\ORM\Type\RelationType;*/class MetadataProvider{- private const string LINK_ACCOUNT = 'account';-public function __construct(private Metadata $metadata,private Defs $defs,@@ -54,7 +53,7 @@ class MetadataProviderreturn $link;}- $link = self::LINK_ACCOUNT;+ $link = Field::ACCOUNT;$relationDefs = $this->defs->getEntity($entityType)@@ -74,4 +73,25 @@ class MetadataProviderreturn $link;}++ public function getParentLink(string $entityType): ?string+ {+ $link = $this->metadata->get("scopes.$entityType.parentLink");++ if ($link) {+ return $link;+ }++ $link = Field::PARENT;++ $relationDefs = $this->defs+ ->getEntity($entityType)+ ->tryGetRelation($link);++ if ($relationDefs?->getType() !== RelationType::BELONGS_TO_PARENT) {+ return null;+ }++ return $link;+ }}diff --git a/schema/metadata/scopes.json b/schema/metadata/scopes.jsonindex 28a6552aaa..f3637ab961 100644--- a/schema/metadata/scopes.json+++ b/schema/metadata/scopes.json@@ -333,7 +333,11 @@},"accountLink": {"type": "string",- "description": "A link determining the Account the record belongs to. As of v10.0."+ "description": "A link determining the Account the record belongs to. The system falls back to 'account' if such a link exists. As of v10.0."+ },+ "parentLink": {+ "type": "string",+ "description": "A link determining the parent record. For example, a project is a parent for a task. The system falls back to 'parent' if such a link exists. As of v10.0."},"entityManager": {"description": "Entity manager items availability.",diff --git a/tests/integration/Espo/Tools/Object/MetadataProviderTest.php b/tests/integration/Espo/Tools/Object/MetadataProviderTest.phpnew file mode 100644index 0000000000..07eb6a3572--- /dev/null+++ b/tests/integration/Espo/Tools/Object/MetadataProviderTest.php@@ -0,0 +1,51 @@+<?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 tests\integration\Espo\Tools\Object;++use Espo\Core\Name\Field;+use Espo\Modules\Crm\Entities\Meeting;+use Espo\Modules\Crm\Entities\Opportunity;+use Espo\Modules\Crm\Entities\Task;+use Espo\Tools\Object\MetadataProvider;+use tests\integration\Core\BaseTestCase;++class MetadataProviderTest extends BaseTestCase+{+ public function testGetLinks(): void+ {+ $provider = $this->getInjectableFactory()->create(MetadataProvider::class);++ $this->assertEquals(Field::ACCOUNT, $provider->getAccountLink(Opportunity::ENTITY_TYPE));+ $this->assertEquals(Field::ACCOUNT, $provider->getAccountLink(Meeting::ENTITY_TYPE));++ $this->assertEquals(Field::PARENT, $provider->getParentLink(Meeting::ENTITY_TYPE));+ $this->assertEquals(Field::PARENT, $provider->getParentLink(Task::ENTITY_TYPE));+ }+}