2-activity_fail.php 916 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace cx_newsletter;
  3. trait activity_fail {
  4. protected function is_failed() : bool {
  5. return $this->error !== null;
  6. }
  7. protected function get_error_site_params() : array {
  8. return [
  9. 'content' => $this->error,
  10. 'type' => 'toast-error'
  11. ];
  12. }
  13. protected function fail(
  14. string|\cx_appengine\string_builder $content
  15. ) : self {
  16. if (!is_string($content)) {
  17. $content = $content->get();
  18. }
  19. $this->error = __($content, 'cx_newsletter');
  20. return $this;
  21. }
  22. protected function get_error_template() : \cx_appengine\template {
  23. return (
  24. $this
  25. ->get_templates()
  26. ->prepare('only_toast_site')
  27. );
  28. }
  29. protected function construct_fail() : self {
  30. $this->error = null;
  31. return $this;
  32. }
  33. private ?string $error;
  34. }