BaseCommand.php 787 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace Drupal\Core\Ajax;
  3. /**
  4. * Base command that only exists to simplify AJAX commands.
  5. */
  6. class BaseCommand implements CommandInterface {
  7. /**
  8. * The name of the command.
  9. *
  10. * @var string
  11. */
  12. protected $command;
  13. /**
  14. * The data to pass on to the client side.
  15. *
  16. * @var string
  17. */
  18. protected $data;
  19. /**
  20. * Constructs a BaseCommand object.
  21. *
  22. * @param string $command
  23. * The name of the command.
  24. * @param string $data
  25. * The data to pass on to the client side.
  26. */
  27. public function __construct($command, $data) {
  28. $this->command = $command;
  29. $this->data = $data;
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function render() {
  35. return [
  36. 'command' => $this->command,
  37. 'data' => $this->data,
  38. ];
  39. }
  40. }