foreach ($this->buttons as $position => $_) {
ksort($this->buttons[$position]);
}
- // @todo do we want to provide a hook here?
+ // Hook for manipulating the docHeaderButtons
+ if (!empty($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['Backend\Template\Components\ButtonBar']['getButtonsHook'])) {
+ foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['Backend\Template\Components\ButtonBar']['getButtonsHook'] as $funcRef) {
+ $params = array(
+ 'buttons' => $this->buttons
+ );
+ $this->buttons = GeneralUtility::callUserFunction($funcRef, $params, $this);
+ }
+ }
return $this->buttons;
}
}
The main challenge is to provide extension developers with all tools they need to build decent backend modules while maintaining control of the docHeader itself.
+
Solution
========
* Left Button Bar
* Right Button Bar
+
API Components
==============
$menuItem->setActive(TRUE);
}
$languageMenu->addMenuItem($menuItem);
- $this->moduleTemplate->getDocHeaderComponent()->getModuleMenuRegistry()->addMenu($languageMenu);
\ No newline at end of file
+ $this->moduleTemplate->getDocHeaderComponent()->getModuleMenuRegistry()->addMenu($languageMenu);
+
+
+ButtonBar Hook
+==============
+
+The old module rendering knew a ``$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/template.php']['docHeaderButtonsHook']`` hook
+to manipulate buttons. A similar hook is available in ModuleTemplate API as ``$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['Backend\Template\Components\ButtonBar']['getButtonsHook']``.
+
+**Registering your own hook**
+
+.. code-block:: php
+
+ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['Backend\Template\Components\ButtonBar']['getButtonsHook']['MyExt'] =
+ \MyVendor\MyExt\Hooks\ButtonBarHook::class . '->getButtons';
+
+**Example usage of the hook**
+
+.. code-block:: php
+
+ class ButtonBarHook {
+
+ /**
+ * Get buttons
+ *
+ * @param array $params
+ * @param ButtonBar $buttonBar
+ * @return array
+ */
+ public function getButtons(array $params, ButtonBar $buttonBar) {
+ $buttons = $params['buttons'];
+
+ $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
+ $button = $buttonBar->makeLinkButton();
+ $button->setIcon($iconFactory->getIcon('my-custom-icon', Icon::SIZE_SMALL));
+ $button->setTitle('My custom docHeader button');
+ $button->setOnClick('alert("Hook works");return false;');
+
+ $buttons[ButtonBar::BUTTON_POSITION_LEFT][1][] = $button;
+
+ return $buttons;
+ }
+ }