public function AjaxCommentsForm::validateForm in AJAX Comments 8
Button-level validation handlers are highly discouraged for entity forms, as they will prevent entity validation from running. If the entity is going to be saved during the form submission, this method should be manually invoked from the button-level validation handler, otherwise an exception will be thrown.
Overrides ContentEntityForm::validateForm
File
- src/
Form/ AjaxCommentsForm.php, line 364
Class
- AjaxCommentsForm
- Provides ajax enhancements to core default Comment form.
Namespace
Drupal\ajax_comments\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
/** @var \Drupal\comment\CommentInterface $comment */
$comment = $form_state
->getFormObject()
->getEntity();
$comment_formatter = $this->fieldSettingsHelper
->getFieldFormatterFromComment($comment, 'full');
if ($comment_formatter && !$this->fieldSettingsHelper
->isEnabled($comment_formatter)) {
// If not using Ajax Comments, do not process further.
return;
}
$request = $this->requestStack
->getCurrentRequest();
$route_name = $this->currentRouteMatch
->getRouteName();
$this->tempStore
->processForm($request, $form, $form_state, $is_validating = TRUE);
if ($form_state
->hasAnyErrors() && in_array($route_name, [
'ajax_comments.save',
'ajax_comments.save_reply',
])) {
// If we are trying to save an edit to an existing comment, and there is
// a form error, set the wrapper element ID back to its original value,
// because we haven't executed a complete replacement of the wrapper
// element in this case.
$wrapper_html_id = $this->tempStore
->getSelectorValue($request, 'wrapper_html_id');
$this
->setWrapperId($form, $wrapper_html_id);
}
}