‪TYPO3CMS  10.4
LinkButton.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
37 {
43  protected ‪$href = '';
44 
50  public function ‪getHref()
51  {
52  return ‪$this->href;
53  }
54 
62  public function ‪setHref(‪$href)
63  {
64  $this->href = ‪$href;
65  return $this;
66  }
67 
73  public function ‪isValid()
74  {
75  if (
76  trim($this->‪getHref()) !== ''
77  && trim($this->‪getTitle()) !== ''
78  && $this->‪getType() === self::class
79  && $this->‪getIcon() !== null
80  ) {
81  return true;
82  }
83  return false;
84  }
85 
91  public function ‪render()
92  {
93  $attributes = [
94  'href' => $this->‪getHref(),
95  'class' => 'btn btn-default btn-sm ' . $this->‪getClasses(),
96  'title' => $this->‪getTitle()
97  ];
98  $labelText = '';
99  if ($this->showLabelText) {
100  $labelText = ' ' . ‪$this->title;
101  }
102  foreach ($this->dataAttributes as $attributeName => $attributeValue) {
103  $attributes['data-' . $attributeName] = $attributeValue;
104  }
105  if ($this->onClick !== '') {
106  $attributes['onclick'] = ‪$this->onClick;
107  }
108  if ($this->‪isDisabled()) {
109  $attributes['disabled'] = 'disabled';
110  $attributes['class'] .= ' disabled';
111  }
112  $attributesString = '';
113  foreach ($attributes as $key => $value) {
114  $attributesString .= ' ' . htmlspecialchars($key) . '="' . htmlspecialchars($value) . '"';
115  }
116 
117  return '<a ' . $attributesString . '>'
118  . $this->‪getIcon()->‪render() . htmlspecialchars($labelText)
119  . '</a>';
120  }
121 
127  public function ‪__toString()
128  {
129  return $this->‪render();
130  }
131 }
‪TYPO3\CMS\Backend\Template\Components\Buttons\AbstractButton\getType
‪string getType()
Definition: AbstractButton.php:82
‪TYPO3\CMS\Backend\Template\Components\Buttons\AbstractButton\getIcon
‪Icon getIcon()
Definition: AbstractButton.php:72
‪TYPO3\CMS\Core\Imaging\Icon\render
‪string render($alternativeMarkupIdentifier=null)
Definition: Icon.php:232
‪TYPO3\CMS\Backend\Template\Components\AbstractControl\$onClick
‪string $onClick
Definition: AbstractControl.php:47
‪TYPO3\CMS\Backend\Template\Components\Buttons\AbstractButton
Definition: AbstractButton.php:25
‪TYPO3\CMS\Backend\Template\Components\AbstractControl\getClasses
‪string getClasses()
Definition: AbstractControl.php:54
‪TYPO3\CMS\Backend\Template\Components\Buttons\AbstractButton\isDisabled
‪bool isDisabled()
Definition: AbstractButton.php:105
‪TYPO3\CMS\Backend\Template\Components\AbstractControl\$title
‪string $title
Definition: AbstractControl.php:33
‪TYPO3\CMS\Backend\Template\Components\AbstractControl\getTitle
‪string getTitle()
Definition: AbstractControl.php:64
‪TYPO3\CMS\Backend\Template\Components\Buttons
Definition: AbstractButton.php:16