Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
InputBag::get can return array, too#45650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Closed
Closed
Uh oh!
There was an error while loading.Please reload this page.
Conversation
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
Just a simple fix to help static code analysis. Simply using a form will trigger a returned array when calling `::get()` on the form name, for instance, containing all the keys.
Contributor
ro0NL commentedMar 6, 2022
it can not ;) |
ContributorAuthor
DocFX commentedMar 6, 2022
Then why do I have one? Am I a true magician? ;)
<?phpdeclare(strict_types =1);namespaceApp\Form\Admin;useApp\Entity\User;useSymfony\Component\Form\AbstractType;useSymfony\Component\Form\Extension\Core\Type\PasswordType;useSymfony\Component\Form\Extension\Core\Type\RepeatedType;useSymfony\Component\Form\FormBuilderInterface;useSymfony\Component\OptionsResolver\OptionsResolver;useSymfony\Component\Security\Core\Validator\Constraints\UserPassword;useSymfony\Component\Validator\Constraints\Length;useSymfony\Component\Validator\Mapping\ClassMetadata;class UserPasswordTypeextends AbstractType{publicfunctionbuildForm(FormBuilderInterface$builder,array$options):void {$builder ->add('oldpassword', PasswordType::class, ['label' =>'front.users.forms.password.oldpassword.label','mapped' =>false,'required' =>true,'empty_data' =>'','invalid_message' =>'front.users.forms.password.invalid_repeated','help' =>'front.users.forms.password.oldpassword.help', ] ) ->add('password', RepeatedType::class, ['type' => PasswordType::class,'required' =>true,'empty_data' =>'','options' => ['attr' => ['class' =>'password-field']],'first_options' => ['label' =>'front.users.forms.password.first','attr' => ['minlength' =>'6', ],'help' =>'front.users.forms.password.help', ],'second_options' => ['label' =>'front.users.forms.password.second','attr' => ['minlength' =>'6', ],'help' =>'front.users.forms.password.help', ],'invalid_message' =>'front.users.forms.password.invalid_repeated','help' =>'front.users.forms.password.help','constraints' => [newLength(['min' =>6, ]), ], ] ); }publicfunctionconfigureOptions(OptionsResolver$resolver):void {$resolver->setDefaults(['data_class' => User::class, ]); }publicstaticfunctionloadValidatorData(ClassMetadata$metadata):void {$metadata->addPropertyConstraint('oldpassword',newUserPassword(['message' =>'front.users.forms.password.oldpassword.error', ]) ); }}
<?phpdeclare(strict_types =1);namespaceApp\Controller\Front;useApp\Entity\User;useApp\Form\Admin\UserPasswordType;useApp\Form\Front\UserType;useDoctrine\ORM\EntityManagerInterface;useSensio\Bundle\FrameworkExtraBundle\Configuration\Security;useSymfony\Bundle\FrameworkBundle\Controller\AbstractController;useSymfony\Component\HttpFoundation\File\Exception\FileException;useSymfony\Component\HttpFoundation\Request;useSymfony\Component\HttpFoundation\Response;useSymfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;useSymfony\Component\Routing\Annotation\Route;useSymfony\Contracts\Translation\TranslatorInterface;#[Route('/my-account')]#[Security("is_granted('ROLE_PARTICIPANT')")]class AccountControllerextends AbstractController{ #[Route('/edit-my-password', name:'my_account_password', methods: ['GET','POST'])]publicfunctionpasswordEdit(Request$request,TranslatorInterface$translator,UserPasswordHasherInterface$userPasswordHasher,EntityManagerInterface$em):Response {/** @var User $user */$user =$this->getUser();$form =$this->createForm(UserPasswordType::class,$user);$form->handleRequest($request);if ($form->isSubmitted() &&$form->isValid() && !empty($request->request->get('user_password')['oldpassword']) && !empty($request->request->get('user_password')['password']['first']) ) {$user->setPassword($userPasswordHasher->hashPassword($user,$request->request->get('user_password')['password']['first']));$em->persist($user);$em->flush();$this->addFlash('success',$translator->trans('front.users.forms.password.success', ['{entity_name}' =>$user->getDisplayName()]));return$this->redirectToRoute('my_account', [], Response::HTTP_SEE_OTHER); }return$this->renderForm('front/account/my_account_password.html.twig', ['user' =>$user,'form' =>$form, ]); }... |
Contributor
ro0NL commentedMar 6, 2022
perhaps check your deprecations on 5.4
|
Member
nicolas-grekas commentedMar 6, 2022
Duplicate of#41766 |
ContributorAuthor
DocFX commentedMar 6, 2022
Thanks! Got it, now! Totally missed that part! :) |
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Just a simple fix to help static code analysis. Simply using a form will trigger a returned array when calling
::get()on the form name, for instance, containing all the keys.This doesn't break test, as it only changes PHPDoc.
6.1 only (not going back to 5.4 so as not to break static code analysis (I suppose this is better as it's also absolutely not critical).