src/FMT/Application/FormType/Admin/ExternalUserCrudType.php line 346

Open in your IDE?
  1. <?php
  2. namespace FMT\Application\FormType\Admin;
  3. use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField;
  4. use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
  5. use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
  6. use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField;
  7. use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
  8. use EasyCorp\Bundle\EasyAdminBundle\Field\ImageField;
  9. use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField;
  10. use EasyCorp\Bundle\EasyAdminBundle\Field\TelephoneField;
  11. use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
  12. use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
  13. use FMT\Application\Controller\Admin\Crud\ExternalUserController;
  14. use FMT\Application\FormType\Admin\Fields\MajorFiled;
  15. use FMT\Application\FormType\RoleType;
  16. use FMT\Application\Validator\Constraints\FmtEmail;
  17. use FMT\Data\Entity\User;
  18. use FMT\Data\Entity\UserProfile;
  19. use FMT\Data\Entity\UserSchool;
  20. use FMT\Data\Repository\UserSchoolRepository;
  21. use FMT\Domain\Repository\UserRepositoryInterface;
  22. use FMT\Domain\Service\Manager\FileManager;
  23. use FMT\Domain\Service\Synchronizer\MajorSynchronizer;
  24. use FMT\Infrastructure\Service\AmazonS3\StorageInterface;
  25. use Generator;
  26. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  27. use Symfony\Component\HttpFoundation\File\File;
  28. use Symfony\Component\HttpFoundation\File\UploadedFile;
  29. use Symfony\Component\Validator\Constraints\Length;
  30. use Symfony\Component\Validator\Constraints\NotBlank;
  31. use Symfony\Component\Validator\Constraints\Range;
  32. use Symfony\Component\Validator\Constraints\Regex;
  33. use FMT\Infrastructure\Helper\CurrencyHelper;
  34. use Symfony\Component\Security\Core\Security;
  35. class ExternalUserCrudType
  36. {
  37.     private UserSchoolRepository $userSchoolRepository;
  38.     private MajorSynchronizer $majorSynchronizer;
  39.     private UserRepositoryInterface $userRepository;
  40.     private FileManager $fileManager;
  41.     private StorageInterface $avatarStorage;
  42.     private array $usStates;
  43.     private Security $security;
  44.     public function __construct(
  45.         UserSchoolRepository $userSchoolRepository,
  46.         MajorSynchronizer $majorSynchronizer,
  47.         UserRepositoryInterface $userRepository,
  48.         FileManager $fileManager,
  49.         StorageInterface $avatarStorage,
  50.         array $usStates,
  51.         Security $security,
  52.     ) {
  53.         $this->userSchoolRepository $userSchoolRepository;
  54.         $this->majorSynchronizer $majorSynchronizer;
  55.         $this->userRepository $userRepository;
  56.         $this->fileManager $fileManager;
  57.         $this->avatarStorage $avatarStorage;
  58.         $this->usStates $usStates;
  59.         $this->security $security;
  60.     }
  61.     public function getUserCrudFields(
  62.         string $pageName,
  63.         StorageInterface $avatarStorage,
  64.         ?User $user,
  65.         string $url
  66.     ): Generator {
  67.         if ($pageName === 'edit') {
  68.             return $this->getEditDetailFields($user$avatarStorage$url);
  69.         }
  70.         return $this->getViewFields($avatarStorage$user$pageName);
  71.     }
  72.     /**
  73.      * @param StorageInterface $avatarStorage
  74.      * @param User|null $user
  75.      * @return mixed
  76.      */
  77.     private function getViewFields(StorageInterface $avatarStorage, ?User $userstring $pageName)
  78.     {
  79.         $isStudent $user instanceof User && $user->isStudent();
  80.         $loggedInUser $this->security->getUser();
  81.         $isSchoolAdmin $loggedInUser->hasRole(User::ROLE_SCHOOL_ADMIN);
  82.         
  83.         yield FormField::addPanel('Personal Info')->onlyOnDetail()->collapsible();
  84.         /**
  85.          * hide avatar
  86.          *  */    
  87.         if(true && ! $isSchoolAdmin){
  88.             if ($pageName === 'index' || $isStudent) {
  89.                 yield ImageField::new('profile.avatar.filename')
  90.                     ->setLabel('fmt.admin_page.user.avatar.name')
  91.                     ->setUploadDir('var')
  92.                     ->setBasePath("/avatar/");
  93.                     // /->setBasePath($avatarStorage->getBucketUrl())
  94.                     
  95.             }
  96.         }
  97.         yield TextField::new('profile.firstName')
  98.             ->setLabel('fmt.admin_page.user.form.first_name')
  99.             ->setSortable(false)
  100.             ->hideOnForm();
  101.         yield TextField::new('profile.lastName')
  102.             ->setLabel('fmt.admin_page.user.form.last_name')
  103.             ->setSortable(false)
  104.             ->hideOnForm();
  105.         yield TextField::new('profile.email')
  106.             ->setLabel('fmt.admin_page.user.form.email')
  107.             ->setSortable(false)
  108.             ->hideOnForm();
  109.         if(!$isSchoolAdmin){
  110.             if ($pageName === 'index' || $isStudent) {
  111.                 yield TextField::new('profile.school')
  112.                     ->setLabel('fmt.admin_page.user.profile.school.name')
  113.                     ->setSortable(true)
  114.                     ->hideOnForm();
  115.             }
  116.             
  117.             if ($pageName === 'index' || $isStudent) {
  118.                 yield TextField::new('profile.major.name')
  119.                     ->setLabel('fmt.form.major');
  120.                     //->onlyOnDetail();
  121.             }   
  122.         }
  123.        
  124.         if($pageName === 'index' ){
  125.             yield TextField::new('profile.fundedTotal')
  126.             ->setLabel("Funded")
  127.             ->formatValue(function ($value$entity) {
  128.                 if($entity){
  129.                     $campaign $entity->getActiveOrUnstartedCampaign();
  130.                     if($campaign){
  131.                         $funded CurrencyHelper::priceFilter($campaign->getFundedTotal());
  132.                         return $funded;
  133.                     }
  134.                 }
  135.             
  136.                 // Fetch data or process logic here
  137.                 return '-' ;
  138.             });
  139.             yield TextField::new('profile.transferTotal')
  140.             ->setLabel("Purchased")
  141.             ->formatValue(function ($value$entity) {
  142.                 if($entity){
  143.                     $campaign $entity->getActiveOrUnstartedCampaign();
  144.                     if($campaign){
  145.                         $transferred CurrencyHelper::priceFilter($campaign->getTransferTotal());
  146.                         return $transferred;
  147.                     }
  148.                 }
  149.             
  150.                 // Fetch data or process logic here
  151.                 return '-' ;
  152.             });
  153.             yield TextField::new('profile.remainingTotal')
  154.             ->setLabel("Remaining")
  155.             ->formatValue(function ($value$entity) {
  156.                 if($entity){
  157.                     $campaign $entity->getActiveOrUnstartedCampaign();
  158.                     if($campaign){
  159.                         $remaining CurrencyHelper::priceFilter($campaign->getRemainingFunds());
  160.                         return $remaining;
  161.                     }
  162.                 }
  163.             
  164.                 // Fetch data or process logic here
  165.                 return '-' ;
  166.             });
  167.             yield TextField::new('profile.purchaseUrl')
  168.             ->setLabel("Campaign")
  169.             ->formatValue(function ($value$entity) {
  170.                 if($entity){
  171.                     $campaign $entity->getActiveOrUnstartedCampaign();
  172.                     if($campaign){
  173.                         $funded CurrencyHelper::priceFilter($campaign->getFundedTotal());
  174.                         $transferred CurrencyHelper::priceFilter($campaign->getTransferTotal());
  175.                         $remaining CurrencyHelper::priceFilter($campaign->getRemainingFunds());
  176.                         return '<a href="/admin?crudAction=edit&crudControllerFqcn=FMT%5CApplication%5CController%5CAdmin%5CCrud%5CCampaignCrudController&entityId=' $campaign->getId() . '&menuIndex=1&submenuIndex=1&referrer=?crudAction%3Dindex%26crudControllerFqcn%3DFMT%255CApplication%255CController%255CAdmin%255CCrud%255CCampaignCrudController%26entityFqcn%3DFMT%255CApplication%255CController%255CAdmin%255CCampaign%26menuIndex%3D3%26submenuIndex%3D-1&submenuIndex=-1">Purchases/Refunds</a>';
  177.                     }
  178.                 }
  179.             
  180.                 // Fetch data or process logic here
  181.                 return '-' ;
  182.             });
  183.             
  184.             
  185.            
  186.         }
  187.        
  188.         if ($pageName === 'index' && !$isSchoolAdmin){
  189.             
  190.             
  191.           
  192.                 yield TextField::new('profile.fundedPercent')
  193.                 ->setLabel("% Funded")
  194.                 ->formatValue(function ($value$entity) {
  195.                     if($entity){
  196.                         $campaign $entity->getActiveOrUnstartedCampaign();
  197.                         if($campaign){
  198.                             //return $campaign->estimatedCost();
  199.                             $total CurrencyHelper::priceFilter($campaign->getEstimatedCost());
  200.                             $total = (double)str_replace('$','',$total);
  201.                             $funded CurrencyHelper::priceFilter($campaign->getFundedTotal());
  202.                             $percent number_format(((double)str_replace('$','',$funded)/$total) * 100,1);
  203.                             return $percent."%";
  204.                         
  205.                         }
  206.                     }
  207.                 
  208.                     // Fetch data or process logic here
  209.                     return '-' ;
  210.                 });
  211.             
  212.             
  213.             
  214.         }
  215.        
  216.        
  217.         
  218.         
  219.         
  220.         if ($isStudent) {
  221.             yield BooleanField::new('profile.avatar.status')
  222.                 ->hideWhenCreating()
  223.                 ->setLabel('fmt.admin_page.user.avatar.status')
  224.                 ->onlyOnDetail();
  225.         }
  226.         if(!$isSchoolAdmin){
  227.             yield ChoiceField::new('roles')
  228.                 ->setLabel('fmt.form.roles')
  229.                 ->setChoices(ExternalUserController::EXTERNAL_USER_ROLES)
  230.                 ->setFormType(RoleType::class)
  231.                 ->hideOnForm();
  232.             /*
  233.             yield DateTimeField::new('lastLogin')
  234.             ->renderAsText()
  235.             ->setLabel('fmt.admin_page.user.index.last_login')
  236.             ->onlyOnIndex();
  237.             */
  238.             yield BooleanField::new('enabled')
  239.                 ->setLabel('fmt.form.enabled')
  240.                 ->setTemplatePath('admin/field/boolean.html.twig')
  241.                 ->renderAsSwitch(false)
  242.                 ->hideOnForm();
  243.             yield EmailField::new('login')
  244.                 ->setLabel('fmt.user.profile.label.email')
  245.                 ->onlyOnDetail();
  246.             if ($isStudent) {
  247.                 yield TelephoneField::new('profile.phone')
  248.                     ->setLabel('fmt.admin_page.user.form.phone')
  249.                     ->onlyOnDetail();
  250.             }
  251.             yield TextField::new('profile.snapchatId')
  252.                 ->setLabel('fmt.admin_page.user.form.snapchat')
  253.                 ->onlyOnDetail();
  254.             yield TextField::new('profile.facebookMessengerId')
  255.                 ->setLabel('fmt.admin_page.user.form.facebook')
  256.                 ->onlyOnDetail();
  257.             yield EmailField::new('profile.otherEmail')
  258.                 ->setLabel('fmt.admin_page.user.form.other')
  259.                 ->onlyOnDetail();
  260.             if ($isStudent) {
  261.                 yield FormField::addPanel('Shipping')
  262.                     ->onlyOnDetail()
  263.                     ->renderCollapsed();
  264.                 yield TextField::new('profile.address.address1')
  265.                     ->setLabel('fmt.admin_page.user.form.address.line_1')
  266.                     ->onlyOnDetail();
  267.                 yield TextField::new('profile.address.address2')
  268.                     ->setLabel('fmt.admin_page.user.form.address.line_2')
  269.                     ->onlyOnDetail();
  270.                 yield TextField::new('profile.address.city')
  271.                     ->setLabel('fmt.admin_page.user.form.address.city')
  272.                     ->onlyOnDetail();
  273.                 yield TextField::new('profile.address.region')
  274.                     ->setLabel('fmt.admin_page.user.form.address.state')
  275.                     ->onlyOnDetail();
  276.                 yield TextField::new('profile.address.code')
  277.                     ->setLabel('fmt.admin_page.user.form.address.postal_code')
  278.                     ->onlyOnDetail();
  279.             }
  280.             yield FormField::addPanel('Visibility')->onlyOnDetail()->renderCollapsed($isStudent);
  281.             yield ChoiceField::new('profile.visible')
  282.                 ->setChoices($this->getVisibilityChoices($isStudent))
  283.                 ->setLabel(sprintf('fmt.admin_page.user.form.%s.visible'$isStudent 'student' 'donor'))
  284.                 ->onlyOnDetail();
  285.             yield BooleanField::new('profile.facebook')
  286.                 ->setLabel(
  287.                     sprintf(
  288.                         'fmt.admin_page.user.form.%s.facebook_enabled',
  289.                         $isStudent 'student' 'donor'
  290.                     )
  291.                 )
  292.                 ->onlyOnDetail();
  293.             yield BooleanField::new('profile.twitter')
  294.                 ->setLabel(sprintf('fmt.admin_page.user.form.%s.twitter_enabled'$isStudent 'student' 'donor'))
  295.                 ->onlyOnDetail();
  296.             if ($isStudent) {
  297.                 yield FormField::addPanel('About Me')->renderCollapsed();
  298.                 yield TextareaField::new('profile.aboutText')->setLabel(false);
  299.             }
  300.         }
  301.         
  302.     }
  303.     /**
  304.      * @param User|null $user
  305.      * @param StorageInterface $avatarStorage
  306.      * @param $url
  307.      * @return mixed
  308.      */
  309.     public function getEditDetailFields(User $userStorageInterface $avatarStorage$url)
  310.     {
  311.         yield FormField::addPanel('User Settings');
  312.         if ($user->isStudent()) {
  313.             $originalAvatar $user->getProfile()->getAvatar();
  314.             $previousFile = clone $originalAvatar;
  315.             $usrSchoolId $user->getProfile()->getSchool()->getId();
  316.             $majors $this->majorSynchronizer->synchronizeBySchool($usrSchoolId)->getValues();
  317.             
  318.             
  319.             yield ImageField::new('profile.avatar.filename')
  320.                 ->setFormTypeOption('upload_new', function (UploadedFile $file) use ($user$previousFile) {
  321.                     if ($file) {
  322.                         $avatarFileName $this->fileManager->uploadAvatar($user$file$previousFile->getFilename());
  323.                         $user->getProfile()->getAvatar()->setFilename($avatarFileName);
  324.                     }
  325.                 })
  326.                 ->setFormTypeOption('upload_delete', function (?File $file) {
  327.                     if ($file) {
  328.                         $this->avatarStorage->delete($file->getFilename());
  329.                     }
  330.                 })
  331.                 ->setLabel('fmt.admin_page.user.avatar.name')
  332.                 ->setUploadDir('var')
  333.                 ->setBasePath("/avatar")
  334.                 ->setColumns('col-md-5 col-xxl-4');
  335.                 // /->setBasePath($avatarStorage->getBucketUrl())
  336.             
  337.                 
  338.            
  339.             yield FormField::addRow();
  340.             
  341.           
  342.             yield BooleanField::new('profile.avatar.status')
  343.                 ->setTemplatePath('admin/field/boolean.html.twig')
  344.                 ->hideWhenCreating()
  345.                 ->setLabel('fmt.admin_page.user.avatar.status')
  346.                 ->setColumns('col-md-3 col-xxl-2');
  347.         }
  348.         yield BooleanField::new('enabled')
  349.             ->setTemplatePath('admin/field/boolean.html.twig')
  350.             ->hideWhenCreating()
  351.             ->onlyWhenUpdating()
  352.             ->setLabel('fmt.form.active')
  353.             ->addWebpackEncoreEntries('admin_block_user_confirmation')
  354.             ->setColumns('col-md-3 col-xxl-2');
  355.         yield FormField::addRow();
  356.         yield FormField::addPanel('Personal Info');
  357.         yield TextField::new('profile.firstName')
  358.             ->setLabel('fmt.admin_page.user.form.first_name')
  359.             ->setFormTypeOptions([
  360.                 'required' => true,
  361.                 'attr' => [
  362.                     'placeholder' => 'fmt.form.first_name',
  363.                 ],
  364.                 'constraints' => [
  365.                     new NotBlank(),
  366.                     new Length([
  367.                         'min' => 2,
  368.                         'max' => 255,
  369.                     ]),
  370.                 ],
  371.             ])
  372.             ->setColumns('col-md-3 col-xxl-2')
  373.             ->setSortable(true);
  374.         yield TextField::new('profile.lastName')
  375.             ->setLabel('fmt.admin_page.user.form.last_name')
  376.             ->setFormTypeOptions([
  377.                 'required' => true,
  378.                 'attr' => [
  379.                     'placeholder' => 'fmt.form.last_name',
  380.                 ],
  381.                 'constraints' => [
  382.                     new NotBlank(),
  383.                     new Length([
  384.                         'min' => 2,
  385.                         'max' => 255,
  386.                     ]),
  387.                 ],
  388.             ])
  389.             ->setColumns('col-md-3 col-xxl-2')
  390.             ->setSortable(true);
  391.         yield EmailField::new('login')
  392.             ->setLabel('fmt.user.profile.label.email')
  393.             ->setFormTypeOptions([
  394.                 'required' => true,
  395.                 'label' => 'fmt.user.profile.label.email',
  396.                 'attr' => [
  397.                     'placeholder' => 'fmt.user.profile.email_placeholder',
  398.                 ],
  399.                 'constraints' => [
  400.                     new NotBlank(),
  401.                     new FmtEmail(),
  402.                     new Length([
  403.                         'max' => 255,
  404.                     ]),
  405.                 ],
  406.             ])
  407.             ->setColumns('col-md-3 col-xxl-2');
  408.         if ($user->isStudent()) {
  409.             yield TelephoneField::new('profile.phone')
  410.                 ->setLabel('fmt.admin_page.user.form.phone')
  411.                 ->hideOnIndex()
  412.                 ->setFormTypeOptions([
  413.                     'label' => 'fmt.admin_page.user.form.phone',
  414.                     'required' => true,
  415.                     'attr' => [
  416.                         'placeholder' => 'fmt.admin_page.user.form.phone',
  417.                     ],
  418.                     'constraints' => [
  419.                         new NotBlank(),
  420.                         new Regex([
  421.                             'pattern' => '/[0-9]{3}-[0-9]{3}-[0-9]{4}/',
  422.                             'message' => 'fmt.sign_up.phone',
  423.                         ])
  424.                     ],
  425.                 ])
  426.                 ->setColumns('col-md-3 col-xxl-2');
  427.         }
  428.         yield FormField::addRow();
  429.         yield TextField::new('profile.snapchatId')
  430.             ->setLabel('fmt.admin_page.user.form.snapchat')
  431.             ->setFormTypeOptions([
  432.                 'attr' => [
  433.                     'placeholder' => 'fmt.admin_page.user.form.snapchat',
  434.                 ]
  435.             ])
  436.             ->setColumns('col-md-3 col-xxl-2');
  437.         yield TextField::new('profile.facebookMessengerId')
  438.             ->setLabel('fmt.admin_page.user.form.facebook')
  439.             ->setFormTypeOptions([
  440.                 'attr' => [
  441.                     'placeholder' => 'fmt.admin_page.user.form.facebook',
  442.                 ]
  443.             ])
  444.             ->setColumns('col-md-3 col-xxl-2');
  445.         yield EmailField::new('profile.otherEmail')
  446.             ->setLabel('fmt.admin_page.user.form.other')
  447.             ->setFormTypeOptions([
  448.                 'attr' => [
  449.                     'placeholder' => 'fmt.user.profile.email_placeholder',
  450.                 ]
  451.             ])
  452.             ->setColumns('col-md-3 col-xxl-2');
  453.         if ($user->isStudent()) {
  454.             yield FormField::addPanel('Shipping');
  455.             yield TextField::new('profile.address.address1')
  456.                 ->setRequired(true)
  457.                 ->setLabel('fmt.admin_page.user.form.address.line_1')
  458.                 ->setColumns('col-md-4 col-xxl-3');
  459.             yield TextField::new('profile.address.address2')
  460.                 ->setLabel('fmt.admin_page.user.form.address.line_2')
  461.                 ->setColumns('col-md-4 col-xxl-3');
  462.             yield FormField::addRow();
  463.             yield TextField::new('profile.address.city')
  464.                 ->setRequired(true)
  465.                 ->setLabel('fmt.admin_page.user.form.address.city')
  466.                 ->setColumns('col-md-3 col-xxl-2');
  467.             yield ChoiceField::new('profile.address.region')
  468.                 ->setRequired(true)
  469.                 ->setChoices(array_flip($this->usStates))
  470.                 ->setLabel('fmt.admin_page.user.form.address.state')
  471.                 ->setColumns('col-md-3 col-xxl-2');
  472.             yield TextField::new('profile.address.code')
  473.                 ->setRequired(true)
  474.                 ->setLabel('fmt.admin_page.user.form.address.postal_code')
  475.                 ->setColumns('col-md-3 col-xxl-2');
  476.             
  477.             
  478.             yield FormField::addPanel('School');
  479.             yield BooleanField::new('profile.firstGen')
  480.                 ->setLabel('fmt.form.first_gen')
  481.                 ->setTemplatePath('admin/field/boolean.html.twig')
  482.                 ->setColumns('col-md-12 col-xxl-12');
  483.             
  484.             yield ChoiceField::new('profile.studentType')
  485.                 ->setLabel('fmt.user.profile.student_type_text')   // Field label
  486.                 ->setChoices([
  487.                     UserProfile::UNDERGRADUATE => UserProfile::UNDERGRADUATE,
  488.                     UserProfile::GRADUATE => UserProfile::GRADUATE,
  489.                 ])
  490.                 ->setRequired(true)              // Make selection mandatory
  491.                 ->renderExpanded(true)           // Render as radio buttons
  492.                 ->allowMultipleChoices(false)    // Single selection only
  493.                 ->setFormTypeOption('placeholder''Select Type');  // Optional placeholder
  494.             yield IntegerField::new('profile.gradYear')
  495.                 ->setFormTypeOptions([
  496.                     'constraints' => [
  497.                         new NotBlank(),
  498.                         new Range([
  499.                             'min' => 1900,
  500.                             'max' => 3000,
  501.                             'invalidMessage' => 'fmt.grad_year.error',
  502.                             'maxMessage' => 'fmt.grad_year.error',
  503.                             'minMessage' => 'fmt.grad_year.error',
  504.                         ]),
  505.                     ],
  506.                 ])
  507.                 ->setLabel('fmt.form.grad_year')
  508.                 ->setColumns('col-md-2 col-xxl-1');
  509.            
  510.             yield ChoiceField::new('profile.school')
  511.                 ->setChoices($this->userSchoolRepository->getSchoolsCollection($usertrue)->toArray())
  512.                 ->setValue($user->getProfile()->getSchool())
  513.                 ->setFormType(EntityType::class)
  514.                 ->setFormTypeOptions(
  515.                     [
  516.                         'choice_label' => 'name',
  517.                         'class' => UserSchool::class,
  518.                         'attr' => ['data-change' => $url]
  519.                     ]
  520.                 )
  521.                 ->setFormTypeOption('disabled', !is_null($user->getActiveOrUnstartedCampaign()))
  522.                 ->setLabel('fmt.admin_page.user.profile.school.name')
  523.                 ->setColumns('col-md-3 col-xxl-3')
  524.                 ->setSortable(true);
  525.             yield MajorFiled::new('profile.major')
  526.                 ->setDefaultOptions($user)
  527.                 ->setFormTypeOptions(['choices' => $majors])
  528.                 ->setFormTypeOption('disabled', !is_null($user->getActiveOrUnstartedCampaign()))
  529.                 ->setColumns('col-md-3 col-xxl-4');
  530.         }
  531.         yield FormField::addPanel('Visibility');
  532.         yield ChoiceField::new('profile.visible')
  533.             ->setChoices($this->getVisibilityChoices($user->isStudent()))
  534.             ->setFormTypeOption('choice_attr', function ($val) {
  535.                 $visible = ($val == UserProfile::VISIBILITY_NON || $val == UserProfile::VISIBILITY_REGISTRED) ? 'no'
  536.                     'yes';
  537.                 return ['data-visible' => $visible];
  538.             })
  539.             ->setLabel(sprintf('fmt.admin_page.user.form.%s.visible'$user->isStudent() ? 'student' 'donor'))
  540.             ->setColumns('col-md-4 col-xxl-3');
  541.         yield FormField::addRow();
  542.         yield BooleanField::new('profile.facebook')
  543.             ->setLabel(
  544.                 sprintf(
  545.                     'fmt.admin_page.user.form.%s.facebook_enabled',
  546.                     $user->isStudent() ? 'student' 'donor'
  547.                 )
  548.             )
  549.             ->setTemplatePath('admin/field/boolean.html.twig')
  550.             ->renderAsSwitch(true)
  551.             ->hideWhenCreating()
  552.             ->setColumns('col-md-5 col-xxl-4');
  553.         yield BooleanField::new('profile.twitter')
  554.             ->setLabel(sprintf('fmt.admin_page.user.form.%s.twitter_enabled'$user->isStudent() ? 'student' 'donor'))
  555.             ->setTemplatePath('admin/field/boolean.html.twig')
  556.             ->renderAsSwitch(true)
  557.             ->hideWhenCreating()
  558.             ->setColumns('col-md-5 col-xxl-4');
  559.         if ($user->isStudent()) {
  560.             yield FormField::addPanel('About Me');
  561.             yield TextareaField::new('profile.aboutText')
  562.                 ->setFormTypeOptions([
  563.                     'attr' => [
  564.                         'rows' => 10,
  565.                         'maxlength' => 5000,
  566.                     ],
  567.                     'constraints' => [
  568.                         new Length([
  569.                             'max' => 5000,
  570.                         ]),
  571.                     ],
  572.                 ])
  573.                 ->setLabel(false);
  574.         }
  575.     }
  576.     private function getVisibilityChoices(bool $isStudent): array
  577.     {
  578.         if ($isStudent) {
  579.             return array_flip([
  580.                 UserProfile::VISIBILITY_ALL => 'fmt.user.profile.label.visibility_all',
  581.                 UserProfile::VISIBILITY_REGISTRED => 'fmt.user.profile.label.visibility_register',
  582.                 UserProfile::VISIBILITY_NON => 'fmt.user.profile.label.visibility_no',
  583.             ]);
  584.         }
  585.         return [
  586.             'fmt.user.profile.label.donot_visibility_yes' => UserProfile::VISIBILITY_ALL,
  587.             'fmt.user.profile.label.donot_visibility_no' => UserProfile::VISIBILITY_NON
  588.         ];
  589.     }
  590. }