ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilWOPISettingsForm.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 use ILIAS\Data\URI;
27 
34 {
35  private Standard $form;
36  private \ILIAS\UI\Factory $ui_factory;
37  private \ILIAS\UI\Renderer $ui_renderer;
39  private ilLanguage $lng;
40  private \ILIAS\Refinery\Factory $refinery;
41 
42  public function __construct(
43  private Setting $settings,
44  ) {
45  global $DIC;
46  $this->ui_factory = $DIC->ui()->factory();
47  $this->ui_renderer = $DIC->ui()->renderer();
48  $this->ctrl = $DIC->ctrl();
49  $this->lng = $DIC->language();
50  $this->refinery = $DIC->refinery();
51 
52  $this->form = $this->initForm();
53  }
54 
55  private function initForm(): Standard
56  {
57  return $this->ui_factory->input()->container()->form()->standard(
58  $this->ctrl->getFormActionByClass(ilWOPIAdministrationGUI::class, ilWOPIAdministrationGUI::CMD_STORE),
59  $this->getSection()->getInputs()
60  );
61  }
62 
63  private function getSection(): Section
64  {
65  $wopi_activated = (bool) $this->settings->get("wopi_activated", '0');
66  $wopi_discovery_url = $this->settings->get("wopi_discovery_url");
67 
68  $wopi_url = $this->ui_factory->input()->field()->text(
69  $this->lng->txt("wopi_url"),
70  $this->lng->txt("wopi_url_byline")
71  /*. $this->renderLink(
72  " ➜︎ Wikipedia",
73  "https://en.wikipedia.org/wiki/Web_Application_Open_Platform_Interface",
74  true
75  )*/
77  $this->refinery->custom()->transformation(function ($v) {
78  return $v === '' ? null : $v;
79  })
80  )->withAdditionalTransformation(
81  $this->refinery->custom()->constraint(function ($v) {
82  if ($v === null) {
83  return false;
84  }
85  return (new Crawler())->validate(new URI($v));
86  }, $this->lng->txt('msg_error_wopi_invalid_discorvery_url'))
87  )->withAdditionalTransformation(
88  $this->refinery->custom()->transformation(function ($v) {
89  $this->settings->set("wopi_discovery_url", $v);
90 
91  return true;
92  })
93  )->withValue(
94  $wopi_discovery_url ?? ''
95  );
96 
97  return $this->ui_factory->input()->field()->section(
98  [
99  $this->ui_factory->input()->field()->optionalGroup(
100  [$wopi_url],
101  $this->lng->txt("activate_wopi")
102  )->withValue(
103  $wopi_discovery_url === null ? null : [$wopi_discovery_url]
104  )->withAdditionalTransformation(
105  $this->refinery->custom()->transformation(function ($v) {
106  if ($v === null || $v === [null]) {
107  $this->settings->set("wopi_activated", '0');
108  $this->settings->delete("wopi_discovery_url");
109  } else {
110  $this->settings->set("wopi_activated", "1");
111  }
112  return $v;
113  })
114  )
115  ],
116  $this->lng->txt("wopi_settings"),
117  );
118  }
119 
120  public function proceed(RequestInterface $request): bool
121  {
122  $this->form = $this->form->withRequest($request);
123 
124  return $this->form->getData() !== null;
125  }
126 
127  public function getHTML(): string
128  {
129  return $this->ui_renderer->render($this->form);
130  }
131 
132  private function renderLink(string $translation, string $url, bool $new_tab = true): string
133  {
134  $link = $this->ui_factory->link()->standard(
135  $translation,
136  $url
137  )->withOpenInNewViewport($new_tab);
138  return $this->ui_renderer->render($link);
139  }
140 }
proceed(RequestInterface $request)
This describes section inputs.
Definition: Section.php:28
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
ILIAS UI Renderer $ui_renderer
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
The scope of this class is split ilias-conform URI&#39;s into components.
Definition: URI.php:18
$url
Definition: ltiregstart.php:35
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:58
This describes a standard form.
Definition: Standard.php:26
form( $class_path, string $cmd, string $submit_caption="")
renderLink(string $translation, string $url, bool $new_tab=true)
__construct(private Setting $settings,)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Crawler.php:21
ILIAS Refinery Factory $refinery