protected function handleSubmit(ModelInterface $model)
    {
        $environment   = $this->getEnvironment();
        $dispatcher    = $environment->getEventDispatcher();
        $inputProvider = $environment->getInputProvider();

        if ($inputProvider->hasValue('save')) {
            $newUrlEvent = new AddToUrlEvent('act=edit&id=' . ModelId::fromModel($model)->getSerialized());
            $dispatcher->dispatch(ContaoEvents::BACKEND_ADD_TO_URL, $newUrlEvent);
            $dispatcher->dispatch(ContaoEvents::CONTROLLER_REDIRECT, new RedirectEvent($newUrlEvent->getUrl()));
        } elseif ($inputProvider->hasValue('saveNclose')) {
            $this->clearBackendStates();

            $newUrlEvent = new GetReferrerEvent();
            $dispatcher->dispatch(ContaoEvents::SYSTEM_GET_REFERRER, $newUrlEvent);
            $dispatcher->dispatch(ContaoEvents::CONTROLLER_REDIRECT, new RedirectEvent($newUrlEvent->getReferrerUrl()));
        } elseif ($inputProvider->hasValue('saveNcreate')) {
            $this->clearBackendStates();
            $after = ModelId::fromModel($model);

            $newUrlEvent = new AddToUrlEvent('act=create&id=&after=' . $after->getSerialized());
            $dispatcher->dispatch(ContaoEvents::BACKEND_ADD_TO_URL, $newUrlEvent);
            $dispatcher->dispatch(ContaoEvents::CONTROLLER_REDIRECT, new RedirectEvent($newUrlEvent->getUrl()));
        } elseif ($inputProvider->hasValue('saveNback')) {
            $this->clearBackendStates();

            $parentProviderName = $environment->getDataDefinition()->getBasicDefinition()->getParentDataProvider();
            $newUrlEvent        = new GetReferrerEvent(false, $parentProviderName);

            $dispatcher->dispatch(ContaoEvents::SYSTEM_GET_REFERRER, $newUrlEvent);
            $dispatcher->dispatch(ContaoEvents::CONTROLLER_REDIRECT, new RedirectEvent($newUrlEvent->getReferrerUrl()));
        }
    }