12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- namespace Base\OAuthServerBundle\Admin;
- use Base\AdminBundle\Admin\BaseAdmin;
- use \Base\OAuthServerBundle\Entity\OAuthClient;
- use Sonata\AdminBundle\Datagrid\ListMapper;
- use Sonata\AdminBundle\Datagrid\DatagridMapper;
- use Sonata\AdminBundle\Form\FormMapper;
- use Symfony\Component\Form\Extension\Core\Type\CollectionType;
- use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
- class OAuthClientAdmin extends BaseAdmin
- {
- /**
- * @param FormMapper $formMapper
- */
- protected function configureFormFields(FormMapper $formMapper)
- {
- $formMapper
- ->add('randomId')
- ->add('redirectUris', CollectionType::class, array(
- 'entry_type' => null,
- 'allow_add' => true,
- 'allow_delete' => true,
- 'required' => true,
- ))
- ->add('secret')
- ->add('allowedGrantTypes', ChoiceType::class, array(
- 'choices' => OAuthClient::getGrantTypesChoices(),
- 'multiple' => true,
- 'expanded' => true,
- 'required' => true,
- ))
- ;
- }
- /**
- * @param DatagridMapper $datagridMapper
- */
- protected function configureDatagridFilters(DatagridMapper $datagridMapper)
- {
- $datagridMapper
- ->add('id')
- ->add('randomId')
- ->add('redirectUris')
- ->add('secret')
- ->add('allowedGrantTypes')
- ;
- }
- /**
- * @param ListMapper $listMapper
- */
- protected function configureListFields(ListMapper $listMapper)
- {
- unset($this->listModes['mosaic']);
- $listMapper
- ->add('id')
- ->addIdentifier('randomId')
- ->add('redirectUris', 'array', array(
- 'template' => 'BaseOAuthServerBundle:OAuthClient:list_field_redirect_uris.html.twig',
- ))
- ->add('secret')
- ->add('allowedGrantTypes', 'array', array(
- 'template' => 'BaseOAuthServerBundle:OAuthClient:list_field_allowed_grant_types.html.twig',
- ))
- ;
- }
- /**
- * @param OauthClient $oauthclient
- */
- public function preUpdate($oauthclient)
- {
- // Reindexar array de URIs
- $uris = $oauthclient->getRedirectUris();
- $uris = array_values($uris);
- $oauthclient->setRedirectUris($uris);
- // Reindexar array de allowedGrantTypes
- $algt = $oauthclient->getAllowedGrantTypes();
- $algt = array_values($algt);
- $oauthclient->setAllowedGrantTypes($algt);
- }
- }
|