Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document custom login providers #1494

Open
bytehead opened this issue Jan 7, 2025 · 1 comment
Open

Document custom login providers #1494

bytehead opened this issue Jan 7, 2025 · 1 comment

Comments

@bytehead
Copy link
Member

bytehead commented Jan 7, 2025

See contao/contao#7817

@bytehead
Copy link
Member Author

bytehead commented Jan 7, 2025

Create a backend login listener:

# src/EventListener/Menu/AcmeBackendLoginListener.php
<?php

declare(strict_types=1);

namespace App\EventListener\Menu;

use Contao\CoreBundle\Event\MenuEvent;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

#[AsEventListener]
class AcmeBackendLoginListener
{
    public function __construct(
        private readonly TranslatorInterface $translator,
        private readonly RouterInterface $router,
    ) {
    }

    public function __invoke(MenuEvent $event): void
    {
        $tree = $event->getTree();

        if ('loginMenu' !== $tree->getName()) {
            return;
        }

        $acme = $event->getFactory()
            ->createItem('acme')
            ->setAttribute('class', 'acme')
            ->setLabel('Login with Acme')
            ->setUri('https://login.acme')
            ->setLinkAttribute('class', 'tl_submit has-icon')
            ->setExtra('icon', '/path/to/icon.svg')
            ->setExtra('icon_dark', '/path/to/icon--dark.svg')
            ->setExtra('safe_label', true)
            ->setExtra('translation_domain', false)
        ;

        $tree->addChild($acme);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant