ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLinkButton.php
Go to the documentation of this file.
1<?php
2
26{
27 protected string $url = "";
28 protected string $target = "";
29
30 public static function getInstance(): self
31 {
32 return new self(self::TYPE_LINK);
33 }
34
35
36 //
37 // properties
38 //
39
40 public function setUrl(string $a_value): void
41 {
42 $this->url = trim($a_value);
43 }
44
45 public function getUrl(): string
46 {
47 return $this->url;
48 }
49
50 public function setTarget(string $a_value): void
51 {
52 $this->target = trim($a_value);
53 }
54
55 public function getTarget(): string
56 {
57 return $this->target;
58 }
59
60
61 //
62 // render
63 //
64
65 protected function renderCaption(): string
66 {
67 return '&nbsp;' . $this->getCaption() . '&nbsp;';
68 }
69
70 protected function renderAttributes(?array $a_additional_attr = null): string
71 {
72 if ('_blank' === $this->getTarget()) {
73 $relAttrVal = 'noopener';
74
75 if (isset($a_additional_attr['rel'])) {
76 if (strpos($a_additional_attr['rel'], $relAttrVal) === false) {
77 $a_additional_attr['rel'] .= ' ' . $relAttrVal;
78 }
79 } else {
80 $a_additional_attr['rel'] = $relAttrVal;
81 }
82 }
83
84 return parent::renderAttributes($a_additional_attr);
85 }
86
87 public function render(): string
88 {
89 $this->prepareRender();
90
91 $attr = array();
92 $attr["href"] = $this->getUrl() ?: "#";
93 $attr["target"] = $this->getTarget();
94
95 return '<a' . $this->renderAttributes($attr) . '>' .
96 $this->renderCaption() . '</a>';
97 }
98}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getCaption(bool $a_translate=true)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
renderAttributes(?array $a_additional_attr=null)
Render current HTML attributes.
setTarget(string $a_value)
setUrl(string $a_value)