From 6ffc0825e99e762001091741fb8a54d30a0e7f05 Mon Sep 17 00:00:00 2001 From: Andy Weichler Date: Wed, 9 Oct 2024 10:57:43 +0200 Subject: [PATCH] use FactoryInterface for building objects --- src/Controller/ClassController.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Controller/ClassController.php b/src/Controller/ClassController.php index 3ace618..ea2b9cd 100644 --- a/src/Controller/ClassController.php +++ b/src/Controller/ClassController.php @@ -23,6 +23,7 @@ use Pimcore\Db; use Pimcore\Model\DataObject; use Pimcore\Model\DataObject\Classificationstore; +use Pimcore\Model\FactoryInterface; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; @@ -53,7 +54,7 @@ class ClassController extends UserAwareController * * @throws \Exception */ - public function getClassDefinitionForColumnConfigAction(Request $request, EventDispatcherInterface $eventDispatcher) + public function getClassDefinitionForColumnConfigAction(Request $request, EventDispatcherInterface $eventDispatcher, FactoryInterface $factory) { $classId = $request->get('id'); $class = DataObject\ClassDefinition::getById($classId); @@ -108,7 +109,7 @@ public function getClassDefinitionForColumnConfigAction(Request $request, EventD } } - $this->considerClassificationStoreForColumnConfig($request, $class, $fieldDefinitions, $result, $eventDispatcher); + $this->considerClassificationStoreForColumnConfig($request, $class, $fieldDefinitions, $result, $eventDispatcher, $factory); return $this->jsonResponse($result); } @@ -119,7 +120,7 @@ public function getClassDefinitionForColumnConfigAction(Request $request, EventD * @param array $fieldDefinitions * @param array $result */ - private function considerClassificationStoreForColumnConfig(Request $request, ?DataObject\ClassDefinition $class, array $fieldDefinitions, array &$result, EventDispatcherInterface $eventDispatcher): void + private function considerClassificationStoreForColumnConfig(Request $request, ?DataObject\ClassDefinition $class, array $fieldDefinitions, array &$result, EventDispatcherInterface $eventDispatcher, FactoryInterface $factory): void { $displayMode = $this->getClassificationDisplayMode(); @@ -153,7 +154,9 @@ private function considerClassificationStoreForColumnConfig(Request $request, ?D $classString = 'Pimcore\\Model\\DataObject\\' . $class->getName(); $targetObjectId = intval($request->get('target_oid')); $targetObject = DataObject\Concrete::getById($targetObjectId); - $tmpObject = new $classString(); + $tmpObject = $factory->build($classString); + /** @var DataObject\Concrete $tmpObject */ + $db = Db::get(); foreach ($class->getFieldDefinitions() as $fieldDefinition) { if (!$fieldDefinition instanceof DataObject\ClassDefinition\Data\Classificationstore) {