Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save leevigraham/6249125 to your computer and use it in GitHub Desktop.
Save leevigraham/6249125 to your computer and use it in GitHub Desktop.
case ('admin' === $requestScopeDiscriminator) :
// Set default options for form control
$options = array(
'label' => 'Department',
'class' => 'MlfAppBundle:VenueDepartment',
'multiple' => true,
'endpointIndex' => array(
'mlf_back_end_venueDepartment_index',
array(
'_format' => 'json'
)
),
'attr' => array(
'controlInput' => array(
'class' => 'ControlInput--select2EntitySelect',
'data-placeholder' => 'Select a venue department'
),
'control' => array('class' => 'Control--ghost'),
'th' => array('style' => 'width:150px;'),
'td' => array('class' => 'u-pad-none')
)
);
// This is where shit gets real!
// If $venueDepartment is false then we shouldn't try to load anything hence returning a blank array for choices
if(false === $venueDepartmentIds) {
$options['choices'] = array();
// Else we need a query builder to filter the options based on the selected entities
} else {
$options['query_builder'] = function (VenueDepartmentRepository $repo) use ($venueDepartmentIds) {
$qb = $repo->createFindByQueryBuilder(array(
'id' => $venueDepartmentIds
));
return $qb;
};
}
// Create the form field
$form->add(
'venueDepartments',
'select2EntitySearch',
$options
);
break;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment