views:

84

answers:

2

I've installed the sfDoctrineGuard plugin. Everything is working, I can use the /sf_guard_user/edit/:id page to edit a user.

I didn't like the way the permissions were listed as a select list, I wanted to display them as individual checkboxes split up based on the permission name. To do this I created a custom widget that extends sfWidgetFormChoice. This is working the way I want it as well, but my problem is the following:

To use my custom widget, I edited the following lines in this file:

lib/form/doctrine/sfDoctrineGuardPlugin/base/BasesfGuardUserForm.class.php

Before:

      'groups_list'      => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'sfGuardGroup')),
      'permissions_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'sfGuardPermission')),

After:

      'groups_list'      => new sfWidgetFormDoctrineChoice(array('multiple' => true,     'model' => 'sfGuardGroup', 'expanded' => true)),
      'permissions_list' => new myCustomPermissionWidget(),

That gives the correct outcome.

The problem is that I shouldn't have edited the Base class as any time I build my model the file is overwritten.

So I should edit this file:

lib/form/doctrine/sfDoctrineGuardPlugin/sfGuardUserForm.class.php

    class sfGuardUserForm extends PluginsfGuardUserForm
    {
      public function configure()
      {
        parent::configure();

        $this->setWidgets(array(
          'groups_list'      => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'sfGuardGroup', 'expanded' => true)),
          'permissions_list' => new myCustomPermissionWidget(),
        ));
      }
    }

But this does not work. I've tried the code inside a new function setup(), with parent::setup() before and after my code but still nothing.

PluginsfGuardUserForm is abstract and extends BasesfGuardUserForm but I don't see why that would stop it from working.

Any ideas?

Thanks

A: 

Try editing the

lib/vendor/symfony/lib/plugins/sfDoctrineGuardPlugin/lib/form/doctrine/PluginsfGuardUserForm.class.php

"vendor" and "symfony" will be whatever you have it as on your install. This worked for me when I wanted to remove the remember me checkbox from the signin form:

<?php

/**
 * sfGuardFormSignin for sfGuardAuth signin action
 *
 * @package    sfDoctrineGuardPlugin
 * @subpackage form
 * @author     Fabien Potencier <[email protected]>
 * @version    SVN: $Id: sfGuardFormSignin.class.php 23536 2009-11-02 21:41:21Z Kris.Wallsmith $
 */
class sfGuardFormSignin extends BasesfGuardFormSignin
{
  /**
   * @see sfForm
   */
  public function configure()
  {
    $this->widgetSchema->setFormFormatterName('list');
    unset($this['remember']);
  }
}

Was as simple as that.

Hope it helps

Luke

Luke
Thanks for your reply.I searched for PluginsfGuardUserForm.class.php and found it here:plugins/sfDoctrineGuardPlugin/lib/form/doctrine/PluginsfGuardUserForm.class.phpI also looked for lib/vendor/symfony/lib/plugins/sfDoctrineGuardPlugin/lib/form/doctrine but don't seem to have that directory.I get as far as lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/form which contains 2 files:sfFormDoctrine.class.phpsfFormFilterDoctrine.class.phpSo still stuck unfortunately.
Serg
Did you try editing the pluginsfGuardUserForm.class.php that you found? If so nothing happened? It might just be that we have slightly different directory structures.
Luke
A: 

I believe the edit user action uses the class sfGuardUserAdminForm which is in the plugin directory

Copy the file

plugins/sfDoctrineGuardPlugin/lib/form/doctrine/sfGuardUserAdminForm.class.php

into

lib/form/doctrine/

Then add this line to the configure() method

$this->setWidget('permissions_list' => new myCustomPermissionWidget());

You do not need to add a call to parent::configure() it is bad practice to do this in the form framework and you should only do it if you know you need to.

johnwards
Thanks for this, this is definitely along the lines of what I'm looking for, however I can't test at this time. Assuming your answer works, I'm still not sure as to why there is a BasesfGuardUser class, then an sfGuardUser class. To me it makes absolute sense that my changes be in the sfGuardUser class, but just doesn't seem to work. It doesn't even look like it is ever instantiated which could be a problem for later on.
Serg
Base class should never be touched. The pluton uses the admin user form for editing in the admin area. This is because it does it's own things I guess rather. It means you really need to want to make changes to the admin area edit.
johnwards
Excuse any typos, I'm on my phone...
johnwards