19declare(strict_types=1);
58 public function __construct(
string $a_title =
"",
string $a_postvar =
"")
66 $this->ui_factory =
$DIC[
'ui.factory'];
67 $this->ui_renderer =
$DIC[
'ui.renderer'];
72 return $this->hooks[$key] ??
false;
82 if (isset($this->hooks[$key])) {
83 unset($this->hooks[$key]);
128 public function setMulti(
bool $a_multi,
bool $a_sortable =
false,
bool $a_addremove =
true): void
130 $this->multi = $a_multi;
137 foreach ($this->inputs as $key => $item) {
140 } elseif (array_key_exists($key,
$value)) {
141 $item->setValue((
string)
$value[$key]);
149 foreach ($this->inputs as $key => $item) {
150 $out[$key] = $item->getValue();
160 $this->line_values =
$data;
176 if (is_array(
$post)) {
177 foreach (
$post as $authority) {
179 array_key_exists(self::MULTI_FIELD_ID, $authority) &&
180 array_key_exists(self::MULTI_FIELD_OVER, $authority) &&
181 array_key_exists(self::MULTI_FIELD_SCOPE, $authority) &&
182 trim((
string) $authority[self::MULTI_FIELD_OVER]) !==
'' &&
183 trim((
string) $authority[self::MULTI_FIELD_SCOPE]) !==
''
185 $this->
setAlert($this->
lng->txt(
"msg_input_is_required"));
196 if (isset($this->cust_attr[$key]) && !$override) {
197 $this->cust_attr[$key] .=
' ' .
$value;
199 $this->cust_attr[$key] =
$value;
216 public function render(
int|
string $iterator_id = 0,
bool $clean_render =
false): string
219 $tpl =
new ilTemplate(
"tpl.prop_generic_multi_line.html",
true,
true,
'components/ILIAS/OrgUnit');
221 $class =
'multi_input_line';
224 $tpl->setCurrentBlock(
'cust_attr');
225 $tpl->setVariable(
'CUSTOM_ATTR_KEY', $key);
226 $tpl->setVariable(
'CUSTOM_ATTR_VALUE',
$value);
227 $tpl->parseCurrentBlock();
230 foreach (
$inputs as $key => $input) {
231 $input = clone $input;
234 if (!method_exists($input,
'render')) {
243 throw new \ilException(
244 "Method " . $input::class
245 .
"::render() does not exists! You cannot use this input-type in ilMultiLineInputGUI"
250 $is_disabled_hook = $this->
getHook(self::HOOK_IS_INPUT_DISABLED);
251 if ($is_disabled_hook !==
false && !$clean_render) {
252 $input->setDisabled($is_disabled_hook($this->
getValue()));
255 $input->setDisabled(
true);
257 if ($iterator_id == 0 && !isset($this->post_var_cache[$key])) {
258 $this->post_var_cache[$key] = $input->getPostVar();
261 $input->setPostVar($this->post_var_cache[$key]);
264 $input->setPostVar($post_var);
265 $before_render_hook = $this->
getHook(self::HOOK_BEFORE_INPUT_RENDER);
266 if ($before_render_hook !==
false && !$clean_render) {
267 $input = $before_render_hook($this->
getValue(), $key, $input);
271 $tpl->setCurrentBlock(
'hidden');
272 $tpl->setVariable(
'NAME', $post_var);
277 $tpl->setCurrentBlock(
'input_label');
278 $tpl->setVariable(
'LABEL', $input->getTitle());
279 $tpl->setVariable(
'CONTENT', $input->getHTML());
280 $tpl->parseCurrentBlock();
281 $first_label =
false;
283 $tpl->setCurrentBlock(
'input');
284 $tpl->setVariable(
'CONTENT', $input->getHTML());
289 $tpl->setCurrentBlock(
'input_label');
290 $tpl->setVariable(
'LABEL', $input->getTitle());
291 $tpl->setVariable(
'CONTENT', $input->render());
292 $first_label =
false;
294 $tpl->setCurrentBlock(
'input');
295 $tpl->setVariable(
'CONTENT', $input->render());
301 $tpl->setCurrentBlock(
'input_info_label');
302 $tpl->setVariable(
'INFO_LABEL', $input->getInfo());
303 $tpl->parseCurrentBlock();
305 $tpl->setCurrentBlock(
'input_info');
306 $tpl->setVariable(
'INFO', $input->getInfo());
307 $tpl->parseCurrentBlock();
310 $tpl->parseCurrentBlock();
313 $is_removeable_hook = $this->
getHook(self::HOOK_IS_LINE_REMOVABLE);
314 if ($is_removeable_hook !==
false && !$clean_render) {
315 $show_remove = $is_removeable_hook($this->
getValue());
317 $tpl->setCurrentBlock(
'multi_icons');
318 $tpl->setVariable(
'IMAGE_PLUS', $this->getGlyph(
'add'));
319 $tpl->setVariable(
'IMAGE_MINUS', $this->getGlyph(
'remove'));
320 $tpl->parseCurrentBlock();
328 $this->global_tpl->addJavascript(
'assets/js/generic_multi_line_input.js');
339 $output .= $this->
render(0,
true);
340 if ($this->
getMulti() && is_array($this->line_values) && count($this->line_values) > 0) {
341 $tpl =
new ilTemplate(
"tpl.prop_generic_multi_line.html",
true,
true,
'components/ILIAS/OrgUnit');
342 $tpl->setVariable(
'ADDITIONAL_ATTRS',
"id='multi_line_add_button' style='display:none'");
343 $tpl->setCurrentBlock(
'multi_icons');
344 $tpl->setVariable(
'IMAGE_PLUS', $this->getGlyph(
'add'));
345 $tpl->setVariable(
'IMAGE_MINUS', $this->getGlyph(
'remove'));
346 $tpl->parseCurrentBlock();
347 $output .= $tpl->get();
348 foreach ($this->line_values as $run =>
$data) {
350 $object->setValue(
$data);
351 $output .= $object->render($run);
353 } elseif ($this->render_one_for_empty_value) {
354 $output .= $this->
render(0,
true);
356 $tpl =
new ilTemplate(
"tpl.prop_generic_multi_line.html",
true,
true,
'components/ILIAS/OrgUnit');
357 $tpl->setVariable(
'ADDITIONAL_ATTRS',
"id='multi_line_add_button'");
358 $tpl->setCurrentBlock(
'multi_icons');
359 $tpl->setVariable(
'IMAGE_PLUS', $this->getGlyph(
'add'));
360 $tpl->setVariable(
'IMAGE_MINUS', $this->getGlyph(
'remove'));
362 $tpl->parseCurrentBlock();
363 $output .= $tpl->get();
366 $output =
"<div style=\"display:none;\" id='{$this->getFieldId()}' class='multi_line_input'>{$output}</div>";
367 $config = json_encode($this->input_options);
371 'locale' => $this->
lng->getLangKey()
376 il.DataCollection.genericMultiLineInit('{$this->getFieldId()}',$config,$options);
377 document.body.querySelector('#{$this->getFieldId()}').removeAttribute('style');
400 return $this->
render(
"toolbar");
434 private function getGlyph(
string $which): string
436 $symbol = $this->ui_factory->symbol()->glyph()->$which();
440 ->withAdditionalOnLoadCode(
441 fn(
$id):
string =>
"document.getElementById('" .
$id .
"').classList.add('{$which}_button');"
444 return $this->ui_renderer->render($symbol);
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
setVariable($variable, $value='')
Sets a variable value.
Builds a Color from either hex- or rgb values.
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
This class represents a text area property in a property form.
An entity that renders components to a string output.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc