Closed dasraab closed 4 years ago
thanks @dasraab!
thanks for merging! now i'm struggling to get the dev-master version to run with pimcore 6.6.0. Seems like its not yet compatible.
i'm trying to set the Users Groups via Form input. The RegistrationFormType looks like this:
<?php
class RegistrationFormType extends AbstractType
{
protected $class;
public function __construct($class)
{
$this->class = $class;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', TextType::class, [
'constraints' => [new NotBlank()],
'label' => 'Name (*)',
'required' => true
])
->add('groups', ChoiceType::class, [
'label' => 'Ich bin',
'required' => true,
'attr' => [
'required' => 'true',
'class' => 'form-select w-full'
],
'choices' => [
'bitte wählen' => false,
'Elternteil' => MembersGroup::getById(53),
'Lehrer' => MembersGroup::getById(54),
],
'constraints' => [
new NotBlank(),
]
])
->add('submit', SubmitType::class, [
'label' => 'members.registration.submit',
]);
$builder->get('groups')
->addModelTransformer(new CallbackTransformer(
function ($group) {
// transform the array to a string
if (is_object($group)) {
return $group->name;
} else {
return null;
}
},
function ($group) {
// transform the string back to an array
if (is_object($group)) {
return [$group];
} else {
return [];
}
}
))
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => $this->class,
'csrf_token_id' => 'registration'
]);
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'members_user_registration';
}
}
Saving the selected group doesn't seem to work with pimcore 6.6.0 anymore. the selected group gets lost somewhere in the process - if i dump the user right after form submit i can see that "groups" property is an array with the selected group but its not written into the db :/ do you have any idea where to look for the bug? thank you!
@dasraab sorry for the late response, this has been fixed within https://github.com/dachcom-digital/pimcore-members/issues/140
thank you for the update!
only set the initial groups if initial groups are present in the config. this prevents the groups field from being emptied when setting the groups-field via for example a form.