<p dir="auto">Is it possible to filter the choicelist after querying the entities?<br>
I know that you can filter it with the query_builder option but in some case you can't filter in this way.<br>
For example if you use "array" as column definition in your entity.</p>
<p dir="auto">I find only bad way to resolve this problem:</p>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$builder-&gt;add(
    'contact',
    'entity',
    array(
        'query_builder' =&gt; function (EntityRepository $repository) {
            return $repository-&gt;createQueryBuilder('c')
                -&gt;where('c.roles LIKE :role')-&gt;setParameter('role', '%ROLE_CONTACT%');
        },
        'label'         =&gt; 'Contact',
        'class'         =&gt; 'AppBundle\Entity\User',
        'required'      =&gt; false
    )
)"><pre class="notranslate"><span class="pl-s1"><span class="pl-c1">$</span>builder</span>-&gt;<span class="pl-en">add</span>(
    <span class="pl-s">'contact'</span>,
    <span class="pl-s">'entity'</span>,
    <span class="pl-en">array</span>(
        <span class="pl-s">'query_builder'</span> =&gt; <span class="pl-k">function</span> (<span class="pl-smi"><span class="pl-smi">EntityRepository</span></span> <span class="pl-s1"><span class="pl-c1">$</span>repository</span>) {
            <span class="pl-k">return</span> <span class="pl-s1"><span class="pl-c1">$</span>repository</span>-&gt;<span class="pl-en">createQueryBuilder</span>(<span class="pl-s">'c'</span>)
                -&gt;<span class="pl-en">where</span>(<span class="pl-s">'c.roles LIKE :role'</span>)-&gt;<span class="pl-en">setParameter</span>(<span class="pl-s">'role'</span>, <span class="pl-s">'%ROLE_CONTACT%'</span>);
        },
        <span class="pl-s">'label'</span>         =&gt; <span class="pl-s">'Contact'</span>,
        <span class="pl-s">'class'</span>         =&gt; <span class="pl-s">'AppBundle\Entity\User'</span>,
        <span class="pl-s">'required'</span>      =&gt; <span class="pl-c1">false</span>
    )
)</pre></div>
<p dir="auto">Or you must implement your own loader.</p>
<p dir="auto">I think it would be nice and easy to use if you have an option to filter the data after hydration.<br>
Like this:</p>
<div class="highlight highlight-text-html-php notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$builder-&gt;add(
    'contact',
    'entity',
    array(
        'choice_filter' =&gt; function ($user) {
            return $user-&gt;hasRole('ROLE_CONTACT');
        },
        'label'         =&gt; 'Contact',
        'class'         =&gt; 'AppBundle\Entity\User',
        'required'      =&gt; false
    )
)"><pre class="notranslate"><span class="pl-s1"><span class="pl-c1">$</span>builder</span>-&gt;<span class="pl-en">add</span>(
    <span class="pl-s">'contact'</span>,
    <span class="pl-s">'entity'</span>,
    <span class="pl-en">array</span>(
        <span class="pl-s">'choice_filter'</span> =&gt; <span class="pl-k">function</span> (<span class="pl-s1"><span class="pl-c1">$</span>user</span>) {
            <span class="pl-k">return</span> <span class="pl-s1"><span class="pl-c1">$</span>user</span>-&gt;<span class="pl-en">hasRole</span>(<span class="pl-s">'ROLE_CONTACT'</span>);
        },
        <span class="pl-s">'label'</span>         =&gt; <span class="pl-s">'Contact'</span>,
        <span class="pl-s">'class'</span>         =&gt; <span class="pl-s">'AppBundle\Entity\User'</span>,
        <span class="pl-s">'required'</span>      =&gt; <span class="pl-c1">false</span>
    )
)</pre></div>
<p dir="auto">As with <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="64227963" data-permission-text="Title is private" data-url="https://github.com/symfony/symfony/issues/14050" data-hovercard-type="pull_request" data-hovercard-url="/symfony/symfony/pull/14050/hovercard" href="https://github.com/symfony/symfony/pull/14050">#14050</a> <code class="notranslate">choice_filter</code> can be a callback or property path. And i think it should be add in ChoiceType so you can filter every choicelist.</p>
<p dir="auto">I know you should use query_builder to filter the data in the database but in some case you don't have a choice.</p>
<table role="table">
<thead>
<tr>
<th>Q</th>
<th>A</th>
</tr>
</thead>
<tbody>
<tr>
<td>Bug report?</td>
<td>yes</td>
</tr>
<tr>
<td>Feature request?</td>
<td>no</td>
</tr>
<tr>
<td>BC Break report?</td>
<td>no</td>
</tr>
<tr>
<td>RFC?</td>
<td>no</td>
</tr>
<tr>
<td>Symfony version</td>
<td>3.1.8</td>
</tr>
</tbody>
</table>
<p dir="auto">I use php 7.0.0 with symfony 3.1.8. The issue is when I got errors from php - symfony doesn't return me stack trace, all I can see is "Internal Server Error" page. In logs of apache I found FastCGI: comm with server "/Applications/MAMP/fcgi-bin/php7.0.0.fcgi" aborted: error parsing headers: duplicate header 'Content-Type'<br>
I started debugging, and that's what I found. I use php scalar type hinting, so when the wrong type comes as argument, php returns TypeError, symfony catches it, and then step by step:</p>
<ol dir="auto">
<li>Symfony\Component\Debug\ErrorHandler:handleException<br>
call_user_func($this-&gt;exceptionHandler, $exception) L:546</li>
<li>Symfony\Component\Debug\ExceptionHandler:handle<br>
$this-&gt;sendPhpResponse($exception); L:121</li>
<li>Symfony\Component\Debug\ExceptionHandler:sendPhpResponse<br>
header('Content-Type: text/html; charset='.$this-&gt;charset); L:173 - which sends me header of content type first time.</li>
<li>Symfony\Component\Debug\ExceptionHandler:handle (continue)<br>
call_user_func($this-&gt;handler, $exception); L:144</li>
<li>Symfony\Component\HttpKernel\HttpKernel:terminateWithException<br>
$response-&gt;sendHeaders(); L:104</li>
<li>Symfony\Component\HttpFoundation\Response:sendHeaders<br>
header($name.': '.$value, false, $this-&gt;statusCode); L:339 - which sends me header of content type second time.</li>
</ol>
<p dir="auto">The output of headers_list function:<br>
0 = "X-Powered-By: PHP/7.0.0"<br>
1 = "Content-Type: text/html; charset=UTF-8"<br>
2 = "Cache-Control: no-cache"<br>
3 = "X-Debug-Token: 242fbb"<br>
4 = "X-Debug-Token-Link: <a href="http://pr.project/app_dev.php/_profiler/242fbb" rel="nofollow">http://pr.project/app_dev.php/_profiler/242fbb</a>"<br>
5 = "Content-Type: text/html; charset=UTF-8"<br>
6 = "Date: Sun, 08 Jan 2017 18:45:04 GMT"</p>
<p dir="auto">Which causes error of duplicating headers.<br>
Please fix.</p>