ILIAS  trunk Revision v11.0_alpha-1861-g09f3d197f78
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
EditForm.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 class EditForm implements EditFormInterface
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 }
This class represents a property form user interface.
$valid
__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.
form( $class_path, string $cmd, string $submit_caption="")
disabled()
description: > Example showing how to plug a disabled checkbox into a form
Definition: disabled.php:32
ilAdvancedMDRecordGUI $md
Definition: EditForm.php:26