src/Listener/HandleSubmitListener.php
public function handleEvent(HandleSubmitEvent $event): void
    {
        // Only run in the frontend
        if (false === $this->scopeDeterminator->currentScopeIsFrontend()) {
            return;
        }

        $currentUrl = $this->requestStack->getCurrentRequest()->getUri();

        switch ($event->getButtonName()) {
            case 'save':
                // Could be a create action, always redirect to current page with edit action and id properly set.
                $url = UrlBuilder::fromUrl($currentUrl)
                    ->setQueryParameter('act', 'edit')
                    ->setQueryParameter('id', ModelId::fromModel($event->getModel())->getSerialized());

                throw new RedirectResponseException($url->getUrl());
            case 'saveNcreate':
                // We want to create a new model, set create action and pass the current id as "after" to keep sorting.
                $after = ModelId::fromModel($event->getModel());
                $url   = UrlBuilder::fromUrl($currentUrl)
                    ->unsetQueryParameter('id')
                    ->setQueryParameter('act', 'create')
                    ->setQueryParameter('after', $after->getSerialized());

                throw new RedirectResponseException($url->getUrl());
            default:
                // Do nothing.
        }
    }
public function handleEvent(HandleSubmitEvent $event): void
    {
        // Only run in the frontend
        if (false === $this->scopeDeterminator->currentScopeIsFrontend()) {
            return;
        }

        $currentUrl = $this->requestStack->getCurrentRequest()->getUri();

        switch ($event->getButtonName()) {
            case 'save':
                // Could be a create action, always redirect to current page with edit action and id properly set.
                $url = UrlBuilder::fromUrl($currentUrl)
                    ->setQueryParameter('act', 'edit')
                    ->setQueryParameter('id', ModelId::fromModel($event->getModel())->getSerialized());

                throw new RedirectResponseException($url->getUrl());
            case 'saveNcreate':
                // We want to create a new model, set create action and pass the current id as "after" to keep sorting.
                $after = ModelId::fromModel($event->getModel());
                $url   = UrlBuilder::fromUrl($currentUrl)
                    ->unsetQueryParameter('id')
                    ->setQueryParameter('act', 'create')
                    ->setQueryParameter('after', $after->getSerialized());

                throw new RedirectResponseException($url->getUrl());
            default:
                // Do nothing.
        }
    }
Handle the event.

@param HandleSubmitEvent $event The event.

@return void

@throws RedirectResponseException To redirect to the proper edit mask.