TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
ButtonBar.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\Template\Components;
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 
26 
30 class ButtonBar
31 {
35  const BUTTON_POSITION_LEFT = 'left';
36 
40  const BUTTON_POSITION_RIGHT = 'right';
41 
47  protected $buttons = [];
48 
60  public function addButton(
61  ButtonInterface $button,
62  $buttonPosition = self::BUTTON_POSITION_LEFT,
63  $buttonGroup = 1
64  ) {
65  if (!$button->isValid()) {
66  throw new \InvalidArgumentException('Button "' . $button->getType() . '" is not valid', 1441706370);
67  }
68  // Determine the default button position
69  if ($button instanceof PositionInterface) {
70  $buttonPosition = $button->getPosition();
71  $buttonGroup = $button->getGroup();
72  }
73  // We make the button immutable here
74  $this->buttons[$buttonPosition][$buttonGroup][] = clone $button;
75  return $this;
76  }
77 
88  public function makeButton($button)
89  {
90  if (!in_array(ButtonInterface::class, class_implements($button), true)) {
91  throw new \InvalidArgumentException('A Button must implement ButtonInterface', 1441706378);
92  }
93  return GeneralUtility::makeInstance($button);
94  }
95 
101  public function makeInputButton()
102  {
103  return GeneralUtility::makeInstance(InputButton::class);
104  }
105 
111  public function makeSplitButton()
112  {
113  return GeneralUtility::makeInstance(SplitButton::class);
114  }
115 
121  public function makeLinkButton()
122  {
123  return GeneralUtility::makeInstance(LinkButton::class);
124  }
125 
131  public function makeFullyRenderedButton()
132  {
133  return GeneralUtility::makeInstance(FullyRenderedButton::class);
134  }
135 
141  public function makeShortcutButton()
142  {
143  return GeneralUtility::makeInstance(ShortcutButton::class);
144  }
145 
151  public function makeHelpButton()
152  {
153  return GeneralUtility::makeInstance(HelpButton::class);
154  }
155 
162  public function getButtons()
163  {
164  // here we need to call the sorting methods and stuff.
165  foreach ($this->buttons as $position => $_) {
166  ksort($this->buttons[$position]);
167  }
168  // Hook for manipulating the docHeaderButtons
169  if (!empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['Backend\Template\Components\ButtonBar']['getButtonsHook'])) {
170  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['Backend\Template\Components\ButtonBar']['getButtonsHook'] as $funcRef) {
171  $params = [
172  'buttons' => $this->buttons
173  ];
174  $this->buttons = GeneralUtility::callUserFunction($funcRef, $params, $this);
175  }
176  }
177  return $this->buttons;
178  }
179 }
addButton(ButtonInterface $button, $buttonPosition=self::BUTTON_POSITION_LEFT, $buttonGroup=1)
Definition: ButtonBar.php:60
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static makeInstance($className,...$constructorArguments)
static callUserFunction($funcName, &$params, &$ref, $_= '', $errorMode=0)