Skip to content

Commit

Permalink
fix(UserSecurityType): Missing CallbackTransformer on user chroot for…
Browse files Browse the repository at this point in the history
…m normalization
  • Loading branch information
ambroisemaupate committed Sep 4, 2023
1 parent ad15ace commit 0d9a1b2
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/Rozier/src/Forms/UserSecurityType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

namespace Themes\Rozier\Forms;

use RZ\Roadiz\CoreBundle\Entity\Node;
use RZ\Roadiz\CoreBundle\Entity\User;
use RZ\Roadiz\CoreBundle\Form\NodesType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\CallbackTransformer;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\FormBuilderInterface;
Expand Down Expand Up @@ -57,8 +59,21 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
$builder->add('chroot', NodesType::class, [
'label' => 'chroot',
'required' => false,
'multiple' => false,
]);
$builder->get('chroot')->addModelTransformer(new CallbackTransformer(
function (mixed $mixedEntities) {
if ($mixedEntities instanceof Node) {
return [$mixedEntities];
}
return [];
},
function (mixed $mixedIds) {
if (\is_array($mixedIds) && count($mixedIds) === 1) {
return $mixedIds[0];
}
return null;
}
));
}
}

Expand Down

0 comments on commit 0d9a1b2

Please sign in to comment.