function UpdateSettingsForm::formatMultipleViolationsMessage

Same name and namespace in other branches
  1. 11.x core/modules/update/src/UpdateSettingsForm.php \Drupal\update\UpdateSettingsForm::formatMultipleViolationsMessage()

Formats multiple violation messages associated with a single form element.

Validation constraints only know the internal data structure (the configuration schema structure), but this need not be a disadvantage: rather than informing the user some values are wrong, it is possible guide them directly to the Nth entry in the sequence.

To further improve the user experience, it is possible to override method in subclasses to use specific knowledge about the structure of the form and the nature of the data being validated, to instead generate more precise and/or shortened violation messages.

Parameters

string $form_element_name: The form element for which to format multiple violation messages.

\Symfony\Component\Validator\ConstraintViolationListInterface $violations: The list of constraint violations that apply to this form element.

Return value

\Drupal\Core\StringTranslation\TranslatableMarkup

Overrides ConfigFormBase::formatMultipleViolationsMessage

File

core/modules/update/src/UpdateSettingsForm.php, line 93

Class

UpdateSettingsForm
Configure update settings for this site.

Namespace

Drupal\update

Code

protected function formatMultipleViolationsMessage(string $form_element_name, array $violations) : TranslatableMarkup {
  if ($form_element_name !== 'update_notify_emails') {
    return parent::formatMultipleViolationsMessage($form_element_name, $violations);
  }
  $invalid_email_addresses = [];
  foreach ($violations as $violation) {
    $invalid_email_addresses[] = $violation->getInvalidValue();
  }
  return $this->t('%emails are not valid email addresses.', [
    '%emails' => implode(', ', $invalid_email_addresses),
  ]);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.