ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilLinkButton.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once "Services/UIComponent/Button/classes/class.ilButtonBase.php";
5
14{
15 protected $url; // [string]
16 protected $target; // [string]
17
18 public static function getInstance()
19 {
20 return new self(self::TYPE_LINK);
21 }
22
23
24 //
25 // properties
26 //
27
33 public function setUrl($a_value)
34 {
35 $this->url = trim($a_value);
36 }
37
43 public function getUrl()
44 {
45 return $this->url;
46 }
47
53 public function setTarget($a_value)
54 {
55 $this->target = trim($a_value);
56 }
57
63 public function getTarget()
64 {
65 return $this->target;
66 }
67
68
69 //
70 // render
71 //
72
78 protected function renderCaption()
79 {
80 return '&nbsp;' . $this->getCaption() . '&nbsp;';
81 }
82
86 protected function renderAttributes(array $a_additional_attr = null)
87 {
88 if ('_blank' === $this->getTarget()) {
89 $relAttrVal = 'noopener';
90
91 if (isset($a_additional_attr['rel'])) {
92 if (strpos($a_additional_attr['rel'], $relAttrVal) === false) {
93 $a_additional_attr['rel'] .= ' ' . $relAttrVal;
94 }
95 } else {
96 $a_additional_attr['rel'] = $relAttrVal;
97 }
98 }
99
100 return parent::renderAttributes($a_additional_attr);
101 }
102
103 public function render()
104 {
105 $this->prepareRender();
106
107 $attr = array();
108 $attr["href"] = $this->getUrl() ? $this->getUrl() : "#";
109 $attr["target"] = $this->getTarget();
110
111 return '<a' . $this->renderAttributes($attr) . '>' .
112 $this->renderCaption() . '</a>';
113 }
114}
An exception for terminatinating execution or to throw for unit testing.
prepareRender()
Prepare render.
getCaption($a_translate=true)
Get caption.
getTarget()
Get target.
setTarget($a_value)
Set target.
renderCaption()
Prepare caption for render.
render()
Render HTML.
setUrl($a_value)
Set URL.
static getInstance()
Factory.
renderAttributes(array $a_additional_attr=null)
Render current HTML attributes.string