Symfony sfDoctrineGuard plugin sfGuardUser module
Posted
by Joe Mc
on Stack Overflow
See other posts from Stack Overflow
or by Joe Mc
Published on 2010-06-08T15:21:54Z
Indexed on
2010/06/12
12:42 UTC
Read the original article
Hit count: 483
When using sfDoctrineGuard plugin, it automatically generates the backend administration functionality where I can edit users of the system and assign them permissions.
So I visit http://.../backend_dev.php/sf_guard_user/:id/edit where I am presented with the user's information including the available permissions to select.
By default the permissions are shown as a multiple select box, HTML follows:
<select name="sf_guard_user[permissions_list][]" multiple="multiple" id="sf_guard_user_permissions_list">
<option value="1">Permission1</option>
<option value="2">Permission2</option>
<option value="3">Permission3</option>
<option value="4">Permission4</option>
</select>
What I would prefer is a list of checkboxes. So I searched around and found that if I add the option "expanded" set to true to the following code:
'permissions_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'sfGuardPermission', 'expanded' => true,)),
The code is part of this file: lib/form/doctrine/sfDoctrineGuardPlugin/base/BasesfGuardUserForm.class.php. I don't think I should've edited this file (potential for changes to be overwritten should sfDoctrineGuard ever be re-installed) but couldn't think of another way to make it work.
The generated HTML is as follows:
<ul class="checkbox_list">
<li><input name="sf_guard_user[permissions_list][]" type="checkbox" value="1" id="sf_guard_user_permissions_list_1" /> <label for="sf_guard_user_permissions_list_1">Permission1</label></li>
<li><input name="sf_guard_user[permissions_list][]" type="checkbox" value="2" id="sf_guard_user_permissions_list_2" /> <label for="sf_guard_user_permissions_list_2">Permission2</label></li>
<li><input name="sf_guard_user[permissions_list][]" type="checkbox" value="3" id="sf_guard_user_permissions_list_3" /> <label for="sf_guard_user_permissions_list_3">Permission3</label></li>
<li><input name="sf_guard_user[permissions_list][]" type="checkbox" value="4" id="sf_guard_user_permissions_list_4" /> <label for="sf_guard_user_permissions_list_4">Permission4</label></li>
</ul>
What I need to do now is split up the permissions based on their prefix. For example if I had permissions named user_action1, user_action2, file_action1, file_action2, they would display like:
User
checkbox (custom label) Action One
checkbox Action Two
File
checkbox (custom label) Action One
checkbox Action Two
but have no idea where to start with this. It would be easy if there was a template to edit but since I'm dealing with the Forms framework it is my understanding that the templates are generated on the fly - I can see them in my symonfy cache folder.
How would I go about this?
I started writing my own sfWidgetFormDoctrineChoicePermission class that extends the same class as sfWidgetFormDoctrineChoice but am struggling to edit the rendering functions correctly for the desired output. Is this the correct way to go about this work?
I also need to integrate my sfGuardUserProfile model into the edit user page (same as above), I read somwhere that editing the generator.yml file for the sfGuardUser plugin module and simply adding the field names from the sfGuardUserProfile table would make it work, but sadly it doesn't.
Any help with any of my queries would be appreciated.
Thanks
© Stack Overflow or respective owner