ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Action.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ILIAS\UI\Implementation\Component\ComponentHelper;
29
30abstract class Action implements I\Action
31{
32 use ComponentHelper;
38 public const OPT_ACTIONID = 'actId';
39 public const OPT_ROWID = 'rowid';
40
41 protected Signal|URI $target;
42 protected bool $async = false;
43
44 public function __construct(
45 protected string $label,
46 protected URLBuilder $url_builder,
47 protected URLBuilderToken $row_id_parameter
48 ) {
49 $this->target = $url_builder->buildURI();
50 }
51
52 public function getLabel(): string
53 {
54 return $this->label;
55 }
56
57 public function getTarget(): Signal|URI
58 {
59 return $this->target;
60 }
61
62 public function withSignalTarget(Signal $target): self
63 {
64 $clone = clone $this;
65 $clone->target = $target;
66 return $clone;
67 }
68
69 public function withAsync(bool $async = true): self
70 {
71 $clone = clone $this;
72 $clone->async = $async;
73 return $clone;
74 }
75
76 public function isAsync(): bool
77 {
78 return $this->async;
79 }
80
81 public function withRowId(string $row_id): self
82 {
83 $clone = clone $this;
84 $target = $clone->getTarget();
85
86 if ($target instanceof Signal) {
87 $target->addOption('rowid', $row_id);
88 }
89 if ($target instanceof URI) {
90 $target = $this->url_builder->withParameter(
91 $this->row_id_parameter,
92 [$row_id]
93 )
94 ->buildURI();
95 }
96 $clone->target = $target;
97 return $clone;
98 }
99
100 public function getURLBuilderJS(): string
101 {
102 return $this->url_builder->renderObject([$this->row_id_parameter]);
103 }
104 public function getURLBuilderTokensJS(): string
105 {
106 return $this->url_builder->renderTokens([$this->row_id_parameter]);
107 }
108}
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
const OPT_ACTIONID
JS needs to know about the type of an action and where to find the options (in case of signal) Theses...
Definition: Action.php:38
__construct(protected string $label, protected URLBuilder $url_builder, protected URLBuilderToken $row_id_parameter)
Definition: Action.php:44
buildURI()
Get a URI representation of the full URL including query string and fragment/hash.
Definition: URLBuilder.php:214