Contao 4 erweitern
Services in Hooks
Fragments
Symfony-Routen im Backend
Contao 4 erweitern
Services in Hooks
Fragments
Symfony-Routen im Backend
Individuelle Anpassung oder frei verfügbares Bundle?
Individuelle Anpassung
managed-edition/ app/ assets/ files/ src/ system/ templates/ vendor/ web/
app/ config/ config.yml parameters.yml Resources/ contao/ config/ dca/ languages/ templates/
src/ AppBundle/ Controller/ ...
<?php namespace AppBundle\Controller; class MyController { }
In Symfony 4 entfällt der Ordner AppBundle
(bundle-less application):
src/ Controller/ ...
<?php namespace App\Controller; class MyController { }
Namespace | Ressource | Elternklasse |
---|---|---|
App/ContentElement |
Inhaltselemente | extends Contao\ContentElement |
App/DataContainer |
DCA-Callbacks | - |
App/Model |
Models | extends Contao\Model |
App/FrontendModule |
Frontend-Module | extends Contao\Module |
App/Widget |
Widgets | extends Contao\Widget |
app/ ContaoManagerPlugin.php
Damit der Autoloader die Klasse findet, muss sie registriert werden:
"autoload": { "classmap": [ "app/ContaoManagerPlugin.php" ] }
<?php use Contao\ManagerPlugin\Bundle\Config\BundleConfig; use Contao\ManagerPlugin\Bundle\BundlePluginInterface; use Contao\ManagerPlugin\Bundle\Parser\ParserInterface; use Knp\Bundle\MenuBundle\KnpMenuBundle; class ContaoManagerPlugin implements BundlePluginInterface { public function getBundles(ParserInterface $parser) { return [ BundleConfig::create(KnpMenuBundle::class), ]; } }
<?php use Contao\ManagerPlugin\Config\ConfigPluginInterface; use Symfony\Component\Config\Loader\LoaderInterface; class ContaoManagerPlugin implements ConfigPluginInterface { public function registerContainerConfiguration(LoaderInterface $loader, array $config) { $loader->load(__DIR__.'/config/custom.yml'); } }
<?php use Contao\ManagerPlugin\Routing\RoutingPluginInterface; use Symfony\Component\Config\Loader\LoaderResolverInterface; use Symfony\Component\HttpKernel\KernelInterface; class ContaoManagerPlugin implements RoutingPluginInterface { public function getRouteCollection(LoaderResolverInterface $resolver, KernelInterface $kernel) { $file = __DIR__.'/config/routing.yml'; return $resolver->resolve($file)->load($file); } }
<?php use Contao\ManagerPlugin\Dependency\DependentPluginInterface; class ContaoManagerPlugin implements DependentPluginInterface { public function getPackageDependencies() { return [ 'contao/news-bundle', ]; } }
Frei verfügbares Bundle
composer.json
vendor/
-Ordner der Managed-Edition gemacht und anschließend nach
origin
gepushtvendor/
-Ordners soll nicht das Git-Repository löschenDas Repository liegt bei GitHub (oder GitLab etc.) und ist bei Packagist registriert:
"require": { "vendor/package": "dev-master" }, "config": { "preferred-install": { "vendor/": "source", "*": "dist" } }
Das Repository liegt auf dem lokalen Rechner:
"require": { "vendor/package": "dev-master" }, "repositories": [ { "type": "vcs", "path": "/pfad/zum/repo" } ], "config": { "preferred-install": { "vendor/": "source", "*": "dist" } }
Getting started
<?php $GLOBALS['TL_HOOKS']['replaceInsertTags'][] = array( 'ModuleFaq', 'replaceInsertTags' );
<?php $GLOBALS['TL_DCA']['tl_faq'] = array( 'config' => array( 'onload_callback' => array( array('tl_faq', 'checkPermission') ) ) )
<?php $GLOBALS['TL_HOOKS']['replaceInsertTags'][] = array( 'contao_faq.listener.insert_tags', 'onReplaceInsertTags' );
<?php $GLOBALS['TL_DCA']['tl_faq'] = array( 'config' => array( 'onload_callback' => array( array('contao_faq.security.permission_checker', 'onCheckFaq') ) ) )
Hooks taggen
services: contao_faq.listener.insert_tags: class: Contao\FaqBundle\Listener\InsertTagsListener tags: - { name: contao.hook, hook: replaceInsertTags }
onReplaceInsertTags()
aufmethod: foo
explizit definiert werdenpriority: 64
angegeben werden$GLOBALS['FE_MOD']['navigationMenu']['fastnav'] = 'ModuleFastnav';
class ModuleNavigation extends Module { protected $strTemplate = 'mod_fastnav'; public function generate() { } protected function compile() { } }
services: app.module.fastnav_controller: class: App\Controller\Module\FastnavController tags: - { name: contao.frontend_module, category: navigationMenu }
tl_module.type
, $GLOBALS['TL_LANG']
etc. sowie der Name des
Templates werden aus dem Klassennamen generiert: fastnav
, MOD.fastnav
,
mod_fastnav.html5
type: foo
explizit definiert werden: MOD.foo
,
mod_foo.html5
<?php namespace App\Controller\Module; use Contao\CoreBundle\Controller\AbstractFrontendModuleController use Contao\Model; use Contao\Template; use Symfony\Component\HttpFoundation\Request; class FastnavController extends AbstractFrontendModuleController { protected function getResponse(Template $template, Model $model, Request $request) { return $template->getResponse(); } }
Erstellung einer Symfony-Route
Verwendung von Twig
Hinzufügen eines eigenen Menüpunktes
Ausgabe im Contao-Backend
Noch Fragen?
Vielen Dank für die Aufmerksamkeit