ILIAS  release_8 Revision v8.24
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
44 protected $target;
45 protected bool $async = false;
46
47 protected string $label;
50
51 public function __construct(
52 string $label,
55 ) {
56 $this->target = $url_builder->buildURI();
57 $this->label = $label;
58 $this->url_builder = $url_builder;
59 $this->row_id_parameter = $row_id_parameter;
60 }
61
62 public function getLabel(): string
63 {
64 return $this->label;
65 }
66
70 public function getTarget()
71 {
72 return $this->target;
73 }
74
75 public function withSignalTarget(Signal $target): self
76 {
77 $clone = clone $this;
78 $clone->target = $target;
79 return $clone;
80 }
81
82 public function withAsync(bool $async = true): self
83 {
84 $clone = clone $this;
85 $clone->async = $async;
86 return $clone;
87 }
88
89 public function isAsync(): bool
90 {
91 return $this->async;
92 }
93
94 public function withRowId(string $row_id): self
95 {
96 $clone = clone $this;
97 $target = $clone->getTarget();
98
99 if ($target instanceof Signal) {
100 $target->addOption('rowid', $row_id);
101 }
102 if ($target instanceof URI) {
103 $target = $this->url_builder->withParameter(
104 $this->row_id_parameter,
105 [$row_id]
106 )
107 ->buildURI();
108 }
109 $clone->target = $target;
110 return $clone;
111 }
112
113 public function getURLBuilderJS(): string
114 {
115 return $this->url_builder->renderObject([$this->row_id_parameter]);
116 }
117 public function getURLBuilderTokensJS(): string
118 {
119 return $this->url_builder->renderTokens([$this->row_id_parameter]);
120 }
121}
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(string $label, URLBuilder $url_builder, URLBuilderToken $row_id_parameter)
Definition: Action.php:51
buildURI()
Get a URI representation of the full URL including query string and fragment/hash.
Definition: URLBuilder.php:214
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...