TYPO3: Extbase/Fluid im BE Modul

Backend Modul, erstellt mit Extbase und Fluid Templates – ohne viel Bla-Bla:

ext_tables.php

\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerModule(
    'TYPO3.' . $_EXTKEY,
    'tools',
    'tx_myext_m1',
    '',
    array(
        'Backend' => 'migrate',
    ),
    array(
        'access' => 'user, group',
        'icon' => 'EXT:my_ext/ext_icon.gif',
        'labels' => 'LLL:EXT:my_ext/Resources/Private/Language/locallang.xlf',
    )
);

locallang.xlf

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<xliff version="1.0">
    <file source-language="en" datatype="plaintext" original="messages" product-name="loewen_be">
        <header/>
        <body>
            <trans-unit id="mlang_tabs_tab">
                <source>Löwen</source>
            </trans-unit>
            <trans-unit id="mlang_labels_tabdescr">
                <source>BE Modul für Löwen</source>
            </trans-unit>
        </body>
    </file>
</xliff>

ext_typoscript_setup.typoscript

module.tx_myext {
    view {
        templateRootPaths {
            0 = EXT:my_ext/Resources/Private/Templates/
        }
        partialRootPaths {
            0 = EXT:my_ext/Resources/Private/Partials/
        }
        layoutRootPaths {
            0 = EXT:my_ext/Resources/Private/Layouts/
        }
    }
    settings {
        // your TypoScript setup for backend module
    }
}

Resources/Private/Templates/Backend/Migrate.html

<f:layout name="Backend"/>
 
<f:section name="main">
    <h1>Migrate Service Centers</h1>
    <f:flashMessages renderMode="div" />
 
    <f:form action="migrate" name="migrate">
        <f:form.submit name="submit" value="Migrate!" />
    </f:form>
</f:section>

Resources/Private/Layouts/Backend.html

<f:be.container>
    <div class="typo3-fullDoc">
        <div id="typo3-docheader">
            <div class="typo3-docheader-functions">
                <div class="left">
                    <f:be.buttons.csh />
                    <f:be.menus.actionMenu>
                        <f:be.menus.actionMenuItem label="{f:translate(key: 'LLL:EXT:my_ext/Resources/Private/Language/locallang.xlf:action.action1')}" controller="Backend" action="action1" />
                        <f:be.menus.actionMenuItem label="{f:translate(key: 'LLL:EXT:my_ext/Resources/Private/Language/locallang.xlf:action.action2')}" controller="Backend" action="action2" />
                    </f:be.menus.actionMenu>
                </div>
                <div class="right">
                    <f:be.buttons.shortcut />
                    <f:be.pagePath />
                    <f:be.pageInfo />
                </div>
            </div>
        </div>
        <div id="typo3-docbody">
            <div id="typo3-inner-docbody">
                <f:render section="main" />
            </div>
        </div>
    </div>
</f:be.container>

 Classes/Controller/BackendController.php

namespace TYPO3\MyExt\Controller;
class BackendController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
    // TypoScript settings
    protected $settings = array();
    // id of selected page
    protected $id;
    // info of selected page
    protected $pageinfo;
 
    protected function initializeAction() {
        $this->id = (int)\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('id');
        $this->pageinfo = \TYPO3\CMS\Backend\Utility\BackendUtility::readPageAccess($this->id, $GLOBALS['BE_USER']->getPagePermsClause(1));
 
        $configurationManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager::class);
 
        $this->settings = $configurationManager->getConfiguration(
            $this->request->getControllerExtensionName(),
            $this->request->getPluginName()
        );
    }
 
    /**
     * action
     *
     * @return void
     */
    public function migrateAction() {
        $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
        $migrateRepository = $objectManager->get(\Vendor\MyExt\Domain\Repository\MigrateRepository::class);
 
        // form submitted
        if($this->request->hasArgument('submit')) {...}
 
        // add value to view
        $this->view->assign('var', 'value');
 
        // display message
        $this->addFlashMessage(
            'Some text',
            'The title',
            \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING
        );
    }
}

CSS/JS Datei einlesen

<f:be.container addCssFile="{f:uri.resource(path:'path/to/file.css')}" addJsFile="{f:uri.resource(path:'path/to/file.js')}">...</f:be.container>

Fragen?

Ein Kommentar zu “TYPO3: Extbase/Fluid im BE Modul”

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.