TYPO3  7.6
InputButton.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 
36 class InputButton extends AbstractButton implements ButtonInterface
37 {
43  protected $name = '';
44 
50  protected $value = '';
51 
57  protected $form = '';
58 
64  public function getName()
65  {
66  return $this->name;
67  }
68 
76  public function setName($name)
77  {
78  $this->name = $name;
79  return $this;
80  }
81 
87  public function getValue()
88  {
89  return $this->value;
90  }
91 
99  public function setValue($value)
100  {
101  $this->value = $value;
102  return $this;
103  }
104 
108  public function getForm()
109  {
110  return $this->form;
111  }
112 
118  public function setForm($form)
119  {
120  $this->form = $form;
121  return $this;
122  }
123 
129  public function isValid()
130  {
131  if (
132  trim($this->getName()) !== ''
133  && trim($this->getValue()) !== ''
134  && trim($this->getTitle()) !== ''
135  && $this->getType() === InputButton::class
136  && $this->getIcon() !== null
137  ) {
138  return true;
139  }
140  return false;
141  }
142 
148  public function render()
149  {
150  $attributes = array(
151  'name' => $this->getName(),
152  'class' => 'btn btn-default btn-sm ' . $this->getClasses(),
153  'value' => $this->getValue(),
154  'title' => $this->getTitle(),
155  'form' => trim($this->getForm())
156  );
157  $labelText = '';
158  if ($this->showLabelText) {
159  $labelText = ' ' . $this->title;
160  }
161  foreach ($this->dataAttributes as $attributeName => $attributeValue) {
162  $attributes['data-' . htmlspecialchars($attributeName)] = $attributeValue;
163  }
164  $attributesString = '';
165  foreach ($attributes as $key => $value) {
166  if ($value !== '') {
167  $attributesString .= ' ' . htmlspecialchars($key) . '="' . htmlspecialchars($value) . '"';
168  }
169  }
170  return '<button' . $attributesString . '>'
171  . $this->getIcon()->render() . htmlspecialchars($labelText)
172  . '</button>';
173  }
174 
180  public function __toString()
181  {
182  return $this->render();
183  }
184 }