Contao 4 as a Bundle

Willkommen!

Inhalt

Worum gehts?

Content-Management für eine bestehende Symfony-Applikation


Worum gehts?

Composer Dependency Management


Das Contao Eco-System

Paket vs. Bundle


Das Contao Eco-System

Die Contao Standard Edition


Das Contao Eco-System

Das Contao Eco-System

Das MetaPackage contao/contao


Das Contao Eco-System

Das Core Bundle contao/core-bundle


Das Contao Eco-System

Das Installation Bundle contao/installation-bundle


Das Contao Eco-System

Die Features Bundles contao/[...]-bundle


Erweiterung einer Applikation um Contao 4

Die eigene Installation


Erweiterung einer Applikation um Contao 4

“Just use the bundle he said, it will be fun he said”


Ein Bundle …

Erweiterung einer Applikation um Contao 4

Symfony installieren


(Der Vollständigkeitshalber)

$> sudo curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony
$> sudo chmod a+x /usr/local/bin/symfony

$> symfony new contao4-as-a-bundle 2.8
                

Erweiterung einer Applikation um Contao 4

Das composer.json (1)


contao/contao vs. contao/core-bundle


"require": {
    "contao/contao": "~4.1"
},
                

Erweiterung einer Applikation um Contao 4

Das composer.json (2)


"scripts": {
	"post-install-cmd": [
		"Contao\\CoreBundle\\Composer\\ScriptHandler::generateRandomSecret",
		"Contao\\CoreBundle\\Composer\\ScriptHandler::addDirectories",
		"Contao\\CoreBundle\\Composer\\ScriptHandler::generateSymlinks"
	],
	"post-update-cmd": [
		"Contao\\CoreBundle\\Composer\\ScriptHandler::generateRandomSecret",
		"Contao\\CoreBundle\\Composer\\ScriptHandler::addDirectories",
		"Contao\\CoreBundle\\Composer\\ScriptHandler::generateSymlinks"
	]
},
                

Erweiterung einer Applikation um Contao 4

Das composer.json (3)


"config": {
    "bin-dir": "bin",
    "preferred-install": {
        "contao/*": "source",
        "contao-components/*": "source",
        "*": "dist"
    },
    "component-dir": "assets"
},
                

Erweiterung einer Applikation um Contao 4

Das composer.json (4)


"extra": {
    "incenteev-parameters": {
        "file": "app/config/parameters.yml",
        "env-map": {
            "secret": "CONTAO_RANDOM_SECRET"
        }
    }
}
                

Erweiterung einer Applikation um Contao 4


// app/AppKernel.php
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = [
            new ContaoCoreBundle(),
        ];

        return $bundles;
    }
}
                

Erweiterung einer Applikation um Contao 4

Konfiguration


app/config/contao.yml erstellen


# app/config/contao.yml
contao:
    prepend_locale: "%prepend_locale%"
    encryption_key: "%kernel.secret%"

prepend_locale muss im parameters.yml nachgetragen werden

Erweiterung einer Applikation um Contao 4

Konfiguration


contao.yml muss in der config.yml importiert werden


# app/config/config.yml
imports:
	# Other imports
    - { resource: contao.yml }

Erweiterung einer Applikation um Contao 4

Konfiguration


⇢ php app/console debug:router
 -------------------------- -------- -------- ------ --------------
  Name                       Method   Scheme   Host   Path         
 -------------------------- -------- -------- ------ --------------
  _wdt                       ANY      ANY      ANY    /_wdt/{token}
  [...] 
  homepage                   ANY      ANY      ANY    /            
 -------------------------- -------- -------- ------ --------------
            	

Erweiterung einer Applikation um Contao 4

Routing CoreBundle

# app/config/routing.yml

ContaoCoreBundle:
    resource: "@ContaoCoreBundle/Resources/config/routing.yml" 

Erweiterung einer Applikation um Contao 4

Routing InstallationBundle

# app/config/routing_dev.yml

ContaoInstallationBundle:
    resource: "@ContaoInstallationBundle/Resources/config/routing.yml"
⇢ php app/console debug:router
 -------------------------- -------- -------- ------ -----------------
  Name                       Method   Scheme   Host   Path            
 -------------------------- -------- -------- ------ -----------------
  [...]                  
  homepage                   ANY      ANY      ANY    /               
  contao_backend             ANY      ANY      ANY    /contao
  [...]              
  contao_frontend            ANY      ANY      ANY    /{alias}.html   
  contao_index               ANY      ANY      ANY    /
  contao_catch_all           ANY      ANY      ANY    /{_url_fragment}
            	

Erweiterung einer Applikation um Contao 4

Security


Es kann nur einen security-Node geben, daher muss die security.yml von Hand zusammengeführt werden.


security:
    providers:
        [...] Your own providers

        contao.security.user_provider:
            id: contao.security.user_provider

Erweiterung einer Applikation um Contao 4

Security


security:
    firewalls:
        install: [...]
        
        backend:
            pattern: ^/contao

        frontend:
            pattern: ~

Erweiterung einer Applikation um Contao 4

Abschluss


Keine Fehler? Dann sollte Contao erfolgreich installiert worden sein.


⇢ php app/console contao:version
4.1.3

Erweiterung einer Applikation um Contao 4

Abschluss


Herausforderungen

Ist Contao in klassisches Symfony Bundle?



In computer science, a function or expression is said to have a side effect if it modifies some state or has an observable interaction with calling functions or (sic!) the outside world. https://en.wikipedia.org/wiki/Side_effect_(computer_science)

Contao funktioniert als Bundle

Request Tokens



// src/AppBundle/Contao/ContaoFramework.php
private function handleRequestToken()
{
    return;
}
                

Ist bereits gefixt!

UserSessionListener



// src/AppBundle/EventListener/UserSessionListener.php
protected function hasUser()
{
    $user = $this->tokenStorage->getToken();

    return (
        !$user instanceof AnonymousToken &&
        !$user instanceof AppBundle\Entity\User
    );
}
                

Baselayouts


CMS und Applikation miteinander verbinden

Contao 3


CMS und Applikation miteinander verbinden

Nachteile


CMS und Applikation miteinander verbinden

Contao 4


CMS und Applikation miteinander verbinden

Nachteile


CMS und Applikation miteinander verbinden

Contao Inhalte in Symfony templates



Contao Inhalte in Symfony templates


class ContaoDataProviderExtension
{
    public function renderFrontendModule($id)
    {
        $this->container->enterScope('frontend');
        $this->framework->initialize();
        $this->container->leaveScope('frontend');

        return Controller::replaceInsertTags(Controller::getFrontendModule($id));
    }
}
                

CMS und Applikation miteinander verbinden

Symfony Controller Responses in Contao Seiten


class SimpleControllerReferenceModule extends Module
{
    protected $strTemplate = 'mod_simple_controller_reference';

    protected function compile()
    {
        $container = $this->getContainer();
        $request = $container->get('request');

        $response = $container->get('fragment.renderer.inline')->render(
            new ControllerReference($this->controllerReference),
            $request
        );

        $this->Template->content = $response->getContent();
    }
}
                

Abschluss

Contao 4 as a Bundle - viable?


Abschluss

Wünschenswertes für die Zukunft


Danke!