ILIAS  release_8 Revision v8.23
PageContentProvider.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\UICore;
22 
23 use ILIAS\Data\URI;
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 (
81  ?Legacy $content
82  ): ?Legacy {
83  $ui = $this->dic->ui();
84  return $ui->factory()->legacy(
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  if (($tab['dir_text'] ?? false) === false) {
132  $tab_title = $this->dic->language()->txt($tab['text']);
133  } else {
134  $tab_title = $tab['text'] ?? '';
135  }
136  $tab_title .= ': ';
137  return $tab_title;
138  };
139 
140  // we only know the 'id' of the active tab and don't want to rely on the array index, so we
141  // loop over tabs or subtabs to find the "right" one
142  $tab_looper = static function (array $tabs, string $active_tab) use ($tab_title_generator): string {
143  $tab_title = '';
144  foreach ($tabs as $tab) {
145  if ($tab['id'] === $active_tab) {
146  $tab_title = $tab_title_generator($tab);
147  break;
148  }
149  }
150  return $tab_title;
151  };
152 
153  // TABS
154  $tabs = $this->dic->tabs()->target; // this only works because target is currently public...
155  $active_tab = $this->dic->tabs()->getActiveTab();
156  if ($active_tab === '' && isset($tabs[0])) {
157  $active_tab = $tabs[0]['id']; // if no tab is active, use the first one
158  }
159 
160  $tab_title = $tab_looper($tabs, $active_tab);
161 
162  // SUBTABS
163  $subtab_title = '';
164  $subtabs = $this->dic->tabs()->sub_target; // this only works because subtarget is currently public...
165  if (count($subtabs) > 1) { // we only need to do something if there are more than one subtabs
166  $active_subtab = array_values(
167  array_filter($subtabs, static function (array $subtab): bool {
168  return $subtab['activate'] ?? false;
169  })
170  )[0]['id'] ?? '';
171 
172  if ($active_subtab === '' && isset($subtabs[0])) {
173  $active_subtab = $subtabs[0]['id']; // if no tab is active, use the first one
174  }
175  $subtab_title = $tab_looper($subtabs, $active_subtab);
176  }
177 
178  return $subtab_title . $tab_title;
179  }
180 
181 
182  public function getFooterModification(CalledContexts $screen_context_stack): ?FooterModification
183  {
184  return $this->globalScreen()->layout()->factory()->footer()->withModification(function (?Footer $footer): ?Footer {
185  $f = $this->dic->ui()->factory();
186 
187  $links = [];
188  // ILIAS Version and Text
189  $ilias_version = ILIAS_VERSION;
190  $text = "powered by ILIAS (v{$ilias_version})";
191 
192  // Imprint
193  $base_class = ($this->dic->http()->wrapper()->query()->has(\ilCtrlInterface::PARAM_BASE_CLASS)) ?
194  $this->dic->http()->wrapper()->query()->retrieve(
196  $this->dic->refinery()->kindlyTo()->string()
197  ) : null;
198 
199  if ($base_class !== \ilImprintGUI::class && \ilImprint::isActive()) {
200  $imprint_title = $this->dic->language()->txt("imprint");
201  $imprint_url = \ilLink::_getStaticLink(0, "impr");
202  $links[] = $f->link()->standard($imprint_title, $imprint_url);
203  }
204 
205  // system support contacts
206  if (($system_support_url = \ilSystemSupportContactsGUI::getFooterLink()) !== '') {
207  $system_support_title = \ilSystemSupportContactsGUI::getFooterText();
208  $links[] = $f->link()->standard($system_support_title, $system_support_url);
209  }
210 
211  // output translation link
213  $translation_url = \ilObjLanguageAccess::_getTranslationLink();
214  $translation_title = $this->dic->language()->txt('translation');
215  $links[] = $f->link()->standard($translation_title, $translation_url)->withOpenInNewViewport(true);
216  }
217 
218  // accessibility control concept
219  if (($accessibility_control_url = \ilAccessibilityControlConceptGUI::getFooterLink()) !== '') {
220  $accessibility_control_title = \ilAccessibilityControlConceptGUI::getFooterText();
221  $links[] = $f->link()->standard($accessibility_control_title, $accessibility_control_url);
222  }
223 
224  // report accessibility issue
225  if (($accessibility_report_url = \ilAccessibilitySupportContactsGUI::getFooterLink()) !== '') {
226  $accessibility_report_title = \ilAccessibilitySupportContactsGUI::getFooterText();
227  $links[] = $f->link()->standard($accessibility_report_title, $accessibility_report_url);
228  }
229 
230  $footer = $f->mainControls()->footer($links, $text);
231 
232  $tosWithdrawalGui = new \ilTermsOfServiceWithdrawalGUIHelper($this->dic->user());
233  $footer = $tosWithdrawalGui->modifyFooter($footer);
234 
235  if (self::$perma_link !== "") {
236  $footer = $footer->withPermanentURL(new URI(self::$perma_link));
237  }
238 
239  return $footer;
240  });
241  }
242 }
const ILIAS_VERSION
static setViewTitle(string $view_title)
static _isPageTranslation()
Check if the current request is a page translation.
getFooterModification(CalledContexts $screen_context_stack)
getContentModification(CalledContexts $screen_context_stack)
static _getTranslationLink()
Get the link to translate the current page.
buildTabTitle()
This method was introduced due to A11y problems, see https://mantis.ilias.de/view.php?id=31534.
The scope of this class is split ilias-conform URI&#39;s into components.
Definition: URI.php:34
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static setContent(string $content)
static setShortTitle(string $short_title)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static setPermaLink(string $perma_link)
This describes the Footer.
Definition: Footer.php:32
static _checkTranslate()
Permission check for translations.
static isActive()