ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
PageContentProvider.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\UICore;
22
34
41{
42 private static string $content = "";
43 private static string $perma_link = "";
44 private static string $title = "";
45 private static string $short_title = "";
46 private static string $view_title = "";
47
48 public static function setContent(string $content): void
49 {
50 self::$content = $content;
51 }
52
53 public static function setTitle(string $title): void
54 {
55 self::$title = $title;
56 }
57
58 public static function setShortTitle(string $short_title): void
59 {
60 self::$short_title = $short_title;
61 }
62
63 public static function setViewTitle(string $view_title): void
64 {
65 self::$view_title = $view_title;
66 }
67
68 public static function setPermaLink(string $perma_link): void
69 {
70 self::$perma_link = $perma_link;
71 }
72
74 {
75 return $this->context_collection->main();
76 }
77
78 public function getContentModification(CalledContexts $screen_context_stack): ?ContentModification
79 {
80 return $this->globalScreen()->layout()->factory()->content()->withModification(function (
82 ): ?Content {
83 $ui = $this->dic->ui();
84 return $ui->factory()->legacy()->content(
85 $ui->renderer()->render($content) . self::$content
86 );
87 })->withLowPriority();
88 }
89
90 public function getTitleModification(CalledContexts $screen_context_stack): ?TitleModification
91 {
93 $modification = $this->globalScreen()->layout()->factory()->title()->withModification(
94 fn(?string $content): ?string => self::$title
95 )->withLowPriority();
96
97 return $modification;
98 }
99
100 public function getShortTitleModification(CalledContexts $screen_context_stack): ?ShortTitleModification
101 {
103 $modification = $this->globalScreen()->layout()->factory()->short_title()->withModification(
104 fn(?string $content): ?string => self::$short_title
105 )->withLowPriority();
106
107 return $modification;
108 }
109
110 public function getViewTitleModification(CalledContexts $screen_context_stack): ?ViewTitleModification
111 {
113 $modification = $this->globalScreen()->layout()->factory()->view_title()->withModification(
114 fn(?string $content): ?string => $this->buildTabTitle() . self::$view_title
115 )->withLowPriority();
116
117 return $modification;
118 }
119
126 private function buildTabTitle(): string
127 {
128 // This anonymous function generates a translated title from a "tab" array.
129 // in some cases the tabs are already translated (dir_text = true), in others not...
130 $tab_title_generator = function (array $tab): string {
131 $tab_title = ($tab['dir_text'] ?? false) === false ? $this->dic->language()->txt($tab['text']) : $tab['text'] ?? '';
132 return $tab_title . ': ';
133 };
134
135 // we only know the 'id' of the active tab and don't want to rely on the array index, so we
136 // loop over tabs or subtabs to find the "right" one
137 $tab_looper = static function (array $tabs, string $active_tab) use ($tab_title_generator): string {
138 $tab_title = '';
139 foreach ($tabs as $tab) {
140 if ($tab['id'] === $active_tab) {
141 $tab_title = $tab_title_generator($tab);
142 break;
143 }
144 }
145 return $tab_title;
146 };
147
148 // TABS
149 $tabs = $this->dic->tabs()->target; // this only works because target is currently public...
150 $active_tab = $this->dic->tabs()->getActiveTab();
151 if ($active_tab === '' && isset($tabs[0])) {
152 $active_tab = $tabs[0]['id']; // if no tab is active, use the first one
153 }
154
155 $tab_title = $tab_looper($tabs, $active_tab);
156
157 // SUBTABS
158 $subtab_title = '';
159 $subtabs = $this->dic->tabs()->sub_target; // this only works because subtarget is currently public...
160 if (count($subtabs) > 1) { // we only need to do something if there are more than one subtabs
161 $active_subtab = array_values(
162 array_filter($subtabs, static fn(array $subtab): bool => $subtab['activate'] ?? false)
163 )[0]['id'] ?? '';
164
165 if ($active_subtab === '' && isset($subtabs[0])) {
166 $active_subtab = $subtabs[0]['id']; // if no tab is active, use the first one
167 }
168 $subtab_title = $tab_looper($subtabs, $active_subtab);
169 }
170
171 return $subtab_title . $tab_title;
172 }
173
177 public static function getPermaLink(): string
178 {
179 return self::$perma_link;
180 }
181}
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
static setPermaLink(string $perma_link)
static setContent(string $content)
static setViewTitle(string $view_title)
buildTabTitle()
@description This method was introduced due to A11y problems, see https://mantis.ilias....
getContentModification(CalledContexts $screen_context_stack)
@inheritDoc
static setShortTitle(string $short_title)