public function copy(EnvironmentInterface $environment, ModelIdInterface $modelId)
    {
        $this->guardNotEditOnly($environment->getDataDefinition(), $modelId);
        $this->guardIsCreatable($environment, $modelId);

        $dataProvider = $environment->getDataProvider();
        $model        = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($modelId->getId()));

        // We need to keep the original data here.
        $copyModel = $environment->getController()->createClonedModel($model);

        $eventDispatcher = $environment->getEventDispatcher();
        // Dispatch pre duplicate event.
        $preCopyEvent = new PreDuplicateModelEvent($environment, $copyModel, $model);
        $eventDispatcher->dispatch($preCopyEvent::NAME, $preCopyEvent);

        // Save the copy.
        $environment->getDataProvider($copyModel->getProviderName())->save($copyModel);

        // Dispatch post duplicate event.
        $postCopyEvent = new PostDuplicateModelEvent($environment, $copyModel, $model);
        $eventDispatcher->dispatch($postCopyEvent::NAME, $postCopyEvent);

        return $copyModel;
    }