class AnnounceCommand implements CommandInterface, CommandWithAttachedAssetsInterface (View source)

AJAX command for a JavaScript Drupal.announce() call.

Developers should be extra careful if this command and \Drupal\Core\Ajax\MessageCommand are included in the same response. By default, MessageCommand will also call Drupal.announce() and announce the message to the screen reader (unless the option to suppress announcements is passed to the constructor). Manual testing with a screen reader is strongly recommended.

Constants

PRIORITY_ASSERTIVE

The assertive priority attribute value.

PRIORITY_POLITE

The polite priority attribute value.

Properties

protected string $text

The text to be announced.

protected string $priority

The priority that will be used for the announcement.

Methods

__construct(string $text, string|null $priority = NULL)

Constructs an AnnounceCommand object.

render()

Return an array to be run through json_encode and sent to the client.

getAttachedAssets()

Gets the attached assets.

Details

__construct(string $text, string|null $priority = NULL)

Constructs an AnnounceCommand object.

Parameters

string $text

The text to be announced.

string|null $priority

(optional) The priority that will be used for the announcement. Defaults to NULL which will not set a 'priority' in the response sent to the client and therefore the JavaScript Drupal.announce() default of 'polite' will be used for the message.

render()

Return an array to be run through json_encode and sent to the client.

AttachedAssets|null getAttachedAssets()

Gets the attached assets.

Return Value

AttachedAssets|null

The attached assets for this command.