Scope Parent link paremeter

This commit is contained in:
Yurii
2026-06-06 12:56:57 +03:00
parent c4a213cc1c
commit ac201012c9
4 changed files with 84 additions and 4 deletions

View File

@@ -51,6 +51,11 @@ class Field
public const VERSION_NUMBER = 'versionNumber';
public const string IS_LOCKED = 'isLocked';
/**
* @since 10.0.0
*/
public const string ACCOUNT = 'account';
/**
* @since 10.0.0
*/

View File

@@ -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 MetadataProvider
return $link;
}
$link = self::LINK_ACCOUNT;
$link = Field::ACCOUNT;
$relationDefs = $this->defs
->getEntity($entityType)
@@ -74,4 +73,25 @@ class MetadataProvider
return $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;
}
}

View File

@@ -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.",

View File

@@ -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));
}
}