Skip to content

Instantly share code, notes, and snippets.

@symball
Last active March 10, 2016 06:31
Show Gist options
  • Save symball/88de2e42e435e93d8201 to your computer and use it in GitHub Desktop.
Save symball/88de2e42e435e93d8201 to your computer and use it in GitHub Desktop.
Sonata Admin DataGrid filter trying to use foreign text index
<?php
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
/* Get the filtered tags */
$repo = $this->getConfigurationPool()->getContainer()->get('repository.tag');
$temp = $repo->findByType('job-role---buy-side');
/* Work the results in to a choice compatible array */
$choices = array();
foreach ($temp as $entry) { $choices[$entry->getTitle()] = $entry->getTitle(); }
$datagridMapper
->add('buySideResponsibility', 'doctrine_mongo_callback', array(
'callback' => function($queryBuilder, $alias, $field, $value) {
if(!$value['value']) {
return true;
}
$queryBuilder
/* This is the referenceOne property that I would like to perform the text search on */
->field('buySideResponsibility')
->text('"'.$value['value'].'"');
return true;
}, 'field_type' => 'choice', 'field_options' => array(
'choices' => $choices
)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment