ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
Toast.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 
31 
33 {
34  use ComponentHelper;
36 
37  public const DEFAULT_VANISH_TIME = 5000;
38  public const DEFAULT_DELAY_TIME = 500;
39 
43  protected $title;
44  protected Icon $icon;
45  protected string $description = '';
47  protected array $links = [];
48  protected string $action = '';
50  protected Signal $signal;
53 
54  public function __construct($title, Icon $icon, SignalGeneratorInterface $signal_generator)
55  {
56  $this->signal_generator = $signal_generator;
57  $this->title = $title;
58  $this->icon = $icon;
59  }
60 
64  public function getTitle()
65  {
66  return $this->title;
67  }
68 
69  public function withDescription(string $description): ComponentInterface\Toast
70  {
71  $new = clone $this;
72  $new->description = $description;
73  return $new;
74  }
75 
76  public function getDescription(): string
77  {
78  return $this->description;
79  }
80 
82  {
83  $new = clone $this;
84  $new->links[] = $link;
85  return $new;
86  }
87 
89  {
90  $new = clone $this;
91  $new->links = [];
92  return $new;
93  }
94 
98  public function getLinks(): array
99  {
100  return $this->links;
101  }
102 
103  public function withAction(string $action): ComponentInterface\Toast
104  {
105  $new = clone $this;
106  $new->action = $action;
107  return $new;
108  }
109 
110  public function getAction(): string
111  {
112  return $this->action;
113  }
114 
115  public function getIcon(): Icon
116  {
117  return $this->icon;
118  }
119 
120  public function initSignals(): void
121  {
122  $this->signal = $this->signal_generator->create();
123  }
124 
125  public function getShowSignal(): Signal
126  {
127  return $this->signal;
128  }
129 
130  public function withVanishTime(int $vanishTime): Toast
131  {
132  $new = clone $this;
133  $new->vanishTime = $vanishTime;
134  return $new;
135  }
136 
137  public function getVanishTime(): int
138  {
139  return $this->vanishTime;
140  }
141 
142  public function withDelayTime(int $delayTime): Toast
143  {
144  $new = clone $this;
145  $new->delayTime = $delayTime;
146  return $new;
147  }
148 
149  public function getDelayTime(): int
150  {
151  return $this->delayTime;
152  }
153 }
__construct($title, Icon $icon, SignalGeneratorInterface $signal_generator)
Definition: Toast.php:54
This describes how an icon could be modified during construction of UI.
Definition: Icon.php:28
getShowSignal()
Get the signal to show this toast in the frontend.
Definition: Toast.php:125
withAction(string $action)
Create a copy of this toast with an url, which is called asynchronous when the user interact with the...
Definition: Toast.php:103
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Container.php:21
SignalGeneratorInterface $signal_generator
Definition: Toast.php:49
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Container.php:21
initSignals()
Init the default signals.
Definition: Toast.php:120