typo3typo3-6.1.x

How do I add own buttons in Typo3-Backend to call extension method


could anyone tell me, what's the way to add own buttons in the backend of Typo3? It should appear there:

enter image description here

THX in advance!!


Solution

  • TYPO3 6.2: Use the file .../typo3_src-6.2.4/typo3/sysext/backend/Classes/Controller/BackendController.php and its method addToolbarItem.

    /**
     * Adds an item to the toolbar, the class file for the toolbar item must be loaded at this point
     *
     * @param string $toolbarItemName Toolbar item name, f.e. tx_toolbarExtension_coolItem
     * @param string $toolbarItemClassName Toolbar item class name, f.e. tx_toolbarExtension_coolItem
     * @return void
     * @throws \UnexpectedValueException
     */
    public function addToolbarItem($toolbarItemName, $toolbarItemClassName) {
        $toolbarItem = GeneralUtility::makeInstance($toolbarItemClassName, $this);
        if (!$toolbarItem instanceof \TYPO3\CMS\Backend\Toolbar\ToolbarItemHookInterface) {
            throw new \UnexpectedValueException('$toolbarItem "' . $toolbarItemName . '" must implement interface TYPO3\\CMS\\Backend\\Toolbar\\ToolbarItemHookInterface', 1195125501);
        }
        if ($toolbarItem->checkAccess()) {
            $this->toolbarItems[$toolbarItemName] = $toolbarItem;
        } else {
            unset($toolbarItem);
        }
    }
    

    Do it the same way as the opendocs system extension does it.

    if (TYPO3_MODE === 'BE') {
        // Now register the class as toolbar item
        $GLOBALS['TYPO3backend']->addToolbarItem('opendocs', 'TYPO3\\CMS\\Opendocs\\Controller\\OpendocsController');
    }
    

    See the file .../typo3_src-6.2.4/typo3/sysext/opendocs/Classes/Controller/OpendocsController.php:

    class OpendocsController implements \TYPO3\CMS\Backend\Toolbar\ToolbarItemHookInterface {