<p dir="auto">I have some properties of a deeply nested entity that need to be decimal. I have them marked up that way via the ORM Doctrine column type. Symfony2 renders an input field with a pattern attribute.</p>
<p dir="auto">I am validating via AJAX. I post over the data, use the form bindRequest to setup an instance of the entity but then use the validator service.</p>
<p dir="auto">The thing I am finding is that if my user enters some letters 'abc' into a decimal-mapped column property, the bindRequest is setting the property to 0 (zero) rather than 'abc' so that the Type(float) constraint is always calling is_float(0) unless I specify an actual number in the field.</p>
<p dir="auto">Because I am using AJAX, the field validates behind the scenes due to this setting of 0 rather than 'abc' but my UI stays the same. as Symfony is not called again to regenerate it like you would have if I were posting the whole page.</p>
<p dir="auto">2 options really - figure out a way of returning the modified value back to my UI in the AJAX response to reset it, or be able to tell Symfony to validate the value before setting/casting the values on my entity so that it truly validates the input and not the post-casted values.</p>
<p dir="auto">I think actually the latter is what should truly be happening. I think Symfony should not be helping me out by casting values here.</p>
<p dir="auto">If you accidentally use <code class="notranslate">{% if is_granted('ROLE_EMPLOYEE') %}</code> in a view that does not have a Firewall/TokenStorage enabled the AuthorizationChecker throws an exception:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="new AuthenticationCredentialsNotFoundException('The token storage contains no authentication token. One possible reason may be that there is no firewall configured for this URL.');"><pre class="notranslate"><code class="notranslate">new AuthenticationCredentialsNotFoundException('The token storage contains no authentication token. One possible reason may be that there is no firewall configured for this URL.');
</code></pre></div>
<p dir="auto">The solution is to use this:</p>
<div class="highlight highlight-text-html-twig notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{% if app.security.token is not null and is_granted('ROLE_EMPLOYEE') %}"><pre class="notranslate">{% <span class="pl-k">if</span> <span class="pl-smi">app</span>.<span class="pl-smi">security</span>.<span class="pl-smi">token</span> <span class="pl-k">is not</span> <span class="pl-c1">null</span> <span class="pl-k">and</span> is_granted(<span class="pl-s"><span class="pl-pds">'</span>ROLE_EMPLOYEE<span class="pl-pds">'</span></span>) %}</pre></div>
<p dir="auto">Wouldn't it be better to just handle this exception inside SecurityExtension::isGranted and simply return <code class="notranslate">false</code>?</p>