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; }