Created
August 16, 2013 11:32
-
-
Save leevigraham/6249125 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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