From c2f4afd52020c64bb10917f87bf9fda2b2c75a0c Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Mon, 23 Jun 2025 18:13:59 +0300 Subject: [PATCH] entity factory create with additional attributes --- application/Espo/Core/ORM/EntityFactory.php | 22 +++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/application/Espo/Core/ORM/EntityFactory.php b/application/Espo/Core/ORM/EntityFactory.php index bc1e04e795..944c4c9c0d 100644 --- a/application/Espo/Core/ORM/EntityFactory.php +++ b/application/Espo/Core/ORM/EntityFactory.php @@ -77,6 +77,14 @@ class EntityFactory implements EntityFactoryInterface } public function create(string $entityType): Entity + { + return $this->createInternal($entityType); + } + + /** + * @param ?array $attributeDefs + */ + private function createInternal(string $entityType, ?array $attributeDefs = null): Entity { $className = $this->getClassName($entityType); @@ -90,6 +98,10 @@ class EntityFactory implements EntityFactoryInterface throw new RuntimeException("Entity '$entityType' is not defined in metadata."); } + if ($attributeDefs) { + $defs['attributes'] = array_merge($defs['attributes'] ?? [], $attributeDefs); + } + $relations = $this->injectableFactory->createWithBinding( RDBRelations::class, BindingContainerBuilder::create() @@ -123,6 +135,16 @@ class EntityFactory implements EntityFactoryInterface return $entity; } + /** + * @param array $attributeDefs + * @internal + * @noinspection PhpUnused + */ + public function createWithAdditionalAttributes(string $entityType, array $attributeDefs): Entity + { + return $this->createInternal($entityType, $attributeDefs); + } + /** * @return class-string */