19 declare(strict_types=1);
60 public function __construct(
string $a_title =
"",
string $a_postvar =
"")
68 $this->ui_factory = $DIC[
'ui.factory'];
69 $this->ui_renderer = $DIC[
'ui.renderer'];
70 $this->renderer_loader = $DIC[
"ui.component_renderer_loader"];
76 if (isset($this->hooks[$key])) {
77 return $this->hooks[$key];
83 public function addHook(
string $key, array $options)
85 $this->hooks[$key] = $options;
90 if (isset($this->hooks[$key])) {
91 unset($this->hooks[$key]);
102 $this->input_options[$input->
getPostVar()] = $options;
135 public function setMulti(
bool $a_multi,
bool $a_sortable =
false,
bool $a_addremove =
true): void
137 $this->multi = $a_multi;
144 foreach ($this->inputs as $key => $item) {
148 if (array_key_exists($key, $value)) {
149 $item->setValue((
string) $value[$key]);
158 foreach ($this->inputs as $key => $item) {
159 $out[$key] = $item->getValue();
169 $this->line_values =
$data;
181 $internal_fields = array_keys($this->inputs);
185 if (is_array(
$post)) {
186 foreach (
$post as $authority) {
188 array_key_exists(self::MULTI_FIELD_ID, $authority) &&
189 array_key_exists(self::MULTI_FIELD_OVER, $authority) &&
190 array_key_exists(self::MULTI_FIELD_SCOPE, $authority) &&
191 trim($authority[self::MULTI_FIELD_OVER]) !==
'' &&
192 trim($authority[self::MULTI_FIELD_SCOPE]) !==
'' 194 $this->
setAlert($this->
lng->txt(
"msg_input_is_required"));
205 if (isset($this->cust_attr[$key]) && !$override) {
206 $this->cust_attr[$key] .=
' ' .
$value;
208 $this->cust_attr[$key] =
$value;
227 public function render(
int|
string $iterator_id = 0,
bool $clean_render =
false): string
230 $tpl =
new ilTemplate(
"tpl.prop_generic_multi_line.html",
true,
true,
'components/ILIAS/OrgUnit');
232 $class =
'multi_input_line';
235 $tpl->setCurrentBlock(
'cust_attr');
236 $tpl->setVariable(
'CUSTOM_ATTR_KEY', $key);
237 $tpl->setVariable(
'CUSTOM_ATTR_VALUE',
$value);
238 $tpl->parseCurrentBlock();
241 foreach ($inputs as $key => $input) {
242 $input = clone $input;
245 if (!method_exists($input,
'render')) {
254 throw new \ilException(
"Method " . get_class($input)
255 .
"::render() does not exists! You cannot use this input-type in ilMultiLineInputGUI");
259 $is_disabled_hook = $this->
getHook(self::HOOK_IS_INPUT_DISABLED);
260 if ($is_disabled_hook !==
false && !$clean_render) {
261 $input->setDisabled($is_disabled_hook($this->
getValue()));
264 $input->setDisabled(
true);
266 if ($iterator_id == 0 && !isset($this->post_var_cache[$key])) {
267 $this->post_var_cache[$key] = $input->getPostVar();
270 $input->setPostVar($this->post_var_cache[$key]);
273 $input->setPostVar($post_var);
274 $before_render_hook = $this->
getHook(self::HOOK_BEFORE_INPUT_RENDER);
275 if ($before_render_hook !==
false && !$clean_render) {
276 $input = $before_render_hook($this->
getValue(), $key, $input);
280 $tpl->setCurrentBlock(
'hidden');
281 $tpl->setVariable(
'NAME', $post_var);
286 $tpl->setCurrentBlock(
'input_label');
287 $tpl->setVariable(
'LABEL', $input->getTitle());
288 $tpl->setVariable(
'CONTENT', $input->getHTML());
289 $tpl->parseCurrentBlock();
290 $first_label =
false;
292 $tpl->setCurrentBlock(
'input');
293 $tpl->setVariable(
'CONTENT', $input->getHTML());
298 $tpl->setCurrentBlock(
'input_label');
299 $tpl->setVariable(
'LABEL', $input->getTitle());
300 $tpl->setVariable(
'CONTENT', $input->render());
301 $first_label =
false;
303 $tpl->setCurrentBlock(
'input');
304 $tpl->setVariable(
'CONTENT', $input->render());
310 $tpl->setCurrentBlock(
'input_info_label');
311 $tpl->setVariable(
'INFO_LABEL', $input->getInfo());
312 $tpl->parseCurrentBlock();
314 $tpl->setCurrentBlock(
'input_info');
315 $tpl->setVariable(
'INFO', $input->getInfo());
316 $tpl->parseCurrentBlock();
319 $tpl->parseCurrentBlock();
322 $is_removeable_hook = $this->
getHook(self::HOOK_IS_LINE_REMOVABLE);
323 if ($is_removeable_hook !==
false && !$clean_render) {
324 $show_remove = $is_removeable_hook($this->
getValue());
326 $tpl->setCurrentBlock(
'multi_icons');
327 $tpl->setVariable(
'IMAGE_PLUS', $this->
getGlyph(
'add'));
328 $tpl->setVariable(
'IMAGE_MINUS', $this->
getGlyph(
'remove'));
329 $tpl->parseCurrentBlock();
332 $tpl->setCurrentBlock(
'multi_icons_move');
333 $tpl->setVariable(
'IMAGE_UP', $this->
getGlyph(
'up'));
334 $tpl->setVariable(
'IMAGE_DOWN', $this->
getGlyph(
'down'));
335 $tpl->parseCurrentBlock();
344 $this->global_tpl->addJavascript(
'assets/js/generic_multi_line_input.js');
355 $output .= $this->
render(0,
true);
356 if ($this->
getMulti() && is_array($this->line_values) && count($this->line_values) > 0) {
357 $tpl =
new ilTemplate(
"tpl.prop_generic_multi_line.html",
true,
true,
'components/ILIAS/OrgUnit');
358 $tpl->setVariable(
'ADDITIONAL_ATTRS',
"id='multi_line_add_button' style='display:none'");
359 $tpl->setCurrentBlock(
'multi_icons');
360 $tpl->setVariable(
'IMAGE_PLUS', $this->
getGlyph(
'add'));
361 $tpl->setVariable(
'IMAGE_MINUS', $this->
getGlyph(
'remove'));
362 $tpl->parseCurrentBlock();
363 $output .= $tpl->get();
365 foreach ($this->line_values as $run =>
$data) {
367 $object->setValue(
$data);
368 $output .= $object->render($run);
371 if ($this->render_one_for_empty_value) {
372 $output .= $this->
render(0,
true);
374 $tpl =
new ilTemplate(
"tpl.prop_generic_multi_line.html",
true,
true,
'components/ILIAS/OrgUnit');
375 $tpl->setVariable(
'ADDITIONAL_ATTRS',
"id='multi_line_add_button'");
376 $tpl->setCurrentBlock(
'multi_icons');
377 $tpl->setVariable(
'IMAGE_PLUS', $this->
getGlyph(
'add'));
378 $tpl->setVariable(
'IMAGE_MINUS', $this->
getGlyph(
'remove'));
380 $tpl->parseCurrentBlock();
381 $output .= $tpl->get();
385 $output =
"<div style=\"display:none;\" id='{$this->getFieldId()}' class='multi_line_input'>{$output}</div>";
386 $config = json_encode($this->input_options);
387 $options = json_encode([
390 'locale' => $this->
lng->getLangKey()
393 $tpl->addOnLoadCode(
" 394 il.DataCollection.genericMultiLineInit('{$this->getFieldId()}',$config,$options); 395 document.body.querySelector('#{$this->getFieldId()}').removeAttribute('style'); 417 return $this->
render(
"toolbar");
463 $symbol = $this->ui_factory->symbol()->glyph()->$which();
468 $renderer = $this->renderer_loader->getRendererFor(
470 [$this->ui_factory->button()->bulky($symbol,
'',
'')]
472 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.