‪TYPO3CMS  10.4
ButtonBar.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
27 
32 {
36  const ‪BUTTON_POSITION_LEFT = 'left';
37 
41  const ‪BUTTON_POSITION_RIGHT = 'right';
42 
48  protected ‪$buttons = [];
49 
61  public function ‪addButton(
62  ‪ButtonInterface $button,
63  $buttonPosition = self::BUTTON_POSITION_LEFT,
64  $buttonGroup = 1
65  ) {
66  if (!$button->‪isValid()) {
67  throw new \InvalidArgumentException('Button "' . $button->‪getType() . '" is not valid', 1441706370);
68  }
69  // Determine the default button position
70  if ($button instanceof ‪PositionInterface) {
71  $buttonPosition = $button->getPosition();
72  $buttonGroup = $button->getGroup();
73  }
74  // We make the button immutable here
75  $this->buttons[$buttonPosition][$buttonGroup][] = clone $button;
76  return $this;
77  }
78 
89  public function ‪makeButton($button)
90  {
91  if (!in_array(ButtonInterface::class, class_implements($button), true)) {
92  throw new \InvalidArgumentException('A Button must implement ButtonInterface', 1441706378);
93  }
94  return GeneralUtility::makeInstance($button);
95  }
96 
102  public function ‪makeInputButton()
103  {
104  return GeneralUtility::makeInstance(InputButton::class);
105  }
106 
112  public function ‪makeSplitButton()
113  {
114  return GeneralUtility::makeInstance(SplitButton::class);
115  }
116 
122  public function ‪makeLinkButton()
123  {
124  return GeneralUtility::makeInstance(LinkButton::class);
125  }
126 
132  public function ‪makeFullyRenderedButton()
133  {
134  return GeneralUtility::makeInstance(FullyRenderedButton::class);
135  }
136 
142  public function ‪makeShortcutButton()
143  {
144  return GeneralUtility::makeInstance(ShortcutButton::class);
145  }
146 
152  public function ‪makeHelpButton()
153  {
154  return GeneralUtility::makeInstance(HelpButton::class);
155  }
156 
163  public function ‪getButtons()
164  {
165  // here we need to call the sorting methods and stuff.
166  foreach ($this->buttons as $position => $_) {
167  ksort($this->buttons[$position]);
168  }
169  // Hook for manipulating the docHeaderButtons
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  return ‪$this->buttons;
177  }
178 }
‪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:36
‪TYPO3\CMS\Backend\Template\Components\ButtonBar
Definition: ButtonBar.php:32
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\makeSplitButton
‪SplitButton makeSplitButton()
Definition: ButtonBar.php:111
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\makeInputButton
‪InputButton makeInputButton()
Definition: ButtonBar.php:101
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\addButton
‪$this addButton(ButtonInterface $button, $buttonPosition=self::BUTTON_POSITION_LEFT, $buttonGroup=1)
Definition: ButtonBar.php:60
‪TYPO3\CMS\Backend\Template\Components\Buttons\PositionInterface
Definition: PositionInterface.php:22
‪TYPO3\CMS\Backend\Template\Components\Buttons\ButtonInterface\getType
‪string getType()
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\ShortcutButton
Definition: ShortcutButton.php:40
‪TYPO3\CMS\Backend\Template\Components\Buttons\SplitButton
Definition: SplitButton.php:52
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\makeLinkButton
‪LinkButton makeLinkButton()
Definition: ButtonBar.php:121
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\makeButton
‪ButtonInterface makeButton($button)
Definition: ButtonBar.php:88
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\makeHelpButton
‪HelpButton makeHelpButton()
Definition: ButtonBar.php:151
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\$buttons
‪array $buttons
Definition: ButtonBar.php:47
‪TYPO3\CMS\Backend\Template\Components\Buttons\Action\HelpButton
Definition: HelpButton.php:38
‪TYPO3\CMS\Backend\Template\Components\Buttons\InputButton
Definition: InputButton.php:38
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Template\Components
Definition: AbstractControl.php:16
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\Template\Components\Buttons\FullyRenderedButton
Definition: FullyRenderedButton.php:34
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\BUTTON_POSITION_RIGHT
‪const BUTTON_POSITION_RIGHT
Definition: ButtonBar.php:41
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\makeFullyRenderedButton
‪FullyRenderedButton makeFullyRenderedButton()
Definition: ButtonBar.php:131
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\makeShortcutButton
‪ShortcutButton makeShortcutButton()
Definition: ButtonBar.php:141
‪TYPO3\CMS\Backend\Template\Components\Buttons\ButtonInterface
Definition: ButtonInterface.php:22
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\getButtons
‪array getButtons()
Definition: ButtonBar.php:162