‪TYPO3CMS  9.5
ButtonBar.php
Go to the documentation of this file.
1 <?php
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 
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  foreach (‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['Backend\Template\Components\ButtonBar']['getButtonsHook'] ?? [] as $funcRef) {
170  $params = [
171  'buttons' => ‪$this->buttons
172  ];
173  $this->buttons = GeneralUtility::callUserFunction($funcRef, $params, $this);
174  }
175  return ‪$this->buttons;
176  }
177 }
‪TYPO3\CMS\Backend\Template\Components\Buttons\ButtonInterface\isValid
‪bool isValid()
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\BUTTON_POSITION_LEFT
‪const BUTTON_POSITION_LEFT
Definition: ButtonBar.php:35
‪TYPO3\CMS\Backend\Template\Components\ButtonBar
Definition: ButtonBar.php:31
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\makeSplitButton
‪SplitButton makeSplitButton()
Definition: ButtonBar.php:110
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\makeInputButton
‪InputButton makeInputButton()
Definition: ButtonBar.php:100
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\addButton
‪$this addButton(ButtonInterface $button, $buttonPosition=self::BUTTON_POSITION_LEFT, $buttonGroup=1)
Definition: ButtonBar.php:59
‪TYPO3\CMS\Backend\Template\Components\Buttons\PositionInterface
Definition: PositionInterface.php:21
‪TYPO3\CMS\Backend\Template\Components\Buttons\ButtonInterface\getType
‪string getType()
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton
Definition: ShortcutButton.php:39
‪TYPO3\CMS\Backend\Template\Components\Buttons\SplitButton
Definition: SplitButton.php:51
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\makeLinkButton
‪LinkButton makeLinkButton()
Definition: ButtonBar.php:120
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\makeButton
‪ButtonInterface makeButton($button)
Definition: ButtonBar.php:87
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\makeHelpButton
‪HelpButton makeHelpButton()
Definition: ButtonBar.php:150
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\$buttons
‪array $buttons
Definition: ButtonBar.php:46
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\HelpButton
Definition: HelpButton.php:37
‪TYPO3\CMS\Backend\Template\Components\Buttons\InputButton
Definition: InputButton.php:37
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Template\Components
Definition: AbstractControl.php:2
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Backend\Template\Components\Buttons\FullyRenderedButton
Definition: FullyRenderedButton.php:33
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\BUTTON_POSITION_RIGHT
‪const BUTTON_POSITION_RIGHT
Definition: ButtonBar.php:40
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\makeFullyRenderedButton
‪FullyRenderedButton makeFullyRenderedButton()
Definition: ButtonBar.php:130
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\makeShortcutButton
‪ShortcutButton makeShortcutButton()
Definition: ButtonBar.php:140
‪TYPO3\CMS\Backend\Template\Components\Buttons\ButtonInterface
Definition: ButtonInterface.php:21
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\getButtons
‪array getButtons()
Definition: ButtonBar.php:161