UpdateBuildIdCommand.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Drupal\Core\Ajax;
  3. /**
  4. * AJAX command for updating the value of a hidden form_build_id input element
  5. * on a form. It requires the form passed in to have keys for both the old build
  6. * ID in #build_id_old and the new build ID in #build_id.
  7. *
  8. * The primary use case for this Ajax command is to serve a new build ID to a
  9. * form served from the cache to an anonymous user, preventing one anonymous
  10. * user from accessing the form state of another anonymous user on Ajax enabled
  11. * forms.
  12. *
  13. * This command is implemented by
  14. * Drupal.AjaxCommands.prototype.update_build_id() defined in misc/ajax.js.
  15. *O
  16. * @ingroup ajax
  17. */
  18. class UpdateBuildIdCommand implements CommandInterface {
  19. /**
  20. * Old build id.
  21. *
  22. * @var string
  23. */
  24. protected $old;
  25. /**
  26. * New build id.
  27. *
  28. * @var string
  29. */
  30. protected $new;
  31. /**
  32. * Constructs a UpdateBuildIdCommand object.
  33. *
  34. * @param string $old
  35. * The old build_id.
  36. * @param string $new
  37. * The new build_id.
  38. */
  39. public function __construct($old, $new) {
  40. $this->old = $old;
  41. $this->new = $new;
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. public function render() {
  47. return [
  48. 'command' => 'update_build_id',
  49. 'old' => $this->old,
  50. 'new' => $this->new,
  51. ];
  52. }
  53. }