diff --git a/core/core.libraries.yml b/core/core.libraries.yml index 76dca59c6d..86879cfdee 100644 --- a/core/core.libraries.yml +++ b/core/core.libraries.yml @@ -92,7 +92,6 @@ drupal.ajax: dependencies: - core/jquery - core/drupal - - core/drupal.announce - core/drupalSettings - core/drupal.progress - core/jquery.once diff --git a/core/lib/Drupal/Core/Ajax/AnnounceCommand.php b/core/lib/Drupal/Core/Ajax/AnnounceCommand.php index ba92788ea5..3c612f77e9 100644 --- a/core/lib/Drupal/Core/Ajax/AnnounceCommand.php +++ b/core/lib/Drupal/Core/Ajax/AnnounceCommand.php @@ -2,15 +2,18 @@ namespace Drupal\Core\Ajax; +use Drupal\Core\Asset\AttachedAssets; + /** * AJAX command for a javascript Drupal.announce() call. * * @ingroup ajax */ -class AnnounceCommand implements CommandInterface { +class AnnounceCommand implements CommandInterface, CommandWithAttachedAssetsInterface { + /** - * The text for the message. + * The text to be announced. * * @var string */ @@ -30,11 +33,19 @@ public function __construct($text) { * {@inheritdoc} */ public function render() { - return [ 'command' => 'announce', 'text' => $this->text, ]; } + /** + * {@inheritdoc} + */ + public function getAttachedAssets() { + $assets = new AttachedAssets(); + $assets->setLibraries(['core/drupal.announce']); + return $assets; + } + } diff --git a/core/tests/Drupal/Tests/Core/Ajax/AjaxCommandsTest.php b/core/tests/Drupal/Tests/Core/Ajax/AjaxCommandsTest.php index 2ca7382109..b528659cde 100644 --- a/core/tests/Drupal/Tests/Core/Ajax/AjaxCommandsTest.php +++ b/core/tests/Drupal/Tests/Core/Ajax/AjaxCommandsTest.php @@ -3,6 +3,7 @@ namespace Drupal\Tests\Core\Ajax; use Drupal\Core\Ajax\AnnounceCommand; +use Drupal\Core\Asset\AttachedAssets; use Drupal\Tests\UnitTestCase; use Drupal\Core\Ajax\AddCssCommand; use Drupal\Core\Ajax\AfterCommand; @@ -84,12 +85,16 @@ public function testAlertCommand() { */ public function testAnnounceCommand() { $command = new AnnounceCommand('Things are going to change!'); + $expected_assets = new AttachedAssets(); + $expected_assets->setLibraries(['core/drupal.announce']); + $this->assertEquals($expected_assets, $command->getAttachedAssets()); + $expected = [ 'command' => 'announce', 'text' => 'Things are going to change!', ]; - $this->assertEquals($expected, $command->render()); + $this->assertSame($expected, $command->render()); } /**