Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
feat: Use custom messages for messaging when defined (#99)
Browse files Browse the repository at this point in the history
* feat: Use custom messages for messaging when defined

* chore: Use annotations to configure validation messages

* Add messages with priority

---------

Co-authored-by: Saul Wilcox <[email protected]>
  • Loading branch information
hobbyhacker0 and hobbyhacker0 authored Mar 20, 2024
1 parent 899237e commit acfbaa8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
36 changes: 33 additions & 3 deletions module/Olcs/src/Form/Model/Fieldset/Message/CreateInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Laminas\Form\Annotation as Form;
use Laminas\Form\Element\Textarea;
use Laminas\Validator\StringLength;
use Laminas\Validator\NotEmpty;
use Olcs\Service\Data\MessagingAppOrLicNo;

class CreateInput
Expand All @@ -25,7 +26,13 @@ class CreateInput
* "class": "govuk-select"
* })
* @Form\Type(DynamicSelect::class)
* @Form\Required(true)
* @Form\Validator(NotEmpty::class,
* options={
* "messages":{NotEmpty::IS_EMPTY:"messaging.form.message.subject.empty.error_message"},
* },
* breakChainOnFailure=true,
* priority=100,
* )
*/
public ?DynamicSelect $messageSubject = null;

Expand All @@ -41,7 +48,13 @@ class CreateInput
* "class": "govuk-select"
* })
* @Form\Type(DynamicSelect::class)
* @Form\Required(true)
* * @Form\Validator(NotEmpty::class,
* options={
* "messages":{NotEmpty::IS_EMPTY:"messaging.form.message.app_or_lic_no.empty.error_message"},
* },
* breakChainOnFailure=true,
* priority=100,
* )
*/
public ?DynamicSelect $appOrLicNo = null;

Expand All @@ -57,7 +70,24 @@ class CreateInput
* @Form\Required(true)
* @Form\Type(Textarea::class)
* @Form\Filter(StringTrim::class)
* @Form\Validator(StringLength::class, options={"min": 5, "max": 1000})
* @Form\Validator(NotEmpty::class,
* options={
* "messages": {
* NotEmpty::IS_EMPTY: "messaging.form.message.content.empty.error_message"
* },
* },
* breakChainOnFailure=true
* )
* @Form\Validator(StringLength::class,
* options={
* "min": 5,
* "max": 1000,
* "messages": {
* StringLength::TOO_SHORT:"messaging.form.message.content.too_short.error_message",
* StringLength::TOO_LONG:"messaging.form.message.content.too_long.error_message",
* }
* }
* )
*/
public ?Textarea $messageContent = null;
}
18 changes: 17 additions & 1 deletion module/Olcs/src/Form/Model/Fieldset/Message/ReplyInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Laminas\Form\Annotation as Form;
use Laminas\Form\Element\Textarea;
use Laminas\Validator\StringLength;
use Laminas\Validator\NotEmpty;

class ReplyInput
{
Expand All @@ -23,7 +24,22 @@ class ReplyInput
* @Form\Required(true)
* @Form\Type(Textarea::class)
* @Form\Filter(StringTrim::class)
* @Form\Validator(StringLength::class, options={"min": 5, "max": 1000})
* @Form\Validator(NotEmpty::class,
* options={
* "messages":{NotEmpty::IS_EMPTY: "messaging.form.message.content.empty.error_message"},
* },
* breakChainOnFailure=true
* )
* @Form\Validator(StringLength::class,
* options={
* "min": 5,
* "max": 1000,
* "messages": {
* StringLength::TOO_SHORT: "messaging.form.message.content.too_short.error_message",
* StringLength::TOO_LONG: "messaging.form.message.content.too_long.error_message",
* }
* }
* )
*/
public ?TextArea $reply = null;
}

0 comments on commit acfbaa8

Please sign in to comment.