ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
EditForm.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24{
25 protected \ilPropertyFormGUI $form;
26 protected \ilAdvancedMDRecordGUI $md;
27 protected bool $disabled;
28
29 public function __construct(
31 bool $disabled,
32 string $form_action,
33 string $submit_command,
34 string $submit_label
35 ) {
36 $this->md = $md;
37 $this->disabled = $disabled;
38 $this->form = $this->initForm(
39 $form_action,
40 $submit_command,
41 $submit_label
42 );
43 }
44
45 protected function initForm(
46 string $form_action,
47 string $submit_command,
48 string $submit_label
50 $form = new \ilPropertyFormGUI();
51 $form->setFormAction($form_action);
52
53 $this->md->setPropertyForm($form);
54 $this->md->parse();
55
56 if (!$this->disabled) {
57 $form->addCommandButton($submit_command, $submit_label);
58 return $form;
59 }
60
61 // this is necessary to disable the md fields
62 foreach ($form->getInputItemsRecursive() as $item) {
63 if ($item instanceof \ilCombinationInputGUI) {
64 $item->__call('setValue', ['']);
65 $item->__call('setDisabled', [true]);
66 }
67 if (method_exists($item, 'setDisabled')) {
69 $item->setDisabled(true);
70 }
71 }
72
73 return $form;
74 }
75
76 public function importFromPostAndValidate(): bool
77 {
83 $valid = $this->form->checkInput();
84 $post_imported = $this->md->importEditFormPostValues();
85
86 return $post_imported && $valid && !$this->disabled;
87 }
88
89 public function updateMetadata(): void
90 {
91 $this->md->writeEditForm();
92 }
93
94 public function render(): string
95 {
96 return $this->form->getHTML();
97 }
98
102 public function getFormGUI(): \ilPropertyFormGUI
103 {
104 return $this->form;
105 }
106}
ilAdvancedMDRecordGUI $md
Definition: EditForm.php:26
__construct(\ilAdvancedMDRecordGUI $md, bool $disabled, string $form_action, string $submit_command, string $submit_label)
Definition: EditForm.php:29
getFormGUI()
Use this only for command forwarding via ctrl!
Definition: EditForm.php:102
This class represents a number property in a property form.
setFormAction(string $a_formaction)
This class represents a property form user interface.
getInputItemsRecursive()
returns a flat array of all input items including the possibly existing subitems recursively
$valid
form( $class_path, string $cmd, string $submit_caption="")