ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilFileCommonSettingsGUI.php
Go to the documentation of this file.
1<?php
2
23{
24 public const CMD_EDIT = 'editSettings';
25 public const CMD_SAVE = 'saveSettings';
26 private array $services = [
28 ];
29
30 public function __construct(protected ilObjFile $object, protected ilCtrl $ctrl, protected ilGlobalTemplateInterface $tpl, protected ilLanguage $lng, protected ilObjectService $object_service)
31 {
32 }
33
34 public function executeCommand(): void
35 {
36 $cmd = $this->ctrl->getCmd();
37 match ($cmd) {
38 self::CMD_EDIT => $this->editSettings(),
39 self::CMD_SAVE => $this->saveSettings(),
40 default => throw new Exception('Unknown command ' . $cmd),
41 };
42 }
43
44 protected function editSettings(?ilPropertyFormGUI $form = null): void
45 {
46 if (is_null($form)) {
47 $form = $this->buildForm();
48 }
49 $this->tpl->setContent($form->getHTML());
50 }
51
52 protected function buildForm(): ilPropertyFormGUI
53 {
54 $form = new ilPropertyFormGUI();
55 $form->setFormAction($this->ctrl->getFormAction($this));
56 $form->setTitle($this->txt('obj_features'));
57 $form->addCommandButton(self::CMD_SAVE, $this->txt('save'));
58 $form->addCommandButton(self::CMD_EDIT, $this->txt('cancel'));
59
60 $this->addServiceSettingsToForm($form);
61 $this->addCommonFieldsToForm($form);
62
63 return $form;
64 }
65
66 protected function addServiceSettingsToForm(ilPropertyFormGUI $form): void
67 {
69 $this->object->getId(),
70 $form,
71 $this->services
72 );
73 }
74
75 protected function addCommonFieldsToForm(ilPropertyFormGUI $form): void
76 {
77 //
78 }
79
80 protected function saveSettings(): void
81 {
82 $form = $this->buildForm();
83
84 if (!$form->checkInput()) {
85 $form->setValuesByPost();
86 $this->editSettings($form);
87 return;
88 }
89
91 $this->object->getId(),
92 $form,
93 $this->services
94 );
95
96 $this->tpl->setOnScreenMessage("success", $this->lng->txt('service_settings_saved'), true);
97 $this->ctrl->redirect($this, self::CMD_EDIT);
98 }
99
100 protected function txt(string $code): string
101 {
102 return $this->lng->txt($code);
103 }
104}
Class ilCtrl provides processing control methods.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(protected ilObjFile $object, protected ilCtrl $ctrl, protected ilGlobalTemplateInterface $tpl, protected ilLanguage $lng, protected ilObjectService $object_service)
addCommonFieldsToForm(ilPropertyFormGUI $form)
addServiceSettingsToForm(ilPropertyFormGUI $form)
editSettings(?ilPropertyFormGUI $form=null)
language handling
Class ilObjFile.
static updateServiceSettingsForm(int $obj_id, ilPropertyFormGUI $form, array $services)
static initServiceSettingsForm(int $obj_id, ilPropertyFormGUI $form, array $services)
This class represents a property form user interface.
global $lng
Definition: privfeed.php:31