您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

90 行
3.5KB

  1. <?php
  2. namespace Lc\PietroBundle\Definition\Field\IndividualData;
  3. use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
  4. use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField;
  5. use EasyCorp\Bundle\EasyAdminBundle\Field\HiddenField;
  6. use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
  7. use Lc\PietroBundle\Controller\IndividualData\IndividualDataAdminController;
  8. use Lc\PietroBundle\Form\Dream\DreamType;
  9. use Lc\PietroBundle\Form\ProjectBoost\ProjectBoostType;
  10. use Lc\PietroBundle\Form\ProjectInspiring\ProjectInspiringType;
  11. use Lc\PietroBundle\Form\Revolt\RevoltType;
  12. use Lc\SovBundle\Definition\Field\AbstractFieldDefinition;
  13. use Lc\SovBundle\Field\CollectionField;
  14. use Lc\SovBundle\Field\StatusField;
  15. use Lc\SovBundle\Translation\TranslatorAdmin;
  16. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  17. class IndividualDataFieldDefinition extends AbstractFieldDefinition
  18. {
  19. protected AuthorizationCheckerInterface $authorizationChecker;
  20. public function __construct(TranslatorAdmin $translatorAdmin, AuthorizationCheckerInterface $authorizationChecker)
  21. {
  22. $this->authorizationChecker = $authorizationChecker;
  23. parent::__construct($translatorAdmin);
  24. }
  25. public function configureFieldsIndex(): array
  26. {
  27. return [
  28. 'firstname',
  29. 'lastname',
  30. 'territory',
  31. 'nbDream',
  32. 'nbRevolt',
  33. 'nbProjectBoost',
  34. 'nbProjectInspiring',
  35. ];
  36. }
  37. public function configureFields(): array
  38. {
  39. $fields = array();
  40. $fields['firstname'] = TextField::new('firstname');
  41. $fields['lastname'] = TextField::new('lastname');
  42. $fields['email'] = EmailField::new('email');
  43. $fields['territory'] = AssociationField::new('territory')
  44. ->setTemplatePath('crud/field/association.html.twig');
  45. $fields['nbDream'] = TextField::new('nbDream');
  46. $fields['nbRevolt'] = TextField::new('nbRevolt');
  47. $fields['nbProjectBoost'] = TextField::new('nbProjectBoost');
  48. $fields['nbProjectInspiring'] = TextField::new('nbProjectInspiring');
  49. $fields['revolt'] = CollectionField::new('revolt')
  50. ->setFormTypeOption('entry_type', RevoltType::class)
  51. ->setFormTypeOption('by_reference', false)
  52. ->setRequired(false);
  53. $fields['dream'] = CollectionField::new('dream')
  54. ->setFormTypeOption('entry_type', DreamType::class)
  55. ->setFormTypeOption('by_reference', false)
  56. ->setRequired(false);
  57. $fields['projectBoost'] = CollectionField::new('projectBoost')
  58. ->setFormTypeOption('entry_type', ProjectBoostType::class)
  59. ->setFormTypeOption('by_reference', false)
  60. ->setRequired(false);
  61. $fields['projectInspiring'] = CollectionField::new('projectinspiring')
  62. ->setFormTypeOption('entry_type', ProjectInspiringType::class)
  63. ->setFormTypeOption('by_reference', false)
  64. ->setRequired(false);
  65. $hasAccess = $this->authorizationChecker->isGranted('ROLE_ADMIN');
  66. if ($hasAccess) {
  67. $fields['status'] = StatusField::new('status')
  68. ->setFormTypeOption('data', 0)
  69. ->setFormTypeOption('choices', ['Validé' => 1, 'En attente' => 0])
  70. ->setCustomOption('toggle_label', 'Valider');
  71. } else {
  72. $fields['status'] = HiddenField::new('status')
  73. ->setFormTypeOption('data', 0);
  74. }
  75. return $fields;
  76. }
  77. }