diff --git a/module/VuFind/src/VuFind/Form/Form.php b/module/VuFind/src/VuFind/Form/Form.php index 327726d5c9ae5dc81fb4c09bec4f8a2db30f515d..867b7d83fa4f6cbf47aecc2e6b63f952fd9e761e 100644 --- a/module/VuFind/src/VuFind/Form/Form.php +++ b/module/VuFind/src/VuFind/Form/Form.php @@ -54,11 +54,14 @@ class Form extends \Zend\Form\Form implements protected $inputFilter; /** - * Validation messages + * Default, untranslated validation messages * * @var array */ - protected $messages; + protected $messages = [ + 'empty' => 'This field is required', + 'invalid_email' => 'Email address is invalid', + ]; /** * Default form config (from config.ini > Feedback) @@ -118,13 +121,6 @@ class Form extends \Zend\Form\Form implements throw new \VuFind\Exception\RecordMissing("Form '$formId' not found"); } - $this->messages = []; - $this->messages['empty'] - = $this->translate('This field is required'); - - $this->messages['invalid_email'] - = $this->translate('Email address is invalid'); - $this->formElementConfig = $this->parseConfig($formId, $config); @@ -636,6 +632,20 @@ class Form extends \Zend\Form\Form implements return [$params, 'Email/form.phtml']; } + /** + * Get translated validation message. + * + * @param string $messageId Message identifier + * + * @return string + */ + protected function getValidationMessage($messageId) + { + return $this->translate( + $this->messages[$messageId] ?? $messageId + ); + } + /** * Retrieve input filter used by this form * @@ -653,14 +663,14 @@ class Form extends \Zend\Form\Form implements 'email' => [ 'name' => EmailAddress::class, 'options' => [ - 'message' => $this->messages['invalid_email'] + 'message' => $this->getValidationMessage('invalid_email'), ] ], 'notEmpty' => [ 'name' => NotEmpty::class, 'options' => [ 'message' => [ - NotEmpty::IS_EMPTY => $this->messages['empty'] + NotEmpty::IS_EMPTY => $this->getValidationMessage('empty'), ] ] ]