‪TYPO3CMS  9.5
LinkButton.php
Go to the documentation of this file.
1 <?php
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 
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() === self::class
78  && $this->‪getIcon() !== null
79  ) {
80  return true;
81  }
82  return false;
83  }
84 
90  public function ‪render()
91  {
92  $attributes = [
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-' . $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 }
‪TYPO3\CMS\Backend\Template\Components\Buttons\AbstractButton\getType
‪string getType()
Definition: AbstractButton.php:81
‪TYPO3\CMS\Backend\Template\Components\Buttons\AbstractButton\getIcon
‪Icon getIcon()
Definition: AbstractButton.php:71
‪TYPO3\CMS\Core\Imaging\Icon\render
‪string render($alternativeMarkupIdentifier=null)
Definition: Icon.php:231
‪TYPO3\CMS\Backend\Template\Components\AbstractControl\$onClick
‪string $onClick
Definition: AbstractControl.php:46
‪TYPO3\CMS\Backend\Template\Components\Buttons\AbstractButton
Definition: AbstractButton.php:24
‪TYPO3\CMS\Backend\Template\Components\AbstractControl\getClasses
‪string getClasses()
Definition: AbstractControl.php:53
‪TYPO3\CMS\Backend\Template\Components\AbstractControl\$title
‪string $title
Definition: AbstractControl.php:32
‪TYPO3\CMS\Backend\Template\Components\AbstractControl\getTitle
‪string getTitle()
Definition: AbstractControl.php:63
‪TYPO3\CMS\Backend\Template\Components\Buttons
Definition: AbstractButton.php:2