diff --git a/application/Espo/Core/Record/Input/Filter.php b/application/Espo/Core/Record/Input/Filter.php index 4b00cf2ab8..8739cc887b 100644 --- a/application/Espo/Core/Record/Input/Filter.php +++ b/application/Espo/Core/Record/Input/Filter.php @@ -31,6 +31,8 @@ namespace Espo\Core\Record\Input; /** * An input filter. + * + * $entityType is passed to the constructor as of v9.3. */ interface Filter { diff --git a/application/Espo/Core/Record/Input/FilterProvider.php b/application/Espo/Core/Record/Input/FilterProvider.php index 4784726b6a..3eb1bbb4d9 100644 --- a/application/Espo/Core/Record/Input/FilterProvider.php +++ b/application/Espo/Core/Record/Input/FilterProvider.php @@ -31,6 +31,7 @@ namespace Espo\Core\Record\Input; use Espo\Core\Acl; use Espo\Core\Binding\BindingContainerBuilder; +use Espo\Core\Binding\ContextualBinder; use Espo\Core\InjectableFactory; use Espo\Core\Utils\Metadata; use Espo\Entities\User; @@ -49,17 +50,13 @@ class FilterProvider */ public function getForCreate(string $entityType): array { - $classNameList = $this->getCreateClassNameList($entityType); + $list = []; - $binding = BindingContainerBuilder::create() - ->bindInstance(User::class, $this->user) - ->bindInstance(Acl::class, $this->acl) - ->build(); + foreach ($this->getCreateClassNameList($entityType) as $className) { + $list[] = $this->createFilter($className, $entityType); + } - return array_map( - fn ($className) => $this->injectableFactory->createWithBinding($className, $binding), - $classNameList - ); + return $list; } /** @@ -67,17 +64,29 @@ class FilterProvider */ public function getForUpdate(string $entityType): array { - $classNameList = $this->getUpdateClassNameList($entityType); + $list = []; + foreach ($this->getUpdateClassNameList($entityType) as $className) { + $list[] = $this->createFilter($className, $entityType); + } + + return $list; + } + + /** + * @param class-string $className + */ + private function createFilter(string $className, string $entityType): Filter + { $binding = BindingContainerBuilder::create() ->bindInstance(User::class, $this->user) ->bindInstance(Acl::class, $this->acl) + ->inContext($className, function (ContextualBinder $binder) use ($entityType) { + $binder->bindValue('$entityType', $entityType); + }) ->build(); - return array_map( - fn ($className) => $this->injectableFactory->createWithBinding($className, $binding), - $classNameList - ); + return $this->injectableFactory->createWithBinding($className, $binding); } /**