ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.LinkAdapterGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24
29{
30 protected const TYPE_STD = 0;
31 protected const TYPE_EMPH = 1;
32 protected const TYPE_PRIM = 2;
33 protected \ilToolbarGUI $toolbar;
34 protected \ILIAS\DI\UIServices $ui;
35 protected string $caption = "";
36 protected string $href = "";
37 protected bool $new_viewport = false;
38 protected int $type = self::TYPE_STD;
39
40 public function __construct(
41 string $caption,
42 string $href,
43 bool $new_viewport = false
44 ) {
45 global $DIC;
46
47 $this->caption = $caption;
48 $this->href = $href;
49 $this->new_viewport = $new_viewport;
50 $this->ui = $DIC->ui();
51 $this->toolbar = $DIC->toolbar();
52 }
53
54 public function emphasised(): self
55 {
56 $this->type = self::TYPE_EMPH;
57 return $this;
58 }
59
60 public function primary(): self
61 {
62 $this->type = self::TYPE_PRIM;
63 return $this;
64 }
65
66 protected function getStandardLink(): \ILIAS\UI\Component\Link\Link
67 {
68 $link = $this->ui->factory()->link()->standard(
69 $this->caption,
70 $this->href
71 );
72 if ($this->new_viewport) {
73 $link = $link->withOpenInNewViewport(true);
74 }
75 return $link;
76 }
77
78 protected function getLink(): \ILIAS\UI\Component\Link\Link
79 {
80 return $this->getStandardLink();
81 }
82
83 public function toToolbar(bool $sticky = false, ?\ilToolbarGUI $toolbar = null): void
84 {
85 $link = $this->getLink();
86 if (is_null($toolbar)) {
88 }
89 if ($sticky) {
90 $toolbar->addStickyItem($link);
91 } else {
92 $toolbar->addComponent($link);
93 }
94 }
95
96 public function render(): string
97 {
98 return $this->ui->renderer()->render($this->getLink());
99 }
100}
Definition: UI.php:24
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addComponent(\ILIAS\UI\Component\Component $a_comp)
addStickyItem( $a_item, bool $a_output_label=false)
Add a sticky item.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26