I am using Form Classes to build the various form in my project.
In the Entity Type file, for the buildForm function, there is a secondary parameter of \"array $options\
Well, it turns out, Gregoires answer was very close, but gave me and "Undefined variable" error when trying to actually but the variable into the createQueryBuilder function.
I spent a while trying to figure out why and found the issue. You have to add an extra parameter to the function in the "query_builder" option, like such:
'query_builder' => function(EntityRepository $er) use ($options) {
return $er->createQueryBuilder('u')
->where('u.section = :id')
->setParameter('id', $options['id'])
->orderBy('u.root', 'ASC')
->addOrderBy('u.lft', 'ASC');
},
The magic setting being "use ($options)". This allows you to successfully use $options['id'] in the Query Builder.