‪TYPO3CMS  ‪main
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 
18 use Psr\EventDispatcher\EventDispatcherInterface;
28 
33 {
37  public const ‪BUTTON_POSITION_LEFT = 'left';
38 
42  public const ‪BUTTON_POSITION_RIGHT = 'right';
43 
49  protected ‪$buttons = [];
50 
62  public function ‪addButton(
63  ‪ButtonInterface $button,
64  $buttonPosition = self::BUTTON_POSITION_LEFT,
65  $buttonGroup = 1
66  ) {
67  if (!$button->‪isValid()) {
68  throw new \InvalidArgumentException('Button "' . $button->‪getType() . '" is not valid', 1441706370);
69  }
70  // Determine the default button position
71  if ($button instanceof ‪PositionInterface) {
72  $buttonPosition = $button->getPosition();
73  $buttonGroup = $button->getGroup();
74  }
75  // We make the button immutable here
76  $this->buttons[$buttonPosition][$buttonGroup][] = clone $button;
77  return $this;
78  }
79 
90  public function ‪makeButton($button)
91  {
92  if (!in_array(ButtonInterface::class, class_implements($button) ?: [], true)) {
93  throw new \InvalidArgumentException('A Button must implement ButtonInterface', 1441706378);
94  }
95  return GeneralUtility::makeInstance($button);
96  }
97 
103  public function ‪makeInputButton()
104  {
105  return GeneralUtility::makeInstance(InputButton::class);
106  }
107 
113  public function ‪makeSplitButton()
114  {
115  return GeneralUtility::makeInstance(SplitButton::class);
116  }
117 
123  public function ‪makeDropDownButton()
124  {
125  return GeneralUtility::makeInstance(DropDownButton::class);
126  }
127 
133  public function ‪makeLinkButton()
134  {
135  return GeneralUtility::makeInstance(LinkButton::class);
136  }
137 
143  public function ‪makeFullyRenderedButton()
144  {
145  return GeneralUtility::makeInstance(FullyRenderedButton::class);
146  }
147 
153  public function ‪makeShortcutButton()
154  {
155  return GeneralUtility::makeInstance(ShortcutButton::class);
156  }
157 
162  public function ‪getButtons(): array
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 
169  // Dispatch event for manipulating the docHeaderButtons
170  $this->buttons = GeneralUtility::makeInstance(EventDispatcherInterface::class)->dispatch(
171  new ModifyButtonBarEvent($this->buttons, $this)
172  )->getButtons();
173 
174  return ‪$this->buttons;
175  }
176 }
‪TYPO3\CMS\Backend\Template\Components\ModifyButtonBarEvent
Definition: ModifyButtonBarEvent.php:26
‪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:37
‪TYPO3\CMS\Backend\Template\Components\ButtonBar
Definition: ButtonBar.php:33
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\makeDropDownButton
‪DropDownButton makeDropDownButton()
Definition: ButtonBar.php:122
‪TYPO3\CMS\Backend\Template\Components\Buttons\DropDownButton
Definition: DropDownButton.php:48
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\makeSplitButton
‪SplitButton makeSplitButton()
Definition: ButtonBar.php:112
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\makeInputButton
‪InputButton makeInputButton()
Definition: ButtonBar.php:102
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\addButton
‪$this addButton(ButtonInterface $button, $buttonPosition=self::BUTTON_POSITION_LEFT, $buttonGroup=1)
Definition: ButtonBar.php:61
‪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:53
‪TYPO3\CMS\Backend\Template\Components\Buttons\SplitButton
Definition: SplitButton.php:52
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\getButtons
‪getButtons()
Definition: ButtonBar.php:161
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\makeLinkButton
‪LinkButton makeLinkButton()
Definition: ButtonBar.php:132
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\makeButton
‪ButtonInterface makeButton($button)
Definition: ButtonBar.php:89
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\$buttons
‪array $buttons
Definition: ButtonBar.php:48
‪TYPO3\CMS\Backend\Template\Components\Buttons\InputButton
Definition: InputButton.php:40
‪TYPO3\CMS\Backend\Template\Components
Definition: AbstractControl.php:16
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪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:42
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\makeFullyRenderedButton
‪FullyRenderedButton makeFullyRenderedButton()
Definition: ButtonBar.php:142
‪TYPO3\CMS\Backend\Template\Components\ButtonBar\makeShortcutButton
‪ShortcutButton makeShortcutButton()
Definition: ButtonBar.php:152
‪TYPO3\CMS\Backend\Template\Components\Buttons\ButtonInterface
Definition: ButtonInterface.php:22