ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
IconFormUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\File\Icon;
22 
27 
32 {
33  public const MODE_CREATE = 'create';
34  public const MODE_EDIT = 'edit';
35  public const FORM_ICON_CREATION = 'form_icon_creation';
36  public const FORM_ICON_UPDATING = 'form_icon_updating';
37  public const INPUT_ICON = 'input_icon';
38  public const INPUT_DESC_ICON = 'input_desc_icon';
39  public const INPUT_ACTIVE = 'input_active';
40  public const INPUT_DESC_ACTIVE = 'input_desc_active';
41  public const INPUT_SUFFIXES = 'input_suffixes';
42  public const INPUT_DESC_SUFFIXES = 'input_desc_suffixes';
43 
44  private \ilCtrl $ctrl;
45  private \ilLanguage $lng;
46  private \ilTabsGUI $tabs;
50  private \ILIAS\Refinery\Factory $refinery;
51 
52  public function __construct(
53  private Icon $icon,
54  private string $mode,
55  private IconRepositoryInterface $icon_repo
56  ) {
57  global $DIC;
58  $this->ctrl = $DIC->ctrl();
59  $this->lng = $DIC->language();
60  $this->tabs = $DIC->tabs();
61  $this->ui_factory = $DIC->ui()->factory();
62  $this->wrapper = $DIC->http()->wrapper();
63  $this->refinery = $DIC->refinery();
64 
65  $this->initIconForm();
66  }
67 
68  protected function initIconForm(): void
69  {
70  $this->tabs->clearSubTabs();
71  $this->tabs->clearTargets();
72  $back_target = $this->ctrl->getLinkTargetByClass(
73  ilObjFileIconsOverviewGUI::class,
75  );
76  $this->tabs->setBackTarget($this->lng->txt('back'), $back_target);
77 
78  if ($this->mode === self::MODE_EDIT) {
79  $form_title = $this->lng->txt(self::FORM_ICON_UPDATING);
80  $form_action = $this->ctrl->getFormActionByClass(
81  ilObjFileIconsOverviewGUI::class,
83  );
84  } else {
85  $form_title = $this->lng->txt(self::FORM_ICON_CREATION);
86  $form_action = $this->ctrl->getFormActionByClass(
87  ilObjFileIconsOverviewGUI::class,
89  );
90  }
91 
92  $rid = $this->icon->getRid();
93  $this->ctrl->setParameterByClass(ilIconUploadHandlerGUI::class, 'rid', $rid);
94  $icon_input = $this->ui_factory->input()->field()->file(
96  $this->lng->txt(self::INPUT_ICON),
97  $this->lng->txt(self::INPUT_DESC_ICON)
98  )->withAcceptedMimeTypes(
99  [MimeType::IMAGE__SVG_XML]
100  )->withRequired(
101  true
102  );
103  if ($rid !== "") {
104  $icon_input = $icon_input->withValue([$rid]);
105  }
106 
107  $active_input = $this->ui_factory->input()->field()->checkbox(
108  $this->lng->txt(self::INPUT_ACTIVE),
109  $this->lng->txt(self::INPUT_DESC_ACTIVE)
110  )->withValue(
111  $this->icon->isActive()
112  );
113 
114  $suffix_input = $this->ui_factory->input()->field()->text(
115  $this->lng->txt(self::INPUT_SUFFIXES),
116  $this->lng->txt(self::INPUT_DESC_SUFFIXES)
117  )->withRequired(
118  true
119  )->withValue(
120  $this->icon_repo->turnSuffixesArrayIntoString($this->icon->getSuffixes())
121  )->withAdditionalTransformation(
122  $this->refinery->custom()->transformation(fn($suffixes_input): array => $this->icon_repo->turnSuffixesStringIntoArray($suffixes_input))
123  )->withAdditionalTransformation(
124  $this->refinery->custom()->constraint(fn($suffixes_input): bool => $this->icon_repo->hasSuffixInputOnlyAllowedCharacters($suffixes_input), $this->lng->txt('msg_error_suffixes_with_forbidden_characters'))
125  )->withAdditionalTransformation(
126  $this->refinery->custom()->constraint(fn($suffixes_input): bool => $this->icon_repo->hasSuffixInputNoDuplicatesToItsOwnEntries($suffixes_input), $this->lng->txt('msg_error_duplicate_suffix_entries'))
127  )->withAdditionalTransformation(
128  $this->refinery->custom()->constraint(function ($suffixes_input): bool {
129  //retrieve the value of the active_input as it is needed for the causesNoActiveSuffixesConflict validation
130  $section = $this->icon_form->getInputs()[0];
131  $inputs = $section->getInputs();
132  $input_active = $inputs[self::INPUT_ACTIVE];
133  $field_is_active = $input_active->getName();
134  $to_bool = $this->refinery->custom()->transformation(fn($checkbox_input_value): bool => $this->transformCheckboxInputValueToBool($checkbox_input_value));
135  $post_is_active_value = $this->wrapper->post()->retrieve($field_is_active, $to_bool);
136 
137  return $this->icon_repo->causesNoActiveSuffixesConflict(
138  $suffixes_input,
139  $post_is_active_value,
140  $this->icon
141  );
142  }, $this->lng->txt('msg_error_active_suffixes_conflict'))
143  );
144 
145  $section = $this->ui_factory->input()->field()->section([
146  self::INPUT_ICON => $icon_input,
147  self::INPUT_ACTIVE => $active_input,
148  self::INPUT_SUFFIXES => $suffix_input
149  ], $form_title);
150  $this->icon_form = $this->ui_factory->input()->container()->form()->standard($form_action, [$section]);
151  }
152 
153  public function getIconForm(): Standard
154  {
155  return $this->icon_form;
156  }
157 
158  public function transformCheckboxInputValueToBool($checkbox_input_value): bool
159  {
160  if ($checkbox_input_value !== null) {
161  $checkbox_input_value_str = $this->refinery->kindlyTo()->string()->transform($checkbox_input_value);
162  if ($checkbox_input_value_str == "checked") {
163  return true;
164  }
165  }
166  return false;
167  }
168 }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
__construct(private Icon $icon, private string $mode, private IconRepositoryInterface $icon_repo)
Definition: IconFormUI.php:52
global $DIC
Definition: shib_login.php:26
Builds data types.
Definition: Factory.php:35
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:61
ILIAS Refinery Factory $refinery
Definition: IconFormUI.php:50
WrapperFactory $wrapper
Definition: IconFormUI.php:48
transformCheckboxInputValueToBool($checkbox_input_value)
Definition: IconFormUI.php:158