19declare(strict_types=1);
21use ILIAS\GlobalScreen\Scope\MainMenu\Collector\Renderer\Hasher;
28use ILIAS\GlobalScreen\GUI\I18n\Translator;
29use Psr\Http\Message\RequestInterface;
62 protected Translator
$lng,
63 private RequestInterface $request,
73 $txt = (fn($key):
string => $this->
lng->txt($key));
74 $f = (fn(): InputFactory => $this->ui_fa->input());
77 $title =
$f()->field()->text(
$txt(
'topitem_title_default'),
$txt(
'topitem_title_default_byline'))
79 if (!$this->item_facade->isEmpty()) {
80 $title = $title->withValue($this->item_facade->getDefaultTitle());
85 if ($this->item_facade->supportsCustomIcon()) {
88 ->withByline(
$txt(
'topitem_icon_byline'))
89 ->withAcceptedMimeTypes([MimeType::IMAGE__SVG_XML]);
90 if ($this->item_facade->getIconID() !==
null) {
91 $icon = $icon->withValue([$this->item_facade->getIconID()]);
98 if (($this->item_facade->isEmpty() || $this->item_facade->isCustom())) {
100 $type =
$f()->field()->switchableGroup(
102 $txt(
'topitem_type'),
103 $txt(
'topitem_type_byline')
104 )->withRequired(
true);
105 if (!$this->item_facade->isEmpty()) {
106 $string = $this->item_facade->getType() ===
'' ? TopParentItem::class : $this->item_facade->getType();
107 $type = $type->withValue($this->hash($string));
109 $type = $type->withValue($this->hash(TopParentItem::class));
115 $active =
$f()->field()->checkbox(
$txt(
'topitem_active'),
$txt(
'topitem_active_byline'));
116 $active = $active->withValue($this->item_facade->isActivated());
120 if ($this->item_facade->supportsRoleBasedVisibility()) {
121 $value_role_based_visibility =
null;
122 $global_roles = $this->
access->getGlobalRoles();
123 $global_role_ids = $this->item_facade->getGlobalRoleIDs();
124 if ($this->item_facade->hasRoleBasedVisibility() && !empty($global_role_ids)) {
126 $value_role_based_visibility[0] = array_intersect(
128 array_keys($global_roles)
131 $role_based_visibility =
$f()->field()->optionalGroup(
133 $f()->field()->multiSelect(
134 $txt(
'sub_global_roles'),
136 )->withRequired(
false)
138 $txt(
'sub_role_based_visibility'),
139 $txt(
'sub_role_based_visibility_byline')
140 )->withValue($value_role_based_visibility);
145 if ($this->item_facade->isEmpty()) {
146 $this->
form =
$f()->container()->form()->standard(
147 $this->
ctrl->getLinkTargetByClass(
148 ilMMTopItemGUI::class,
154 $this->
form =
$f()->container()->form()->standard(
155 $this->
ctrl->getLinkTargetByClass(
156 ilMMTopItemGUI::class,
166 $this->
form = $this->
form->withRequest($this->request);
168 if (is_null(
$data)) {
172 $this->item_facade->setAction((
string) (
$data[
'action'] ??
''));
173 $this->item_facade->setDefaultTitle((
string)
$data[self::F_TITLE]);
174 $this->item_facade->setActiveStatus((
bool)
$data[self::F_ACTIVE]);
175 if ($this->item_facade->supportsRoleBasedVisibility()) {
176 $this->item_facade->setRoleBasedVisibility((
bool)
$data[self::F_ROLE_BASED_VISIBILITY]);
177 if (
$data[self::F_ROLE_BASED_VISIBILITY] && !empty(
$data[self::F_ROLE_BASED_VISIBILITY])) {
178 $this->item_facade->setGlobalRoleIDs((array)
$data[self::F_ROLE_BASED_VISIBILITY][0]);
182 $this->item_facade->setIsTopItm(
true);
184 if ($this->item_facade->isEmpty()) {
185 $type = $this->unhash((
string) (
$data[self::F_TYPE][0]));
186 $this->item_facade->setType($type);
187 $this->
repository->createItem($this->item_facade);
190 if ($this->item_facade->supportsCustomIcon()) {
191 $icon = (string) (
$data[self::F_ICON][0] ??
'');
192 $this->item_facade->setIconID($icon);
195 if ($this->item_facade->isCustom()) {
196 $type = $this->item_facade->getType();
197 $type_specific_data = (array)
$data[self::F_TYPE][1];
198 $type_handler = $this->
repository->getTypeHandlerForType($type);
199 $type_handler->saveFormFields($this->item_facade->identification(), $type_specific_data);
202 $this->
repository->updateItem($this->item_facade);
212 return $this->ui_re->render([$this->
form]);
223 $type_informations = $this->
repository->getPossibleTopItemTypesWithInformation($new);
224 foreach ($type_informations as $classname => $information) {
225 if ($this->item_facade->isEmpty()
226 || (!$this->item_facade->isEmpty() && $classname === $this->item_facade->getType(
227 ) && $this->item_facade->isCustom())
229 $inputs = $this->
repository->getTypeHandlerForType($classname)->getAdditionalFieldsForSubForm(
230 $this->item_facade->identification()
232 $type_groups[$this->hash($classname)] =
$f()->field()->group(
234 $information->getTypeNameForPresentation()
Builds a Color from either hex- or rgb values.
Class ilCtrl provides processing control methods.
Class ilMMUploadHandlerGUI.
Class ilObjMainMenuAccess.
This is how the factory for UI elements looks.
An entity that renders components to a string output.
Interface ilMMItemFacadeInterface.
form( $class_path, string $cmd, string $submit_caption="")
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.