| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace cx_newsletter;
- trait activity_toast {
- private function get_toast_template() : \cx_appengine\template {
- return (
- $this
- ->get_templates()
- ->prepare('toast')
- );
- }
- protected function success_toast(string $content) : self {
- return $this->make_toast($content, toast_type::success);
- }
- protected function warning_toast(string $content) : self {
- return $this->make_toast($content, toast_type::warning);
- }
- protected function error_toast(string $content) : self {
- return $this->make_toast($content, toast_type::error);
- }
- private function make_toast(string $content, toast_type $type) : self {
- $this->toast = __($content, 'cx_newsletter');
- $this->toast_type = $type;
-
- return $this;
- }
- protected function has_toast() : bool {
- return $this->toast !== null and $this->toast_type !== null;
- }
- private function get_toast_params() : array {
- return [
- 'content' => $this->toast,
- 'type' => $this->toast_type->value
- ];
- }
- protected function render_toast() : \cx_appengine\string_builder {
- if (!$this->has_toast()) {
- return new \cx_appengine\string_builder();
- }
- return (
- $this
- ->get_toast_template()
- ->render($this->get_toast_params())
- );
- }
- protected function construct_toast() : self {
- $this->toast = null;
- $this->toast_type = null;
-
- return $this;
- }
-
- private ?toast_type $toast_type;
- private ?string $toast;
- }
|