Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow map calculated DB field to entity property #6263

Open
wants to merge 1 commit into
base: 4.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/Factory/EntityFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use EasyCorp\Bundle\EasyAdminBundle\Exception\EntityNotFoundException;
use EasyCorp\Bundle\EasyAdminBundle\Security\Permission;
use Symfony\Component\ExpressionLanguage\Expression;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

Expand All @@ -28,14 +29,16 @@ final class EntityFactory
private AuthorizationCheckerInterface $authorizationChecker;
private ManagerRegistry $doctrine;
private EventDispatcherInterface $eventDispatcher;
private PropertyAccessorInterface $propertyAccessor;

public function __construct(FieldFactory $fieldFactory, ActionFactory $actionFactory, AuthorizationCheckerInterface $authorizationChecker, ManagerRegistry $doctrine, EventDispatcherInterface $eventDispatcher)
public function __construct(FieldFactory $fieldFactory, ActionFactory $actionFactory, AuthorizationCheckerInterface $authorizationChecker, ManagerRegistry $doctrine, EventDispatcherInterface $eventDispatcher, PropertyAccessorInterface $propertyAccessor)
{
$this->fieldFactory = $fieldFactory;
$this->actionFactory = $actionFactory;
$this->authorizationChecker = $authorizationChecker;
$this->doctrine = $doctrine;
$this->eventDispatcher = $eventDispatcher;
$this->propertyAccessor = $propertyAccessor;
}

public function processFields(EntityDto $entityDto, FieldCollection $fields): void
Expand Down Expand Up @@ -80,6 +83,14 @@ public function createCollection(EntityDto $entityDto, ?iterable $entityInstance
$entityDtos = [];

foreach ($entityInstances as $entityInstance) {
if (is_array($entityInstance)) {
$tmp = $entityInstance;
$entityInstance = $tmp[0];
unset($tmp[0]);
foreach ($tmp as $name => $value) {
$this->propertyAccessor->setValue($entityInstance, $name, $value);
}
}
$newEntityDto = $entityDto->newWithInstance($entityInstance);
$newEntityId = $newEntityDto->getPrimaryKeyValueAsString();
if (!$this->authorizationChecker->isGranted(Permission::EA_ACCESS_ENTITY, $newEntityDto)) {
Expand Down
Loading