Skip to content

Instantly share code, notes, and snippets.

@merk
Created June 17, 2014 01:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save merk/af75c64ebbcfa06f16fe to your computer and use it in GitHub Desktop.
Save merk/af75c64ebbcfa06f16fe to your computer and use it in GitHub Desktop.
<?php
/**
* This file is part of the Infinite SSO project.
*
* (c) Infinite Networks Pty Ltd <http://www.infinite.net.au>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace AdminBundle\Form\Type;
use Doctrine\Common\Persistence\ManagerRegistry;
use Entity\Repository\EntityRepository;
use Entity\Specification as Spec;
use JMS\DiExtraBundle\Annotation as DI;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
/**
* @DI\FormType("admin_user")
*/
class UserType extends AbstractType
{
/**
* @var \Doctrine\Common\Persistence\ManagerRegistry
*/
private $registry;
/**
* @DI\InjectParams({
* "registry" = @DI\Inject("doctrine")
* })
* @param ManagerRegistry $registry
*/
public function __construct(ManagerRegistry $registry)
{
$this->registry = $registry;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$spec = new Spec\Sort(array('name' => 'ASC'), new Spec\AndX(array()));
$groups = $this->registry->getRepository('Entity\\Group')->match($spec);
$builder->add('groups', 'entity', array(
'choices' => $groups,
'class' => 'Entity\\Group',
'expanded' => true,
'multiple' => true,
'property' => 'name'
));
}
public function getParent()
{
return 'management_user';
}
/**
* Returns the name of this type.
*
* @return string The name of this type
*/
public function getName()
{
return 'admin_user';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment