ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Custom.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ILIAS\User\Profile\Fields\NoOverrides;
30use ILIAS\Refinery\Factory as Refinery;
32
33class Custom implements FieldDefinition
34{
35 use NoOverrides;
36
37 public function __construct(
38 private readonly Uuid $identifier,
39 private ?Type $type = null,
40 private string $label = '',
41 private ?AvailableSections $section = null,
42 private ?string $additional_edit_form_data = null
43 ) {
44 }
45
46 public function isUnspecific(): bool
47 {
48 return $this->type === null;
49 }
50
51 public function getIdentifier(): string
52 {
53 return $this->identifier->toString();
54 }
55
56 public function getLabel(Language $lng): string
57 {
58 return $this->label;
59 }
60
61 public function withLabel(string $label): self
62 {
63 $clone = clone $this;
64 $clone->label = $label;
65 return $clone;
66 }
67
68 public function getTypeLabel(Language $lng): string
69 {
70 return $this->type?->getLabel($lng) ?? '';
71 }
72
73 public function withType(Type $type): self
74 {
75 $clone = clone $this;
76 $clone->type = $type;
77 return $clone;
78 }
79
80 public function getSection(): AvailableSections
81 {
82 return $this->section;
83 }
84
85 public function withSection(AvailableSections $section): self
86 {
87 $clone = clone $this;
88 $clone->section = $section;
89 return $clone;
90 }
91
94 FieldFactory $ff,
96 ): ?FormInput {
98 $lng,
99 $ff,
100 $refinery,
101 $this->additional_edit_form_data
102 );
103 }
104
105 public function withAdditionalEditFormData(?string $data): self
106 {
107 $clone = clone $this;
108 $clone->additional_edit_form_data = $data;
109 return $clone;
110 }
111
112 public function toStorage(): array
113 {
114 return [
115 'field_name' => [
117 $this->label
118 ],
119 'field_type' => [
121 $this->type::class
122 ],
123 'field_values' => [
125 $this->additional_edit_form_data
126 ],
127 'section' => [
129 $this->section->value
130 ]
131 ];
132 }
133
134 public function getLegacyInput(
137 ?\ilObjUser $user = null
139 $value = $user === null
140 ? []
141 : $user->getProfileData()->getAdditionalFieldByIdentifier($this->getIdentifier()) ?? [];
142 return $this->type->getLegacyInput(
143 $lng,
144 $context,
145 $value,
146 $this->label,
147 $this->additional_edit_form_data
148 );
149 }
150
151 public function addValueToUserObject(
152 \ilObjUser $user,
153 mixed $input,
154 \ilPropertyFormGUI $form
155 ): \ilObjUser {
156 return $user->withProfileData(
157 $user->getProfileData()->withAdditionalFieldByIdentifier(
158 $this->getIdentifier(),
159 $this->type->prepareUserInputForStorage($input)
160 )
161 );
162 }
163
164 public function retrieveValueFromUser(\ilObjUser $user): string
165 {
166 return $this->type->buildPresentationValueFromUserValue(
167 $user->getProfileData()->getAdditionalFieldByIdentifier($this->getIdentifier()) ?? [],
168 $this->additional_edit_form_data
169 );
170 }
171}
Builds data types.
Definition: Factory.php:36
withSection(AvailableSections $section)
Definition: Custom.php:85
getAdditionalEditFormInputs(Language $lng, FieldFactory $ff, Refinery $refinery)
Definition: Custom.php:92
addValueToUserObject(\ilObjUser $user, mixed $input, \ilPropertyFormGUI $form)
Definition: Custom.php:151
retrieveValueFromUser(\ilObjUser $user)
Definition: Custom.php:164
getLegacyInput(Language $lng, Context $context, ?\ilObjUser $user=null)
You don't need to add a post_var to the input as the User will handle this for you,...
Definition: Custom.php:134
__construct(private readonly Uuid $identifier, private ?Type $type=null, private string $label='', private ?AvailableSections $section=null, private ?string $additional_edit_form_data=null)
Definition: Custom.php:37
This class represents a property in a property form.
User class.
This class represents a property form user interface.
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This describes inputs that can be used in forms.
Definition: FormInput.php:33
This is what a factory for input fields looks like.
Definition: Factory.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $lng
Definition: privfeed.php:31
$context
Definition: webdav.php:31