TYPO3  7.6
LinkButton.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\Template\Components\Buttons;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
35 class LinkButton extends AbstractButton implements ButtonInterface
36 {
42  protected $href = '';
43 
49  public function getHref()
50  {
51  return $this->href;
52  }
53 
61  public function setHref($href)
62  {
63  $this->href = $href;
64  return $this;
65  }
66 
72  public function isValid()
73  {
74  if (
75  trim($this->getHref()) !== ''
76  && trim($this->getTitle()) !== ''
77  && $this->getType() === LinkButton::class
78  && $this->getIcon() !== null
79  ) {
80  return true;
81  }
82  return false;
83  }
84 
90  public function render()
91  {
92  $attributes = array(
93  'href' => $this->getHref(),
94  'class' => 'btn btn-default btn-sm ' . $this->getClasses(),
95  'title' => $this->getTitle()
96  );
97  $labelText = '';
98  if ($this->showLabelText) {
99  $labelText = ' ' . $this->title;
100  }
101  foreach ($this->dataAttributes as $attributeName => $attributeValue) {
102  $attributes['data-' . htmlspecialchars($attributeName)] = $attributeValue;
103  }
104  if ($this->onClick !== '') {
105  $attributes['onclick'] = $this->onClick;
106  }
107  $attributesString = '';
108  foreach ($attributes as $key => $value) {
109  $attributesString .= ' ' . htmlspecialchars($key) . '="' . htmlspecialchars($value) . '"';
110  }
111 
112  return '<a ' . $attributesString . '>'
113  . $this->getIcon()->render() . htmlspecialchars($labelText)
114  . '</a>';
115  }
116 
122  public function __toString()
123  {
124  return $this->render();
125  }
126 }