[TASK] Remove ext:dbal from installation steps
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Template / Components / Buttons / FullyRenderedButton.php
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
17 /**
18 * FullyRenderedButton
19 *
20 * This button type is an intermediate solution for buttons that are rendered
21 * by methods from TYPO3 itself, like the CSH buttons or Bookmark buttons.
22 *
23 * There should be no need to use them, so do yourself a favour and don't.
24 *
25 * EXAMPLE USAGE TO ADD A BUTTON TO THE FIRST BUTTON GROUP IN THE LEFT BAR:
26 *
27 * $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
28 * $myButton = $buttonBar->makeFullyRenderedButton()
29 * ->setHtmlSource('<span class="i-should-not-be-using-this>Foo</span>');
30 * $buttonBar->addButton($myButton, ButtonBar::BUTTON_POSITION_LEFT, 1);
31 */
32 class FullyRenderedButton implements ButtonInterface
33 {
34 /**
35 * The full HTML source of the rendered button.
36 * This source will be passed through to the frontend as is,
37 * so keep htmlspecialchars() in mind
38 *
39 * @var string
40 */
41 protected $htmlSource = '';
42
43 /**
44 * Gets the HTML Source of the button
45 *
46 * @return string
47 */
48 public function getHtmlSource()
49 {
50 return $this->htmlSource;
51 }
52
53 /**
54 * Sets the HTML Source of the button and returns itself
55 *
56 * @param string $htmlSource HTML sourcecode of the button
57 *
58 * @return FullyRenderedButton
59 */
60 public function setHtmlSource($htmlSource)
61 {
62 $this->htmlSource = $htmlSource;
63 return $this;
64 }
65
66 /**
67 * Gets the type of the button
68 *
69 * @return string
70 */
71 public function getType()
72 {
73 return get_class($this);
74 }
75
76 /**
77 * Validator for a FullyRenderedButton
78 *
79 * @return bool
80 */
81 public function isValid()
82 {
83 if (
84 trim($this->getHtmlSource()) !== ''
85 && $this->getType() === FullyRenderedButton::class
86 ) {
87 return true;
88 }
89 return false;
90 }
91
92 /**
93 * Renders the button
94 *
95 * @return string
96 */
97 public function __toString()
98 {
99 return $this->render();
100 }
101
102 /**
103 * Renders the button
104 *
105 * @return string
106 */
107 public function render()
108 {
109 return '<span class="btn btn-sm btn-default">' . $this->getHtmlSource() . '</span>';
110 }
111 }