ILIAS  trunk Revision v11.0_alpha-1769-g99a433fe2dc
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.LinkAdapterGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(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)) {
87  $toolbar = $this->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 }
Interface Observer Contains several chained tasks and infos about them.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
global $DIC
Definition: shib_login.php:22
addStickyItem( $a_item, bool $a_output_label=false)
Add a sticky item.