Skip to content
Snippets Groups Projects
Commit e8c038d4 authored by Julian Pustkuchen's avatar Julian Pustkuchen Committed by Pedro Pelaez
Browse files

Resolve #3397446 "Attach library with command"

parent 26f11395
Branches
Tags
1 merge request!3Resolve #3397446 "Attach library with command"
# Ajax Command Page Reload
## Usage
See [Drupal Core AJAX API](https://www.drupal.org/docs/drupal-apis/ajax-api) for general documentation.
~~~
$response = new AjaxResponse();
$response->addCommand(new PageReloadCommand());
return $response;
~~~
Ajax Command Page Reload
Usage:
Add the library to the page with something like:
`$form['#attached']['library'][] = "ajax_command_page_reload/ajax_commands";`
Then a callback can send the command:
`$response->addCommand(new PageReloadCommand());`
......@@ -3,11 +3,13 @@
namespace Drupal\ajax_command_page_reload\Ajax;
use Drupal\Core\Ajax\CommandInterface;
use Drupal\Core\Ajax\CommandWithAttachedAssetsInterface;
use Drupal\Core\Asset\AttachedAssets;
/**
* Trigger "window.location.reload()" within the frontend.
*/
class PageReloadCommand implements CommandInterface {
class PageReloadCommand implements CommandInterface, CommandWithAttachedAssetsInterface {
/**
* {@inheritdoc}
......@@ -18,4 +20,13 @@ class PageReloadCommand implements CommandInterface {
];
}
/**
* {@inheritdoc}
*/
public function getAttachedAssets() {
$assets = new AttachedAssets();
$assets->setLibraries(['ajax_command_page_reload/ajax_commands']);
return $assets;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment