Skip to content

Commit

Permalink
Use ClassUtils to get the classname of the subject
Browse files Browse the repository at this point in the history
This prevents a mixup when the subject is a Doctrine proxy.
  • Loading branch information
jorrit committed Jun 28, 2021
1 parent 14ca68d commit f76555e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Admin/Extension/CloneAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Jorrit\SonataCloneActionBundle\Admin\Extension;

use Doctrine\Common\Util\ClassUtils;
use Doctrine\ORM\EntityManagerInterface;
use Gedmo\Translatable\TranslatableListener;
use Jorrit\SonataCloneActionBundle\Controller\CloneController;
Expand Down Expand Up @@ -60,7 +61,7 @@ public function alterNewInstance(AdminInterface $admin, $object)
}

$subject = $request->attributes->get(self::REQUEST_ATTRIBUTE);
$subjectclass = get_class($subject);
$subjectclass = ClassUtils::getClass($subject);

$idfields = $admin->getModelManager()->getIdentifierFieldNames($subjectclass);
$propertyAccessor = PropertyAccess::createPropertyAccessor();
Expand Down Expand Up @@ -151,7 +152,8 @@ public function prePersist(AdminInterface $admin, $object)

if ($this->translatableListener !== null && $object instanceof AbstractPersonalTranslatable) {
$eventAdapter = new \Gedmo\Translatable\Mapping\Event\Adapter\ORM();
$config = $this->translatableListener->getConfiguration($this->entityManager, get_class($subject));
$subjectclass = ClassUtils::getClass($subject);
$config = $this->translatableListener->getConfiguration($this->entityManager, $subjectclass);
$translationClass = $this->translatableListener->getTranslationClass($eventAdapter, $config['useObjectClass']);

$translationRepository = $this->entityManager->getRepository($translationClass);
Expand Down

0 comments on commit f76555e

Please sign in to comment.