php - symfony2 auth in formbuillder -


I need to modify a form field attribute, when it is the user's specific user role.

I saw something similar to one asking:

  -> Addition ('description') if ($ user.hasRole (ROLE_SUPERADMIN)) - gt; ; ('Created')  

This will be enough for me because I need to do it once, but I am the one-builder. When a user has a specific user-role, then what is the way to be able to modify the properties?

The part I want to modify is the cashback tracehold field. In addition, it is a continuous form type and I can not put it in a different type of type

  // payment panel $ manufacturer-> create ('payment', 'form' Array ('virtual' = & gt; true, 'entry' => array ('class' => 'form-section'))) - & gt; Plus ('commission', 'integer') - & gt; ('CashbackThreshold', 'Integer')  

Edit

I have found a way to do this.

I have in my type:

  Private $ securityContax; Public function __ composition (SecurityContext $ securityContext) {$ this- & gt; SecurityContext = $ securityContext; } .... public function buildForm (FormBuilderInterface $ builder, array $ option) {$ disabled = false; If (false === $ this-> safety stamps- & gt; Uncredited ('ROLE_SUPER_ADMIN')) {$ disabled = true; } ... $ builder- & gt; Create ('Payment', 'form', array ('virtual' = & gt; true, 'atr ='> array ('square' => 'form-section'))) - & gt; Plus ('commission', 'integer') - & gt; Plus ('cachebackhold', 'integer', array ('disabled' = & gt; $ disabled))  

and I have more than my controller:

 
$ form = $ this- & gt; CreateForm (get new white label type ($-> $ (get-> 'security.context'), $ whiteLabel); Of course you can use a conditional format in the format:

if ( $ This- & gt; user.hasRole (ROLE_SUPERADMIN)) {$ builder-> Add ('createdAt')}

But you want to see the user in $ form type controller, or simply this boolean as an example:

 < Code> private $ user; Public function __ conversion ($ user) {$ this- & gt; User = $ user; }  

And whenever you type the form, do not forget to add it:

  $ user = $ this-> ('Security.context') - & gt; GetToken () - & gt; GetUser (); $ Form = $ this- & gt; CreateForm (new yourFormType ($ user) // ....)  

is to ensure that this is not the recommended way of doing it; I just wanted to help you Wanted.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -