Skip to content

Commit

Permalink
use FactoryInterface for building objects
Browse files Browse the repository at this point in the history
  • Loading branch information
aweichler committed Oct 9, 2024
1 parent d917945 commit 6ffc082
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/Controller/ClassController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -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();

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 6ffc082

Please sign in to comment.