[TASK] Integrate DocHeader action buttons
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Template / Components / Buttons / Action / HelpButton.php
1 <?php
2 namespace TYPO3\CMS\Backend\Template\Components\Buttons\Action;
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 use TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Backend\Template\Components\ButtonBar;
19 use TYPO3\CMS\Backend\Template\Components\Buttons\ButtonInterface;
20 use TYPO3\CMS\Backend\Template\Components\Buttons\PositionInterface;
21
22 /**
23 * HelpButton
24 *
25 * Renders a help button in the DocHeader which will be rendered
26 * to the right position using button group "99".
27 *
28 * EXAMPLE USAGE TO ADD A HELP BUTTON:
29 *
30 * $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
31 * $myButton = $buttonBar->makeHelpButton()
32 * ->setModuleName('xMOD_csh_corebe')
33 * ->setFieldName('list_module');
34 * $buttonBar->addButton($myButton);
35 */
36 class HelpButton implements ButtonInterface, PositionInterface
37 {
38 /**
39 * @var string
40 */
41 protected $moduleName;
42
43 /**
44 * @var string
45 */
46 protected $fieldName;
47
48 /**
49 * Gets the name of the module.
50 *
51 * @return string
52 */
53 public function getModuleName()
54 {
55 return $this->moduleName;
56 }
57
58 /**
59 * Sets the name of the module.
60 *
61 * @param string $moduleName
62 * @return HelpButton
63 */
64 public function setModuleName($moduleName)
65 {
66 $this->moduleName = $moduleName;
67 return $this;
68 }
69
70 /**
71 * Gets the name of the field.
72 *
73 * @return string
74 */
75 public function getFieldName()
76 {
77 return $this->fieldName;
78 }
79
80 /**
81 * Sets the name of the field.
82 *
83 * @param string $fieldName
84 * @return HelpButton
85 */
86 public function setFieldName($fieldName)
87 {
88 $this->fieldName = $fieldName;
89 return $this;
90 }
91
92 /**
93 * Gets the button position.
94 *
95 * @return string
96 */
97 public function getPosition()
98 {
99 return ButtonBar::BUTTON_POSITION_RIGHT;
100 }
101
102 /**
103 * Gets the button group.
104 *
105 * @return int
106 */
107 public function getGroup()
108 {
109 return 99;
110 }
111
112 /**
113 * Gets the type of the button
114 *
115 * @return string
116 */
117 public function getType()
118 {
119 return get_class($this);
120 }
121
122 /**
123 * Determines whether the button shall be rendered.
124 * Depends on the defined module and field name.
125 *
126 * @return bool
127 */
128 public function isValid()
129 {
130 return (
131 !empty($this->moduleName)
132 && !empty($this->fieldName)
133 );
134 }
135
136 /**
137 * Renders the button
138 *
139 * @return string
140 */
141 public function __toString()
142 {
143 return $this->render();
144 }
145
146 /**
147 * Renders the button
148 *
149 * @return string
150 */
151 public function render()
152 {
153 $helpMarkup = BackendUtility::cshItem($this->moduleName, $this->fieldName);
154 return '<span class="btn btn-sm btn-default">' . $helpMarkup . '</span>';
155 }
156 }