ILIAS  release_8 Revision v8.23
Slate.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
22 
32 
33 abstract class Slate implements ISlate\Slate
34 {
35  use ComponentHelper;
37  use Triggerer;
38 
39  // allowed ARIA roles
40  public const MENU = 'menu';
41 
45  protected static array $allowed_aria_roles = array(
46  self::MENU
47  );
48 
49  protected string $name;
50  protected Symbol $symbol;
53  protected ?Signal $replace_signal = null;
54  protected bool $engaged = false;
55  protected ?string $mainbar_tree_position = null;
56  protected ?string $aria_role = null;
58 
62  public function __construct(
63  SignalGeneratorInterface $signal_generator,
64  string $name,
65  Symbol $symbol
66  ) {
67  $this->signal_generator = $signal_generator;
68  $this->name = $name;
69  $this->symbol = $symbol;
70 
71  $this->initSignals();
72  }
73 
77  protected function initSignals(): void
78  {
79  $this->toggle_signal = $this->signal_generator->create();
80  $this->engage_signal = $this->signal_generator->create();
81  $signal = $this->signal_generator->create(ReplaceSignalImplementation::class);
82  $this->replace_signal = $signal;
83  }
84 
88  public function getName(): string
89  {
90  return $this->name;
91  }
92 
96  public function getSymbol(): Symbol
97  {
98  return $this->symbol;
99  }
100 
104  public function getToggleSignal(): Signal
105  {
106  return $this->toggle_signal;
107  }
108 
112  public function getEngageSignal(): Signal
113  {
114  return $this->engage_signal;
115  }
116 
120  public function withEngaged(bool $state): ISlate\Slate
121  {
122  $clone = clone $this;
123  $clone->engaged = $state;
124  return $clone;
125  }
126 
130  public function getEngaged(): bool
131  {
132  return $this->engaged;
133  }
134 
138  abstract public function getContents(): array;
139 
143  public function getReplaceSignal(): ?Signal
144  {
145  return $this->replace_signal;
146  }
147 
151  public function appendOnInView(Signal $signal): ISlate\Slate
152  {
153  return $this->appendTriggeredSignal($signal, 'in_view');
154  }
155 
156 
157  abstract public function withMappedSubNodes(callable $f): ISlate\Slate;
158 
162  public function withMainBarTreePosition(string $tree_pos): ISlate\Slate
163  {
164  $clone = clone $this;
165  $clone->mainbar_tree_position = $tree_pos;
166  return $clone;
167  }
168 
169  public function getMainBarTreePosition(): ?string
170  {
172  }
173 
174  public function getMainBarTreeDepth(): int
175  {
176  $pos = explode(':', $this->mainbar_tree_position);
177  return count($pos) - 1;
178  }
179 
183  public function withAriaRole(string $aria_role): ISlate\Slate
184  {
185  $this->checkArgIsElement(
186  "role",
187  $aria_role,
188  self::$allowed_aria_roles,
189  implode('/', self::$allowed_aria_roles)
190  );
191  $clone = clone $this;
192  $clone->aria_role = $aria_role;
193  return $clone;
194  }
195 
199  public function getAriaRole(): ?string
200  {
201  return $this->aria_role;
202  }
203 }
appendTriggeredSignal(C\Signal $signal, string $event)
Append a triggered signal to other signals of the same event.
Definition: Triggerer.php:47
__construct(SignalGeneratorInterface $signal_generator, string $name, Symbol $symbol)
Definition: Slate.php:62
This describes a symbol.
Definition: Symbol.php:29
getReplaceSignal()
Signal to replace the contents of the slate.
Definition: Slate.php:143
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
withMainBarTreePosition(string $tree_pos)
Slates in the main bar need to be addressable via JS, a.o.for storing current activation states or tr...
Definition: Slate.php:162
getEngaged()
Should the slate be rendered as engaged?
Definition: Slate.php:130
withEngaged(bool $state)
Configures the slate to be rendered as engaged (or not).
Definition: Slate.php:120
initSignals()
Set the signals for this component.
Definition: Slate.php:77
appendOnInView(Signal $signal)
A Signal that is triggered when the slate "comes into view", i.e.is being engaged.
Definition: Slate.php:151
getAriaRole()
Get the ARIA role on the slate.
Definition: Slate.php:199
getEngageSignal()
Signal that engages the slate when triggered.
Definition: Slate.php:112
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Combined.php:21
withAriaRole(string $aria_role)
Get a slate like this, but with an additional ARIA role.
Definition: Slate.php:183
getToggleSignal()
Signal that toggles the slate when triggered.
Definition: Slate.php:104
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Combined.php:20