EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
entity factory create with additional attributes
Yuri Kuznetsovc2f4afd52020
diff --git a/application/Espo/Core/ORM/EntityFactory.php b/application/Espo/Core/ORM/EntityFactory.phpindex 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<string, mixed> $attributeDefs+ */+ private function createInternal(string $entityType, ?array $attributeDefs = null): Entity{$className = $this->getClassName($entityType);@@ -90,6 +98,10 @@ class EntityFactory implements EntityFactoryInterfacethrow 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 EntityFactoryInterfacereturn $entity;}+ /**+ * @param array<string, mixed> $attributeDefs+ * @internal+ * @noinspection PhpUnused+ */+ public function createWithAdditionalAttributes(string $entityType, array $attributeDefs): Entity+ {+ return $this->createInternal($entityType, $attributeDefs);+ }+/*** @return class-string<Entity>*/