ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Image.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ILIAS\UI\Implementation\Component\ComponentHelper;
28
33class Image implements C\Image\Image
34{
35 use ComponentHelper;
37 use Triggerer;
38
39 private static array $types = [
40 self::STANDARD,
41 self::RESPONSIVE
42 ];
43
44 private string $type;
45 private string $src;
46 private array $additional_high_res_sources = [];
47 private string $alt;
48 protected ?string $action = '';
49
50 public function __construct(string $type, string $source, string $alt)
51 {
52 $this->checkArgIsElement("type", $type, self::$types, "image type");
53
54 $this->type = $type;
55 $this->src = $source;
56 $this->alt = $alt;
57 }
58
62 public function getType(): string
63 {
64 return $this->type;
65 }
66
70 public function withSource(string $source): C\Image\Image
71 {
72 $clone = clone $this;
73 $clone->src = $source;
74 return $clone;
75 }
76
80 public function getSource(): string
81 {
82 return $this->src;
83 }
84
88 public function withAdditionalHighResSource(string $source, int $min_width_in_pixels): C\Image\Image
89 {
90 $clone = clone $this;
91 $clone->additional_high_res_sources[$min_width_in_pixels] = $source;
92 return $clone;
93 }
94
98 public function getAdditionalHighResSources(): array
99 {
101 }
102
103
107 public function withAlt(string $alt): C\Image\Image
108 {
109 $clone = clone $this;
110 $clone->alt = $alt;
111 return $clone;
112 }
113
117 public function getAlt(): string
118 {
119 return $this->alt;
120 }
121
125 public function withAction($action): C\Image\Image
126 {
127 $this->checkStringOrSignalArg("action", $action);
128 $clone = clone $this;
129 if (is_string($action)) {
130 $clone->action = $action;
131 } else {
135 $clone->action = null;
136 $clone->setTriggeredSignal($action, "click");
137 }
138
139 return $clone;
140 }
141
145 public function getAction()
146 {
147 if ($this->action !== null) {
148 return $this->action;
149 }
150 return $this->getTriggeredSignalsFor("click");
151 }
152
156 public function withOnClick(Signal $signal): C\Clickable
157 {
158 return $this->withTriggeredSignal($signal, 'click');
159 }
160
164 public function appendOnClick(Signal $signal): C\Clickable
165 {
166 return $this->appendTriggeredSignal($signal, 'click');
167 }
168}
withAdditionalHighResSource(string $source, int $min_width_in_pixels)
Definition: Image.php:88
__construct(string $type, string $source, string $alt)
Definition: Image.php:50
withAction(URI|Signal|string $action)
appendTriggeredSignal(C\Signal $signal, string $event)
Append a triggered signal to other signals of the same event.
Definition: Triggerer.php:47
withTriggeredSignal(C\Signal $signal, string $event)
Add a triggered signal, replacing any other signals registered on the same event.
Definition: Triggerer.php:62
getTriggeredSignalsFor(string $event)
Get signals that are triggered for a certain event.
Definition: Triggerer.php:94
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.