‪TYPO3CMS  ‪main
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 
19 
39 {
45  protected ‪$href = '';
46 
52  public function ‪getHref()
53  {
54  return ‪$this->href;
55  }
56 
64  public function ‪setHref(‪$href)
65  {
66  $this->href = ‪$href;
67  return $this;
68  }
69 
75  public function ‪isValid()
76  {
77  if (
78  trim($this->‪getHref()) !== ''
79  && trim($this->‪getTitle()) !== ''
80  && $this->‪getType() === self::class
81  && $this->‪getIcon() !== null
82  ) {
83  return true;
84  }
85  return false;
86  }
87 
93  public function ‪render()
94  {
95  $attributes = [
96  'href' => $this->‪getHref(),
97  'class' => 'btn btn-sm btn-default ' . $this->‪getClasses(),
98  'title' => $this->‪getTitle(),
99  ];
100  $labelText = '';
101  if ($this->showLabelText) {
102  $labelText = ' ' . ‪$this->title;
103  }
104  foreach ($this->dataAttributes as $attributeName => $attributeValue) {
105  $attributes['data-' . $attributeName] = $attributeValue;
106  }
107  if ($this->‪isDisabled()) {
108  $attributes['disabled'] = 'disabled';
109  $attributes['class'] .= ' disabled';
110  }
111  $attributesString = GeneralUtility::implodeAttributes($attributes, true);
112 
113  return '<a ' . $attributesString . '>'
114  . $this->‪getIcon()->‪render() . htmlspecialchars($labelText)
115  . '</a>';
116  }
117 
121  public function ‪__toString(): string
122  {
123  return $this->‪render();
124  }
125 }
‪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
‪render(?string $alternativeMarkupIdentifier=null)
Definition: Icon.php:237
‪TYPO3\CMS\Backend\Template\Components\Buttons\AbstractButton
Definition: AbstractButton.php:25
‪TYPO3\CMS\Backend\Template\Components\AbstractControl\getClasses
‪string getClasses()
Definition: AbstractControl.php:47
‪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:57
‪TYPO3\CMS\Backend\Template\Components\Buttons
Definition: AbstractButton.php:16
‪TYPO3\CMS\Backend\Template\Components\Buttons\AbstractButton\isDisabled
‪isDisabled()
Definition: AbstractButton.php:103
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52