Skip to content

Commit

Permalink
First test if form is submitted
Browse files Browse the repository at this point in the history
Then verify validity. This to prevent the "User Deprecated: Call Form::isValid() with an unsubmitted form is deprecated since Symfony 3.2 and will throw an exception in 4.0. Use Form::isSubmitted() before Form::isValid() instead." deprecation warning.
  • Loading branch information
MKodde committed Aug 30, 2018
1 parent 43f5164 commit de11419
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function createAction(Request $request)

$form = $this->createForm(CreateRaLocationType::class, $command)->handleRequest($request);

if ($form->isValid()) {
if ($form->isSubmitted() && $form->isValid()) {
$logger->debug('RA Location form submitted, start processing command');

$success = $this->getRaLocationService()->create($command);
Expand Down Expand Up @@ -147,7 +147,7 @@ public function changeAction(Request $request)

$form = $this->createForm(ChangeRaLocationType::class, $command)->handleRequest($request);

if ($form->isValid()) {
if ($form->isSubmitted() && $form->isValid()) {
$logger->debug('RA Location form submitted, start processing command');

$success = $this->getRaLocationService()->change($command);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function createRaAction(Request $request)
$command->institution = $raCandidate->institution;

$form = $this->createForm(CreateRaType::class, $command)->handleRequest($request);
if ($form->isValid()) {
if ($form->isSubmitted() && $form->isValid()) {
$logger->debug('Accreditation form submitted, start processing command');

$success = $this->getRaCandidateService()->accreditCandidate($command);
Expand Down Expand Up @@ -214,7 +214,7 @@ public function amendRaInformationAction(Request $request, $identityId)
$command->contactInformation = $raListing->contactInformation;

$form = $this->createForm(AmendRegistrationAuthorityInformationType::class, $command)->handleRequest($request);
if ($form->isValid()) {
if ($form->isSubmitted() && $form->isValid()) {
$logger->notice(sprintf("RA(A) '%s' information amendment form submitted, processing", $identityId));

if ($this->get('ra.service.ra')->amendRegistrationAuthorityInformation($command)) {
Expand Down Expand Up @@ -258,7 +258,7 @@ public function changeRaRoleAction(Request $request, $identityId)
$command->role = $raListing->role;

$form = $this->createForm(ChangeRaRoleType::class, $command)->handleRequest($request);
if ($form->isValid()) {
if ($form->isSubmitted() && $form->isValid()) {
$logger->notice(sprintf('RA(A) "%s" Change Role form submitted, processing', $identityId));

if ($this->get('ra.service.ra')->changeRegistrationAuthorityRole($command)) {
Expand Down Expand Up @@ -300,7 +300,7 @@ public function retractRegistrationAuthorityAction(Request $request, $identityId
$command->identityId = $identityId;

$form = $this->createForm(RetractRegistrationAuthorityType::class, $command)->handleRequest($request);
if ($form->isValid()) {
if ($form->isSubmitted() && $form->isValid()) {
if ($form->get('cancel')->isClicked()) {
$logger->notice('Retraction of registration authority cancelled');
return $this->redirectToRoute('ra_management_manage');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function selectInstitutionAction(Request $request)
$form = $this->createForm(InstitutionSelectionType::class, $command);
$form->handleRequest($request);

if ($form->isValid()) {
if ($form->isSubmitted() && $form->isValid()) {
$institutionConfigurationOptions = $this->get('ra.service.institution_configuration_options')
->getInstitutionConfigurationOptionsFor($command->institution);
$token->changeInstitutionScope($command->institution, $institutionConfigurationOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function sendChallengeAction(Request $request, $procedureId)
$maximumOtpRequests = $vettingService->getSmsMaximumOtpRequestsCount();
$viewVariables = ['otpRequestsRemaining' => $otpRequestsRemaining, 'maximumOtpRequests' => $maximumOtpRequests];

if (!$form->isValid()) {
if (!$form->isSubmitted() || !$form->isValid()) {
$logger->notice('Form has not been submitted, not sending SMS, rendering Send SMS Challenge page');

return array_merge(
Expand Down Expand Up @@ -124,7 +124,7 @@ public function provePossessionAction(Request $request, $procedureId)
return $this->redirectToRoute('ra_vetting_search');
}

if (!$form->isValid()) {
if (!$form->isSubmitted() || !$form->isValid()) {
$logger->notice(
'SMS OTP was not submitted through form, rendering Proof of Possession of SMS Second Factor page'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function provePossessionAction(Request $request, $procedureId)
)
->handleRequest($request);

if (!$form->isValid()) {
if (!$form->isSubmitted() || !$form->isValid()) {
return $this->render('SurfnetStepupRaRaBundle:Vetting/U2f:authentication.html.twig', [
'authenticationFailed' => true,
'procedureId' => $procedureId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function verifyAction(Request $request, $procedureId)
$command = new VerifyYubikeyPublicIdCommand();
$form = $this->createForm(VerifyYubikeyPublicIdType::class, $command)->handleRequest($request);

if ($form->isValid()) {
if ($form->isSubmitted() && $form->isValid()) {
$result = $this->getVettingService()->verifyYubikeyPublicId($procedureId, $command);

if ($result->didPublicIdMatch()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function startProcedureAction(Request $request)

$form = $this->createForm(StartVettingProcedureType::class, $command)->handleRequest($request);

if (!$form->isValid()) {
if (!$form->isSubmitted() || !$form->isValid()) {
$logger->notice('No search submitted, displaying search by registration code form');

return ['form' => $form->createView()];
Expand Down Expand Up @@ -189,6 +189,9 @@ public function cancelProcedureAction($procedureId)
* @param Request $request
* @param string $procedureId
* @return array|Response
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function verifyIdentityAction(Request $request, $procedureId)
{
Expand Down Expand Up @@ -225,7 +228,7 @@ public function verifyIdentityAction(Request $request, $procedureId)
return ['commonName' => $commonName, 'form' => $form->createView()];
};

if (!$form->isValid()) {
if (!$form->isSubmitted() || !$form->isValid()) {
$logger->notice('Verify Identity Form not submitted, displaying form');

return $showForm();
Expand Down

0 comments on commit de11419

Please sign in to comment.