PHP code example of eliashaeussler / typo3-config-objects

1. Go to this page and download the library: Download eliashaeussler/typo3-config-objects library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

eliashaeussler / typo3-config-objects example snippets


// Configuration/Icons.php

use TYPO3\CMS\Core;

return [
    'tx-example-my-icon' => [
        'provider' => Core\Imaging\IconProvider\SvgIconProvider::class,
        'source' => 'EXT:example/Resources/Public/Icons/my-icon.svg',
    ],
    'tx-example-my-second-icon' => [
        'provider' => Core\Imaging\IconProvider\BitmapIconProvider::class,
        'source' => 'EXT:example/Resources/Public/Icons/my-second-icon.jpg',
    ],
    'tx-example-my-legacy-icon' => [
        'provider' => Core\Imaging\IconProvider\SvgIconProvider::class,
        'source' => 'EXT:example/Resources/Public/Icons/my-legacy-icon.svg',
        'deprecated' => [
            'since' =>  'TYPO3 v12',
            'until' => 'TYPO3 v13',
            'replacement' => 'tx-example-my-new-icon',
        ],
    ],
    'tx-example-my-new-icon' => [
        'provider' => \Vendor\Example\Imaging\MyCustomIconProvider::class,
        'renderer' => \Vendor\Example\Renderer\MyCustomIconRenderer::class,
    ],
];

// Configuration/Icons.php

use EliasHaeussler\Typo3ConfigObjects;

return Typo3ConfigObjects\Configuration\IconConfiguration::create()
    // Add a list of icons to configure
    ->add(
        Typo3ConfigObjects\ValueObject\Icon::create('tx-example-my-icon')
            ->useSvgIconProvider('EXT:example/Resources/Public/Icons/my-icon.svg'),
        Typo3ConfigObjects\ValueObject\Icon::create('tx-example-my-second-icon')
            ->useBitmapIconProvider('EXT:example/Resources/Public/Icons/my-second-icon.jpg')
    )

    // You can also use deprecated icons
    ->add(
        Typo3ConfigObjects\ValueObject\Icon::create('tx-example-my-legacy-icon')
            ->useSvgIconProvider('EXT:example/Resources/Public/Icons/my-legacy-icon.svg')
            ->setDeprecated(
                new Typo3ConfigObjects\ValueObject\DeprecatedIcon(
                    since: 'TYPO3 v12',
                    until: 'TYPO3 v13',
                    replacement: 'tx-example-my-new-icon',
                ),
            )
    )

    // You can also use custom icon providers and custom options
    ->add(
        Typo3ConfigObjects\ValueObject\Icon::create('tx-example-my-new-icon')
            ->useCustomIconProvider(\Vendor\Example\Imaging\MyCustomIconProvider::class)
            ->addOption('renderer', \Vendor\Example\Renderer\MyCustomIconRenderer::class)
    )

    // Don't forget to return an array representation (TYPO3 expects an array to be returned)
    ->toArray();

// Configuration/RequestMiddlewares.php

use TYPO3\CMS\Core;

return [
    'backend' => [
        'vendor/extension/my-middleware' => [
            'target' => \Vendor\Example\Middleware\MyMiddleware::class,
        ],
        'vendor/extension/my-other-middleware' => [
            'target' => \Vendor\Example\Middleware\MyOtherMiddleware::class,
            'before' => [
                'vendor/extension/my-middleware',
            ],
            'after' => [
                'typo3/cms-backend/authentication',
            ],
        ],
    ],
    'frontend' => [
        'typo3/cms-redirects/redirecthandler' => [
            'disabled' => true,
        ],
    ],
];

// Configuration/RequestMiddlewares.php

use EliasHaeussler\Typo3ConfigObjects;

return Typo3ConfigObjects\Configuration\MiddlewareConfiguration::create()
    // Add a list of middlewares
    ->addToBackendStack(
        Typo3ConfigObjects\ValueObject\RequestMiddleware::create('vendor/extension/my-middleware')
            ->setTarget(\Vendor\Example\Middleware\MyMiddleware::class),
        Typo3ConfigObjects\ValueObject\RequestMiddleware::create('vendor/extension/my-other-middleware')
            ->setTarget(\Vendor\Example\Middleware\MyOtherMiddleware::class)
            ->before('vendor/extension/my-middleware')
            ->after('typo3/cms-backend/authentication')
    )

    // You can also disable existing middlewares
    ->addToFrontendStack(
        Typo3ConfigObjects\ValueObject\RequestMiddleware::create('typo3/cms-redirects/redirecthandler')
            ->disable()
    )

    // Don't forget to return an array representation (TYPO3 expects an array to be returned)
    ->toArray();