Add form validation when previewing acces changes
2 unresolved threads
2 unresolved threads
This PR fixes:
taking into consideration form validation
(bonus) Switching to using the StringTranslation trait instead of the translate method of the translation manager, since that should not be used directly, check https://github.com/drupal/drupal/blob/4b25dc769526998569fdced5ffbdf0100584c5c2/core/lib/Drupal/Core/StringTranslation/TranslationInterface.php#L15
Edited by Mario Vercellotti
Merge request reports
Activity
585 $form_state->clearErrors(); 586 $response->addCommand( 587 new MessageCommand( 588 $access_by_taxonomy_service->translationManager->translate('To preview access changes, please fix these validation errors: <strong>:errors</strong>', [':errors' => implode(' ', $errors)]), 589 '#access_by_taxonomy_status_messages', 590 ['type' => 'warning'], 591 TRUE 592 ) 593 ); 594 595 // Since we validated the form, and there were errors, we need to delete 596 // error messages, because we don't want them to be displayed twice 597 // when the user reloads the page or navigates away from the page: 598 /** @var \Drupal\Core\Messenger\MessengerInterface $messenger */ 599 $messenger = \Drupal::service('messenger'); 600 $messenger->deleteByType('error'); This is slightly sketchy @joey-santiago but without it the error messages end up in messenger and are displayed in subsequent page loads...
added 1 commit
- 099da08b - Use string translation trait instead of translation manager
added 1 commit
- e393d469 - Use t instead of the translate method of translation manager
574 // form and test form state. 575 $test_form = $form; 576 $test_form_state = $form_state; 574 577 575 578 /** @var \Drupal\Core\Entity\ContentEntityFormInterface $form_object */ 576 $form_object = $form_state->getFormObject(); 579 $form_object = $test_form_state->getFormObject(); 580 581 try { 582 // Validate the form: 583 $form_object->validateForm($test_form, $test_form_state); 584 } 585 // Validation could trigger more errors depending on special validation 586 // needed for some of the fields in the form. We are not interested in those 587 // errors, so we catch them and ignore them. 588 catch (\Exception) {
Please register or sign in to reply