Mercurial > hg > cmmr2012-drupal-site
comparison core/lib/Drupal/Core/Ajax/AnnounceCommand.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
4:a9cd425dd02b | 5:12f9dff5fda9 |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Core\Ajax; | |
4 | |
5 use Drupal\Core\Asset\AttachedAssets; | |
6 | |
7 /** | |
8 * AJAX command for a JavaScript Drupal.announce() call. | |
9 * | |
10 * @ingroup ajax | |
11 */ | |
12 class AnnounceCommand implements CommandInterface, CommandWithAttachedAssetsInterface { | |
13 | |
14 /** | |
15 * The assertive priority attribute value. | |
16 * | |
17 * @var string | |
18 */ | |
19 const PRIORITY_ASSERTIVE = 'assertive'; | |
20 | |
21 /** | |
22 * The polite priority attribute value. | |
23 * | |
24 * @var string | |
25 */ | |
26 const PRIORITY_POLITE = 'polite'; | |
27 | |
28 /** | |
29 * The text to be announced. | |
30 * | |
31 * @var string | |
32 */ | |
33 protected $text; | |
34 | |
35 /** | |
36 * The priority that will be used for the announcement. | |
37 * | |
38 * @var string | |
39 */ | |
40 protected $priority; | |
41 | |
42 /** | |
43 * Constructs an AnnounceCommand object. | |
44 * | |
45 * @param string $text | |
46 * The text to be announced. | |
47 * @param string|null $priority | |
48 * (optional) The priority that will be used for the announcement. Defaults | |
49 * to NULL which will not set a 'priority' in the response sent to the | |
50 * client and therefore the JavaScript Drupal.announce() default of 'polite' | |
51 * will be used for the message. | |
52 */ | |
53 public function __construct($text, $priority = NULL) { | |
54 $this->text = $text; | |
55 $this->priority = $priority; | |
56 } | |
57 | |
58 /** | |
59 * {@inheritdoc} | |
60 */ | |
61 public function render() { | |
62 $render = [ | |
63 'command' => 'announce', | |
64 'text' => $this->text, | |
65 ]; | |
66 if ($this->priority !== NULL) { | |
67 $render['priority'] = $this->priority; | |
68 } | |
69 return $render; | |
70 } | |
71 | |
72 /** | |
73 * {@inheritdoc} | |
74 */ | |
75 public function getAttachedAssets() { | |
76 $assets = new AttachedAssets(); | |
77 $assets->setLibraries(['core/drupal.announce']); | |
78 return $assets; | |
79 } | |
80 | |
81 } |