diff --git a/application/Espo/Core/Select/Applier/Appliers/Additional.php b/application/Espo/Core/Select/Applier/Appliers/Additional.php index 225e7c5248..9d371e91f7 100644 --- a/application/Espo/Core/Select/Applier/Appliers/Additional.php +++ b/application/Espo/Core/Select/Applier/Appliers/Additional.php @@ -30,12 +30,12 @@ namespace Espo\Core\Select\Applier\Appliers; use Espo\Core\Binding\ContextualBinder; +use Espo\Core\Utils\Metadata; use Espo\ORM\Query\SelectBuilder as QueryBuilder; use Espo\Core\Select\SearchParams; use Espo\Core\InjectableFactory; use Espo\Core\Select\Applier\AdditionalApplier; use Espo\Core\Binding\BindingContainerBuilder; - use Espo\Entities\User; class Additional @@ -44,6 +44,7 @@ class Additional private User $user, private InjectableFactory $injectableFactory, private string $entityType, + private Metadata $metadata, ) {} /** @@ -51,6 +52,8 @@ class Additional */ public function apply(array $classNameList, QueryBuilder $queryBuilder, SearchParams $searchParams): void { + $classNameList = array_merge($this->getMandatoryClassNameList(), $classNameList); + foreach ($classNameList as $className) { $applier = $this->createApplier($className); @@ -73,4 +76,13 @@ class Additional ->build() ); } + + /** + * @return class-string[] + */ + private function getMandatoryClassNameList(): array + { + /** @var class-string[] */ + return $this->metadata->get("selectDefs.$this->entityType.additionalApplierClassNameList") ?? []; + } } diff --git a/application/Espo/Core/Select/SelectBuilder.php b/application/Espo/Core/Select/SelectBuilder.php index 9190259da8..cd9c73ad6a 100644 --- a/application/Espo/Core/Select/SelectBuilder.php +++ b/application/Espo/Core/Select/SelectBuilder.php @@ -495,10 +495,6 @@ class SelectBuilder { assert($this->queryBuilder !== null); - if (count($this->additionalApplierClassNameList) === 0) { - return; - } - $searchParams = SearchParams::create() ->withBoolFilterList($this->boolFilterList) ->withPrimaryFilter($this->primaryFilter) diff --git a/schema/metadata/selectDefs.json b/schema/metadata/selectDefs.json index 1f4e80ed15..611e3f449d 100644 --- a/schema/metadata/selectDefs.json +++ b/schema/metadata/selectDefs.json @@ -80,6 +80,13 @@ "type": "string", "description": "A field." } + }, + "additionalApplierClassNameList": { + "type": "array", + "items": { + "type": "string" + }, + "description": "Additional appliers. Should implement Espo\\Core\\Select\\Applier\\AdditionalApplier interface. Since v9.1.0." } } } diff --git a/tests/unit/Espo/Core/Select/SelectBuilderTest.php b/tests/unit/Espo/Core/Select/SelectBuilderTest.php index 504aedc74b..c7e94f3696 100644 --- a/tests/unit/Espo/Core/Select/SelectBuilderTest.php +++ b/tests/unit/Espo/Core/Select/SelectBuilderTest.php @@ -220,10 +220,12 @@ class SelectBuilderTest extends \PHPUnit\Framework\TestCase ); $this->additionalApplier - ->expects($this->never()) + ->expects($this->once()) ->method('apply') ->with( - $this->isInstanceOf(QueryBuilder::class) + [], + $this->isInstanceOf(QueryBuilder::class), + $this->isInstanceOf(SearchParams::class), ); $query = $this->selectBuilder