20 declare(strict_types=1);
61 public function __construct(
string $a_title =
"",
string $a_postvar =
"")
69 $this->ui_factory = $DIC[
'ui.factory'];
70 $this->ui_renderer = $DIC[
'ui.renderer'];
71 $this->renderer_loader = $DIC[
"ui.component_renderer_loader"];
77 if (isset($this->hooks[$key])) {
78 return $this->hooks[$key];
84 public function addHook(
string $key, array $options)
86 $this->hooks[$key] = $options;
91 if (isset($this->hooks[$key])) {
92 unset($this->hooks[$key]);
103 $this->input_options[$input->
getPostVar()] = $options;
136 public function setMulti(
bool $a_multi,
bool $a_sortable =
false,
bool $a_addremove =
true): void
138 $this->multi = $a_multi;
145 foreach ($this->inputs as $key => $item) {
149 if (array_key_exists($key, $value)) {
150 $item->setValue((
string) $value[$key]);
159 foreach ($this->inputs as $key => $item) {
160 $out[$key] = $item->getValue();
170 $this->line_values =
$data;
182 $internal_fields = array_keys($this->inputs);
186 if (is_array(
$post)) {
187 foreach (
$post as $authority) {
189 array_key_exists(self::MULTI_FIELD_ID, $authority) &&
190 array_key_exists(self::MULTI_FIELD_OVER, $authority) &&
191 array_key_exists(self::MULTI_FIELD_SCOPE, $authority) &&
192 trim($authority[self::MULTI_FIELD_OVER]) !==
'' &&
193 trim($authority[self::MULTI_FIELD_SCOPE]) !==
'' 195 $this->
setAlert($this->
lng->txt(
"msg_input_is_required"));
206 if (isset($this->cust_attr[$key]) && !$override) {
207 $this->cust_attr[$key] .=
' ' .
$value;
209 $this->cust_attr[$key] =
$value;
228 public function render(
int|
string $iterator_id = 0,
bool $clean_render =
false): string
231 $tpl =
new ilTemplate(
"tpl.prop_generic_multi_line.html",
true,
true,
'components/ILIAS/OrgUnit');
233 $class =
'multi_input_line';
236 $tpl->setCurrentBlock(
'cust_attr');
237 $tpl->setVariable(
'CUSTOM_ATTR_KEY', $key);
238 $tpl->setVariable(
'CUSTOM_ATTR_VALUE',
$value);
239 $tpl->parseCurrentBlock();
242 foreach ($inputs as $key => $input) {
243 $input = clone $input;
246 if (!method_exists($input,
'render')) {
255 throw new \ilException(
"Method " . get_class($input)
256 .
"::render() does not exists! You cannot use this input-type in ilMultiLineInputGUI");
260 $is_disabled_hook = $this->
getHook(self::HOOK_IS_INPUT_DISABLED);
261 if ($is_disabled_hook !==
false && !$clean_render) {
262 $input->setDisabled($is_disabled_hook($this->
getValue()));
265 $input->setDisabled(
true);
267 if ($iterator_id == 0 && !isset($this->post_var_cache[$key])) {
268 $this->post_var_cache[$key] = $input->getPostVar();
271 $input->setPostVar($this->post_var_cache[$key]);
274 $input->setPostVar($post_var);
275 $before_render_hook = $this->
getHook(self::HOOK_BEFORE_INPUT_RENDER);
276 if ($before_render_hook !==
false && !$clean_render) {
277 $input = $before_render_hook($this->
getValue(), $key, $input);
281 $tpl->setCurrentBlock(
'hidden');
282 $tpl->setVariable(
'NAME', $post_var);
287 $tpl->setCurrentBlock(
'input_label');
288 $tpl->setVariable(
'LABEL', $input->getTitle());
289 $tpl->setVariable(
'CONTENT', $input->getHTML());
290 $tpl->parseCurrentBlock();
291 $first_label =
false;
293 $tpl->setCurrentBlock(
'input');
294 $tpl->setVariable(
'CONTENT', $input->getHTML());
299 $tpl->setCurrentBlock(
'input_label');
300 $tpl->setVariable(
'LABEL', $input->getTitle());
301 $tpl->setVariable(
'CONTENT', $input->render());
302 $first_label =
false;
304 $tpl->setCurrentBlock(
'input');
305 $tpl->setVariable(
'CONTENT', $input->render());
311 $tpl->setCurrentBlock(
'input_info_label');
312 $tpl->setVariable(
'INFO_LABEL', $input->getInfo());
313 $tpl->parseCurrentBlock();
315 $tpl->setCurrentBlock(
'input_info');
316 $tpl->setVariable(
'INFO', $input->getInfo());
317 $tpl->parseCurrentBlock();
320 $tpl->parseCurrentBlock();
323 $is_removeable_hook = $this->
getHook(self::HOOK_IS_LINE_REMOVABLE);
324 if ($is_removeable_hook !==
false && !$clean_render) {
325 $show_remove = $is_removeable_hook($this->
getValue());
327 $tpl->setCurrentBlock(
'multi_icons');
328 $tpl->setVariable(
'IMAGE_PLUS', $this->
getGlyph(
'add'));
329 $tpl->setVariable(
'IMAGE_MINUS', $this->
getGlyph(
'remove'));
330 $tpl->parseCurrentBlock();
333 $tpl->setCurrentBlock(
'multi_icons_move');
334 $tpl->setVariable(
'IMAGE_UP', $this->
getGlyph(
'up'));
335 $tpl->setVariable(
'IMAGE_DOWN', $this->
getGlyph(
'down'));
336 $tpl->parseCurrentBlock();
345 $this->global_tpl->addJavascript(
'assets/js/generic_multi_line_input.js');
356 $output .= $this->
render(0,
true);
357 if ($this->
getMulti() && is_array($this->line_values) && count($this->line_values) > 0) {
358 $tpl =
new ilTemplate(
"tpl.prop_generic_multi_line.html",
true,
true,
'components/ILIAS/OrgUnit');
359 $tpl->setVariable(
'ADDITIONAL_ATTRS',
"id='multi_line_add_button' style='display:none'");
360 $tpl->setCurrentBlock(
'multi_icons');
361 $tpl->setVariable(
'IMAGE_PLUS', $this->
getGlyph(
'add'));
362 $tpl->setVariable(
'IMAGE_MINUS', $this->
getGlyph(
'remove'));
363 $tpl->parseCurrentBlock();
364 $output .= $tpl->get();
366 foreach ($this->line_values as $run =>
$data) {
368 $object->setValue(
$data);
369 $output .= $object->render($run);
372 if ($this->render_one_for_empty_value) {
373 $output .= $this->
render(0,
true);
375 $tpl =
new ilTemplate(
"tpl.prop_generic_multi_line.html",
true,
true,
'components/ILIAS/OrgUnit');
376 $tpl->setVariable(
'ADDITIONAL_ATTRS',
"id='multi_line_add_button'");
377 $tpl->setCurrentBlock(
'multi_icons');
378 $tpl->setVariable(
'IMAGE_PLUS', $this->
getGlyph(
'add'));
379 $tpl->setVariable(
'IMAGE_MINUS', $this->
getGlyph(
'remove'));
381 $tpl->parseCurrentBlock();
382 $output .= $tpl->get();
386 $output =
"<div style=\"display:none;\" id='{$this->getFieldId()}' class='multi_line_input'>{$output}</div>";
387 $config = json_encode($this->input_options);
388 $options = json_encode([
391 'locale' => $this->
lng->getLangKey()
394 $tpl->addOnLoadCode(
" 395 il.DataCollection.genericMultiLineInit('{$this->getFieldId()}',$config,$options); 396 document.body.querySelector('#{$this->getFieldId()}').removeAttribute('style'); 418 return $this->
render(
"toolbar");
464 $symbol = $this->ui_factory->symbol()->glyph()->$which();
469 $renderer = $this->renderer_loader->getRendererFor(
471 [$this->ui_factory->button()->bulky($symbol,
'',
'')]
473 return $renderer->render($symbol, $this->ui_renderer);
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
setVariable($variable, $value='')
Sets a variable value.
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
__construct(Container $dic, ilPlugin $plugin)
This class represents a text area property in a property form.