ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
Button.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 use ILIAS\UI\Component as C;
30 
34 abstract class Button implements C\Button\Button
35 {
36  use ComponentHelper;
38  use Triggerer;
39  use Engageable;
40  use HasHelpTopics;
41 
42  protected ?Symbol $symbol = null;
43  protected ?string $action;
44  protected bool $active = true;
45  protected string $aria_label = '';
46  protected bool $aria_checked = false;
47 
48 
49  public function __construct(
50  protected string $label,
51  $action
52  ) {
53  $this->checkStringOrSignalArg("action", $action);
54  if (is_string($action)) {
55  $this->action = $action;
56  } else {
57  $this->action = null;
58  $this->setTriggeredSignal($action, "click");
59  }
60  }
61 
65  public function getLabel(): string
66  {
67  return $this->label;
68  }
69 
73  public function withLabel(string $label): C\Button\Button
74  {
75  $clone = clone $this;
76  $clone->label = $label;
77  return $clone;
78  }
79 
83  public function getSymbol(): ?Symbol
84  {
85  return $this->symbol;
86  }
87 
91  public function withSymbol(?Symbol $symbol): self
92  {
93  $clone = clone $this;
94  $clone->symbol = $symbol;
95  return $clone;
96  }
97 
101  public function getAction()
102  {
103  if ($this->action !== null) {
104  return $this->action;
105  }
106  return $this->getTriggeredSignalsFor("click");
107  }
108 
112  public function isActive(): bool
113  {
114  return $this->active;
115  }
116 
120  public function withUnavailableAction(bool $flag = true): C\Button\Button
121  {
122  $clone = clone $this;
123  $clone->active = !$flag;
124  return $clone;
125  }
126 
130  public function withOnClick(Signal $signal): C\Button\Button
131  {
132  $this->action = null;
133  return $this->withTriggeredSignal($signal, 'click');
134  }
135 
139  public function appendOnClick(Signal $signal): C\Clickable
140  {
141  return $this->appendTriggeredSignal($signal, 'click');
142  }
143 
147  public function withOnHover(Signal $signal): C\Hoverable
148  {
149  // Note: The event 'hover' maps to 'mouseenter' in javascript. Although 'hover' is available in JQuery,
150  // it encodes the 'mouseenter' and 'mouseleave' events and thus expects two event handlers.
151  // In the context of this framework, the signal MUST only be triggered on the 'mouseenter' event.
152  // See also: https://api.jquery.com/hover/
153  return $this->withTriggeredSignal($signal, 'mouseenter');
154  }
155 
159  public function appendOnHover(Signal $signal): C\Hoverable
160  {
161  return $this->appendTriggeredSignal($signal, 'mouseenter');
162  }
163 
167  public function withAriaLabel(string $aria_label): C\Button\Button
168  {
169  $clone = clone $this;
170  $clone->aria_label = $aria_label;
171  return $clone;
172  }
173 
177  public function getAriaLabel(): string
178  {
179  return $this->aria_label;
180  }
181 }
appendTriggeredSignal(C\Signal $signal, string $event)
Append a triggered signal to other signals of the same event.
Definition: Triggerer.php:47
This describes a symbol.
Definition: Symbol.php:29
withTriggeredSignal(C\Signal $signal, string $event)
Add a triggered signal, replacing any other signals registered on the same event. ...
Definition: Triggerer.php:62
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
getTriggeredSignalsFor(string $event)
Get signals that are triggered for a certain event.
Definition: Triggerer.php:94
trait Engageable
Trait Engageable.
Definition: Engageable.php:29
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
setTriggeredSignal(C\Signal $signal, string $event)
Add a triggered signal, replacing any other signals registered on the same event. ...
Definition: Triggerer.php:75
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Bulky.php:21
__construct(protected string $label, $action)
Definition: Button.php:49
getSymbol()
Get the symbol (as part of the Buttons&#39;s label) if set.
Definition: Button.php:83