Created
June 17, 2014 01:27
-
-
Save merk/af75c64ebbcfa06f16fe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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