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
30
34final class EditForm
35{
37 private \ilLanguage $lng;
40 private \ILIAS\Refinery\Factory $refinery;
41
42 public function __construct(
43 private Request $request,
44 private ResourceIdentification $rid
45 ) {
46 global $DIC;
47 $this->ui_factory = $DIC->ui()->factory();
48 $this->lng = $DIC->language();
49 $this->manager = $DIC->resourceStorage()->manage();
50 $this->revision = $this->manager->getCurrentRevision($this->rid);
51 $this->refinery = $DIC->refinery();
52 }
53
54 private function customTrafo(callable $trafo): Transformation
55 {
56 return $this->refinery->custom()->transformation($trafo);
57 }
58
59 public function getFields(): array
60 {
61 return [
62 'title' => $this->ui_factory // currently we use the filename as title in collection guis
63 ->input()
64 ->field()
65 ->text(
66 $this->lng->txt('title')
67 )
68 ->withRequired(true)
69 ->withValue(
70 $this->revision->getInformation()->getTitle()
71 )
72 ->withAdditionalTransformation(
73 $this->customTrafo(
74 function (?string $value): ?string {
75 // we store the title with the suffix. the suffix must be preserved
76 $new_title = empty($value) ? $this->revision->getInformation()->getTitle() : $value;
77 $new_title_without_suffix = preg_replace('/\.\w+$/', '', $new_title);
78 $new_title_with_suffix = $new_title_without_suffix . '.' . $this->revision->getInformation(
79 )->getSuffix();
80
81 $this->revision->getInformation()->setTitle(
82 $new_title_with_suffix
83 );
84
85 return $new_title_with_suffix;
86 }
87 )
88 ),
89 ];
90 }
91
92 public function getAsSection(): Section
93 {
94 return $this->ui_factory->input()->field()->section(
95 $this->getFields(),
96 $this->lng->txt('edit')
98 $this->customTrafo(
99 fn(array $values): bool => $this->manager->updateRevision($this->revision)
100 )
101 );
102 }
103
104 public function getAsForm(string $post_url): Standard
105 {
106 return $this->ui_factory->input()->container()->form()->standard(
107 $post_url,
108 $this->getFields()
110 $this->customTrafo(
111 fn(array $values): bool => $this->manager->updateRevision($this->revision)
112 )
113 );
114 }
115}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
__construct(private Request $request, private ResourceIdentification $rid)
Definition: EditForm.php:42
A transformation is a function from one datatype to another.
withAdditionalTransformation(Transformation $trafo)
Apply a transformation to the data of the form.
This describes a standard form.
Definition: Standard.php:29
This describes section inputs.
Definition: Section.php:29
withAdditionalTransformation(Transformation $trafo)
Apply a transformation to the content of the input.
This is how the factory for UI elements looks.
Definition: Factory.php:38
global $DIC
Definition: shib_login.php:26