Reputation: 194
I'm following the question and answer here: One form with all row of one entity
My files are:
PermissionCollectionType:
class PermissionsCollectionType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('permissions', CollectionType::class, [
'entry_type' => PermissionsContentsType::class,
])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => null
));
}
}
PermissionsContentsType:
class PermissionsContentsType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', TextType::class, [
'label' => 'Name',
'attr' => [
'placeholder' => 'Name'
]
])
->add('view', CheckboxType::class, [
'mapped' => false,
'required' => false,
'label' => false
])
->add('new', CheckboxType::class, [
'mapped' => false,
'required' => false,
'label' => false
])
->add('edit', CheckboxType::class, [
'mapped' => false,
'required' => false,
'label' => false
])
->add('delete', CheckboxType::class, [
'mapped' => false,
'required' => false,
'label' => false
])
->add('accept', CheckboxType::class, [
'mapped' => false,
'required' => false,
'label' => false
])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Categories::class
]);
}
}
Controller:
public function permissionsAction(Request $request, EntityManagerInterface $em, $role, $type, UserInterface $user)
{
$categoriesRepository = $em->getRepository('App:Categories');
$list = $categoriesRepository->findAll();
$form = $this->createForm(PermissionsCollectionType::class, $list);
$form->handleRequest($request);
return $this->render('Acl\permissionForm.html.twig', [
'list' => $list,
'form' => $form->createView(),
]);
}
Twig:
{% extends 'base.html.twig' %}
{% block body %}
{{ form(form) }}
{% endblock %}
Unfortunately, the form displays only a word 'Permissions' and nothing more, like the list doesn't exist. What could be the issue or how to fix that?
Upvotes: 0
Views: 73
Reputation: 8374
your PermissionCollectionType
will look into your $list
array to find the permissions
key, which doesn't exist. To fix, try setting the key before giving it to the form (as is done in your linked question+answer):
//...
$list = array('permissions' => $list);
$form = $this->createForm(PermissionsCollectionType::class, $list);
//...
Upvotes: 2