trait FormMessage mixin ViewableData (View source)

Form component which contains a castable message

Properties

protected string $message
protected string $messageType
protected string $messageCast

Casting for message

Methods

public
string
getMessage()

Returns the field message, used by form validation.

public
string
getMessageType()

Returns the field message type.

public
string
getMessageCast()

Casting type for this message. Will be 'text' or 'html'

public
$this
setMessage(string $message, string $messageType = ValidationResult::TYPE_ERROR, string $messageCast = ValidationResult::CAST_TEXT)

Sets the error message to be displayed on the form field.

public
appendMessage(string $message, string $messageType = ValidationResult::TYPE_ERROR, string $messageCast = ValidationResult::CAST_TEXT, bool $force = false)

Appends a message to the existing message if the types and casts match.

protected
string
getMessageCastingHelper()

Get casting helper for message cast, or null if not known

public
array|null
getSchemaMessage()

Get form schema encoded message

Details

string getMessage()

Returns the field message, used by form validation.

Use setError() to set this property.

Return Value

string

string getMessageType()

Returns the field message type.

Arbitrary value which is mostly used for CSS classes in the rendered HTML, e.g "required".

Use setError() to set this property.

Return Value

string

string getMessageCast()

Casting type for this message. Will be 'text' or 'html'

Return Value

string

$this setMessage(string $message, string $messageType = ValidationResult::TYPE_ERROR, string $messageCast = ValidationResult::CAST_TEXT)

Sets the error message to be displayed on the form field.

Allows HTML content, so remember to use Convert::raw2xml().

Parameters

string $message

Message string

string $messageType

Message type

string $messageCast

Return Value

$this

FormMessage appendMessage(string $message, string $messageType = ValidationResult::TYPE_ERROR, string $messageCast = ValidationResult::CAST_TEXT, bool $force = false)

Appends a message to the existing message if the types and casts match.

If either is different, the $force argument determines the behaviour.

Note: to prevent duplicates, we check for the $message string in the existing message. If the existing message contains $message as a substring, it won't be added.

Parameters

string $message
string $messageType
string $messageCast
bool $force

if true, and the new message cannot be appended to the existing one, the existing message will be overridden.

Return Value

FormMessage

Exceptions

InvalidArgumentException

protected string getMessageCastingHelper()

Get casting helper for message cast, or null if not known

Return Value

string

array|null getSchemaMessage()

Get form schema encoded message

Return Value

array|null

Message in array format, or null if no message