OAuthClientAdmin.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace Base\OAuthServerBundle\Admin;
  3. use Base\AdminBundle\Admin\BaseAdmin;
  4. use \Base\OAuthServerBundle\Entity\OAuthClient;
  5. use Sonata\AdminBundle\Datagrid\ListMapper;
  6. use Sonata\AdminBundle\Datagrid\DatagridMapper;
  7. use Sonata\AdminBundle\Form\FormMapper;
  8. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  9. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  10. class OAuthClientAdmin extends BaseAdmin
  11. {
  12. /**
  13. * @param FormMapper $formMapper
  14. */
  15. protected function configureFormFields(FormMapper $formMapper)
  16. {
  17. $formMapper
  18. ->add('randomId')
  19. ->add('redirectUris', CollectionType::class, array(
  20. 'entry_type' => null,
  21. 'allow_add' => true,
  22. 'allow_delete' => true,
  23. 'required' => true,
  24. ))
  25. ->add('secret')
  26. ->add('allowedGrantTypes', ChoiceType::class, array(
  27. 'choices' => OAuthClient::getGrantTypesChoices(),
  28. 'multiple' => true,
  29. 'expanded' => true,
  30. 'required' => true,
  31. ))
  32. ;
  33. }
  34. /**
  35. * @param DatagridMapper $datagridMapper
  36. */
  37. protected function configureDatagridFilters(DatagridMapper $datagridMapper)
  38. {
  39. $datagridMapper
  40. ->add('id')
  41. ->add('randomId')
  42. ->add('redirectUris')
  43. ->add('secret')
  44. ->add('allowedGrantTypes')
  45. ;
  46. }
  47. /**
  48. * @param ListMapper $listMapper
  49. */
  50. protected function configureListFields(ListMapper $listMapper)
  51. {
  52. unset($this->listModes['mosaic']);
  53. $listMapper
  54. ->add('id')
  55. ->addIdentifier('randomId')
  56. ->add('redirectUris', 'array', array(
  57. 'template' => 'BaseOAuthServerBundle:OAuthClient:list_field_redirect_uris.html.twig',
  58. ))
  59. ->add('secret')
  60. ->add('allowedGrantTypes', 'array', array(
  61. 'template' => 'BaseOAuthServerBundle:OAuthClient:list_field_allowed_grant_types.html.twig',
  62. ))
  63. ;
  64. }
  65. /**
  66. * @param OauthClient $oauthclient
  67. */
  68. public function preUpdate($oauthclient)
  69. {
  70. // Reindexar array de URIs
  71. $uris = $oauthclient->getRedirectUris();
  72. $uris = array_values($uris);
  73. $oauthclient->setRedirectUris($uris);
  74. // Reindexar array de allowedGrantTypes
  75. $algt = $oauthclient->getAllowedGrantTypes();
  76. $algt = array_values($algt);
  77. $oauthclient->setAllowedGrantTypes($algt);
  78. }
  79. }