ILIAS  release_8 Revision v8.24
Image.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
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 string $alt;
47 protected ?string $action = '';
48
49 public function __construct(string $type, string $source, string $alt)
50 {
51 $this->checkArgIsElement("type", $type, self::$types, "image type");
52
53 $this->type = $type;
54 $this->src = $source;
55 $this->alt = $alt;
56 }
57
61 public function getType(): string
62 {
63 return $this->type;
64 }
65
69 public function withSource(string $source): C\Image\Image
70 {
71 $clone = clone $this;
72 $clone->src = $source;
73 return $clone;
74 }
75
79 public function getSource(): string
80 {
81 return $this->src;
82 }
83
87 public function withAlt(string $alt): C\Image\Image
88 {
89 $clone = clone $this;
90 $clone->alt = $alt;
91 return $clone;
92 }
93
97 public function getAlt(): string
98 {
99 return $this->alt;
100 }
101
105 public function withAction($action): C\Image\Image
106 {
107 $this->checkStringOrSignalArg("action", $action);
108 $clone = clone $this;
109 if (is_string($action)) {
110 $clone->action = $action;
111 } else {
115 $clone->action = null;
116 $clone->setTriggeredSignal($action, "click");
117 }
118
119 return $clone;
120 }
121
125 public function getAction()
126 {
127 if ($this->action !== null) {
128 return $this->action;
129 }
130 return $this->getTriggeredSignalsFor("click");
131 }
132
136 public function withOnClick(Signal $signal): C\Clickable
137 {
138 return $this->withTriggeredSignal($signal, 'click');
139 }
140
144 public function appendOnClick(Signal $signal): C\Clickable
145 {
146 return $this->appendTriggeredSignal($signal, 'click');
147 }
148}
__construct(string $type, string $source, string $alt)
Definition: Image.php:49
$source
Definition: metadata.php:93
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: Factory.php:21
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.